Skip to content

Commit

Permalink
[TASK] Provide encryptionKey in unit tests
Browse files Browse the repository at this point in the history
Since TYPO3 12.4.11 and 11.5.35 the encryptionKey is not initialized
in the default configuration, thus some unit tests will fail.

This commit ensures an encryptionKey is set for the unit tests.

Resolves: TYPO3-Solr#3958
  • Loading branch information
dkd-friedrich committed Feb 22, 2024
1 parent e6282ad commit 6153c30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
17 changes: 1 addition & 16 deletions Tests/Unit/Domain/Variants/IdBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,14 @@
*/
class IdBuilderTest extends SetUpUnitTestCase
{
protected string $oldEncryptionKey;

protected function setUp(): void
{
$this->oldEncryptionKey = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testkey';
parent::setUp();
}

protected function tearDown(): void
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = $this->oldEncryptionKey;
parent::tearDown();
}

/**
* @test
*/
public function canBuildVariantId(): void
{
$build = new IdBuilder(new NoopEventDispatcher());
$variantId = $build->buildFromTypeAndUid('pages', 4711, [], $this->createMock(Site::class), new Document());
self::assertSame('e99b3552a0451f1a2e7aca4ac06ccaba063393de/pages/4711', $variantId);
self::assertSame('c523304ea47711019595d2bb352b623d1db40427/pages/4711', $variantId);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions Tests/Unit/SetUpUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,25 @@
abstract class SetUpUnitTestCase extends UnitTestCase
{
protected bool $resetSingletonInstances = true;
protected ?string $originalEncryptionKey;

protected function setUp(): void
{
date_default_timezone_set('Europe/Berlin');
$this->originalEncryptionKey = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] ?? null;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'solr-tests-secret-encryption-key';
parent::setUp();
}

protected function tearDown(): void
{
unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
if ($this->originalEncryptionKey !== null) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = $this->originalEncryptionKey;
}
parent::tearDown();
}

/**
* Returns the absolute root path to the fixtures.
*
Expand Down

0 comments on commit 6153c30

Please sign in to comment.