Skip to content

Commit

Permalink
[TASK] Refactor Integration tests : Schrink fixtures
Browse files Browse the repository at this point in the history
Fixes: #3092
Relates: #2976, #2977
  • Loading branch information
dkd-kaehm committed Dec 2, 2021
1 parent 66afd4f commit 25cf5b9
Show file tree
Hide file tree
Showing 86 changed files with 548 additions and 2,750 deletions.
30 changes: 16 additions & 14 deletions Classes/FrontendEnvironment/Tsfe.php
Expand Up @@ -3,6 +3,7 @@

use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationPageResolver;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Throwable;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
Expand All @@ -13,7 +14,6 @@
use TYPO3\CMS\Core\Error\Http\InternalServerErrorException;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\SingletonInterface;
Expand Down Expand Up @@ -154,21 +154,20 @@ protected function initializeTsfe(int $pageId, int $language = 0, ?int $rootPage

try {
$globalsTSFE->determineId($serverRequest);
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (PropagateResponseException $exception)
{
$globalsTSFE->tmpl->start($globalsTSFE->rootLine);
$globalsTSFE->no_cache = false;
$globalsTSFE->getConfigArray($serverRequest);

$globalsTSFE->newCObj($serverRequest);
$globalsTSFE->absRefPrefix = self::getAbsRefPrefixFromTSFE($globalsTSFE);
$globalsTSFE->calculateLinkVars([]);
} catch (Throwable $exception) {
// @todo: logging
$this->serverRequestCache[$cacheIdentifier] = null;
$this->tsfeCache[$cacheIdentifier] = null;
return;
}

$globalsTSFE->tmpl->start($globalsTSFE->rootLine);
$globalsTSFE->no_cache = false;
$globalsTSFE->getConfigArray($serverRequest);

$globalsTSFE->newCObj($serverRequest);
$globalsTSFE->absRefPrefix = self::getAbsRefPrefixFromTSFE($globalsTSFE);
$globalsTSFE->calculateLinkVars([]);

$this->tsfeCache[$cacheIdentifier] = $globalsTSFE;
}

Expand All @@ -191,8 +190,6 @@ protected function initializeTsfe(int $pageId, int $language = 0, ?int $rootPage
* @throws SiteNotFoundException
* @throws DBALDriverException
* @throws Exception\Exception
*
* @todo : Call `$globalsTSFE->newCObj($serverRequest);` each time the TSFE requested. And then remove {@link getServerRequestForTsfeByPageIdAndLanguageId()} method.
*/
public function getTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?TypoScriptFrontendController
{
Expand Down Expand Up @@ -239,8 +236,13 @@ public function getServerRequestForTsfeByPageIdAndLanguageId(int $pageId, int $l
*/
protected function assureIsInitialized(int $pageId, int $language, ?int $rootPageId = null): void
{
if(!array_key_exists($this->getCacheIdentifier($pageId, $language, $rootPageId), $this->serverRequestCache)) {
$cacheIdentifier = $this->getCacheIdentifier($pageId, $language, $rootPageId);
if(!array_key_exists($cacheIdentifier, $this->tsfeCache)) {
$this->initializeTsfe($pageId, $language, $rootPageId);
return;
}
if ($this->tsfeCache[$cacheIdentifier] instanceof TypoScriptFrontendController) {
$this->tsfeCache[$cacheIdentifier]->newCObj($this->serverRequestCache[$cacheIdentifier]);
}
}

Expand Down
Expand Up @@ -144,7 +144,7 @@ protected function resolveFieldValue($solrFieldName, Document $pageDocument)
$pageRecord = AbstractIndexer::addVirtualContentFieldToRecord($pageDocument, $pageRecord);

// configuration found => need to resolve a cObj
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $GLOBALS['TSFE']);
$contentObject->start($pageRecord, 'pages');

$fieldValue = $contentObject->cObjGetSingle(
Expand Down
2 changes: 2 additions & 0 deletions Classes/IndexQueue/FrontendHelper/PageIndexer.php
Expand Up @@ -35,6 +35,7 @@
use ApacheSolrForTypo3\Solr\Typo3PageIndexer;
use ApacheSolrForTypo3\Solr\Util;
use Exception;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand Down Expand Up @@ -339,6 +340,7 @@ public function hook_indexContent(array $params, TypoScriptFrontendController $p
* @param Item $indexQueueItem
* @return SolrConnection Solr server connection
* @throws NoSolrConnectionFoundException
* @throws AspectNotFoundException
*/
protected function getSolrConnection(Item $indexQueueItem)
{
Expand Down
13 changes: 7 additions & 6 deletions Classes/Typo3PageIndexer.php
Expand Up @@ -33,6 +33,7 @@
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use Exception;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down Expand Up @@ -131,7 +132,7 @@ public function __construct(TypoScriptFrontendController $page)

try {
$this->initializeSolrConnection();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->log(
SolrLogManager::ERROR,
$e->getMessage() . ' Error code: ' . $e->getCode()
Expand Down Expand Up @@ -163,15 +164,15 @@ public function setIndexQueueItem($indexQueueItem)
/**
* Initializes the Solr server connection.
*
* @throws \Exception when no Solr connection can be established.
* @throws Exception when no Solr connection can be established.
*/
protected function initializeSolrConnection()
{
$solr = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($this->page->id, Util::getLanguageUid());

// do not continue if no server is available
if (!$solr->getWriteService()->ping()) {
throw new \Exception(
throw new Exception(
'No Solr instance available while trying to index a page.',
1234790825
);
Expand Down Expand Up @@ -205,12 +206,12 @@ public static function getPageSolrDocument()
* initialized by the constructor.
*
* @param SolrConnection $solrConnection Solr connection
* @throws \Exception if the Solr server cannot be reached
* @throws Exception if the Solr server cannot be reached
*/
public function setSolrConnection(SolrConnection $solrConnection)
{
if (!$solrConnection->getWriteService()->ping()) {
throw new \Exception(
throw new Exception(
'Could not connect to Solr server.',
1323946472
);
Expand Down Expand Up @@ -438,7 +439,7 @@ protected function addDocumentsToSolrIndex(array $documents)
}

$documentsAdded = true;
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->log(SolrLogManager::ERROR, $e->getMessage() . ' Error code: ' . $e->getCode());

if ($this->configuration->getLoggingExceptions()) {
Expand Down
9 changes: 6 additions & 3 deletions Tests/Integration/ConnectionManagerTest.php
Expand Up @@ -27,7 +27,6 @@
use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use Nimut\TestingFramework\Exception\Exception;
use ReflectionException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use function vsprintf;
Expand All @@ -41,6 +40,12 @@
class ConnectionManagerTest extends IntegrationTest
{

/**
* @inheritdoc
* @todo: Remove unnecessary fixtures and remove that property as intended.
*/
protected bool $skipImportRootPagesAndTemplatesForConfiguredSites = true;

public function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -75,7 +80,6 @@ public function canFindSolrConnectionsByRootPageIdDataProvider()
* @param string $siteName
* @param string $expectedSolrHost
* @throws NoSolrConnectionFoundException
* @throws Exception
* @throws ReflectionException
*/
public function canFindSolrConnectionsByRootPageId(int $rootPageId, string $siteName, string $expectedSolrHost)
Expand Down Expand Up @@ -134,7 +138,6 @@ public function canFindSolrConnectionsByPageIdDataProvider()
* @param string $siteName
* @param string $expectedSolrHost
* @throws NoSolrConnectionFoundException
* @throws Exception
* @throws ReflectionException
*/
public function canFindSolrConnectionsByPageId(int $pageId, string $siteName, string $expectedSolrHost)
Expand Down
Expand Up @@ -28,7 +28,6 @@
use ApacheSolrForTypo3\Solr\Controller\Backend\Search\IndexAdministrationModuleController;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest;
use ApacheSolrForTypo3\Solr\Util;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -60,8 +59,6 @@ public function setUp(): void {
*/
public function testReloadIndexConfigurationAction()
{
$this->importDataSetFromFixture('can_reload_index_configuration.xml');

/** @var SiteRepository $siteRepository */
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
$selectedSite = $siteRepository->getFirstAvailableSite();
Expand All @@ -77,15 +74,13 @@ public function testReloadIndexConfigurationAction()
*/
public function testEmptyIndexAction()
{
$this->importDataSetFromFixture('can_reload_index_configuration.xml');

/** @var SiteRepository $siteRepository */
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
$selectedSite = $siteRepository->getFirstAvailableSite();
$this->controller->setSelectedSite($selectedSite);
$this->controller->expects($this->once())
$this->controller->expects($this->atLeastOnce())
->method('addFlashMessage')
->with('Index emptied for Site ", Root Page ID: 1" (core_en, core_de, core_da).', '', FlashMessage::OK);
->with('Index emptied for Site "Root of Testpage testone.site aka integration_tree_one, Root Page ID: 1" (core_en, core_de, core_da).', '', FlashMessage::OK);

$this->controller->emptyIndexAction();
}
Expand Down
30 changes: 23 additions & 7 deletions Tests/Integration/Domain/Index/IndexServiceTest.php
Expand Up @@ -30,14 +30,17 @@
use ApacheSolrForTypo3\Solr\System\Environment\CliEnvironment;
use ApacheSolrForTypo3\Solr\System\Environment\WebRootAllReadyDefinedException;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest;
use ApacheSolrForTypo3\Solr\Util;
use Nimut\TestingFramework\Exception\Exception;
use ReflectionException;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception as DoctrineDBALException;
use Doctrine\DBAL\Schema\SchemaException;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\Schema\Exception\StatementException;
use TYPO3\CMS\Core\Database\Schema\Exception\UnexpectedSignalReturnValueTypeException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\TestingFramework\Core\Exception as TestingFrameworkCoreException;

/**
* Testcase for the record indexer
Expand All @@ -46,6 +49,11 @@
*/
class IndexServiceTest extends IntegrationTest
{
/**
* @inheritdoc
* @todo: Remove unnecessary fixtures and remove that property as intended.
*/
protected bool $skipImportRootPagesAndTemplatesForConfiguredSites = true;

/**
* @var Queue
Expand All @@ -54,7 +62,10 @@ class IndexServiceTest extends IntegrationTest

/**
* @return void
*
* @throws DBALException
* @throws NoSuchCacheException
* @throws TestingFrameworkCoreException
*/
public function setUp(): void
{
Expand Down Expand Up @@ -84,7 +95,7 @@ protected function addToIndexQueue($table, $uid): void
$this->indexQueue->updateItem($table, $uid, time());
}

public function canResolveBaseAsPrefixDataProvider()
public function canResolveBaseAsPrefixDataProvider(): array
{
return [
'absRefPrefixIsFoo' => [
Expand All @@ -96,12 +107,17 @@ public function canResolveBaseAsPrefixDataProvider()

/**
* @dataProvider canResolveBaseAsPrefixDataProvider
*
* @param string $absRefPrefix
* @param string $expectedUrl
*
* @throws DoctrineDBALException
* @throws SchemaException
* @throws StatementException
* @throws TestingFrameworkCoreException
* @throws WebRootAllReadyDefinedException
* @throws Exception
* @throws ReflectionException
* @throws \Exception
*
* @throws UnexpectedSignalReturnValueTypeException
* @test
*/
public function canResolveBaseAsPrefix($absRefPrefix, $expectedUrl)
Expand Down
Expand Up @@ -28,7 +28,6 @@
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest;
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Page;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -38,6 +37,11 @@
*/
class QueueItemRepositoryTest extends IntegrationTest
{
/**
* @inheritdoc
* @todo: Remove unnecessary fixtures and remove that property as intended.
*/
protected bool $skipImportRootPagesAndTemplatesForConfiguredSites = true;

public function setUp(): void {
parent::setUp();
Expand Down
Expand Up @@ -31,6 +31,12 @@

class ApacheSolrDocumentRepositoryTest extends IntegrationTest
{
/**
* @inheritdoc
* @todo: Remove unnecessary fixtures and remove that property as intended.
*/
protected bool $skipImportRootPagesAndTemplatesForConfiguredSites = true;

/**
* @var Repository
*/
Expand Down
Expand Up @@ -35,6 +35,12 @@

class SearchResultSetServiceTest extends IntegrationTest
{
/**
* @inheritdoc
* @todo: Remove unnecessary fixtures and remove that property as intended.
*/
protected bool $skipImportRootPagesAndTemplatesForConfiguredSites = true;

public function setUp(): void {
parent::setUp();
$this->writeDefaultSolrTestSiteConfiguration();
Expand Down
Expand Up @@ -2,7 +2,8 @@
<dataset>

<pages>
<uid>1</uid>
<uid>151</uid>
<pid>0</pid>
<is_siteroot>0</is_siteroot>
</pages>

Expand Down

This file was deleted.

@@ -1,9 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<pages>
<uid>1</uid>
<is_siteroot>1</is_siteroot>
</pages>
<pages>
<uid>2</uid>
<pid>1</pid>
Expand All @@ -25,10 +21,4 @@
<uid>30</uid>
<pid>3</pid>
</pages>
<sys_template>
<pid>1</pid>
<uid>1</uid>
<root>1</root>
<config>plugin.tx_solr.index.queue.pages = 1</config>
</sys_template>
</dataset>
</dataset>

0 comments on commit 25cf5b9

Please sign in to comment.