Skip to content

Commit

Permalink
[TASK] Fix Ingration tests: ResultSetReconstitutionProcessorTest and …
Browse files Browse the repository at this point in the history
…ApacheSolrDocumentRepositoryTest

Relates: #3376
  • Loading branch information
dkd-kaehm committed May 15, 2023
1 parent ead957e commit 3d3aae9
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 20 deletions.
21 changes: 13 additions & 8 deletions Classes/Domain/Search/ApacheSolrDocument/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use ApacheSolrForTypo3\Solr\System\Solr\SolrCommunicationException;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Solr\Util;
use Exception;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -79,9 +79,10 @@ public function __construct(
* @param $pageId
* @param $languageId
* @return Document|false
* @throws Exception
*
* @throws DBALDriverException
*/
public function findOneByPageIdAndByLanguageId($pageId, $languageId)
public function findOneByPageIdAndByLanguageId($pageId, $languageId): Document|false
{
$documentCollection = $this->findByPageIdAndByLanguageId($pageId, $languageId);
return reset($documentCollection);
Expand All @@ -94,15 +95,16 @@ public function findOneByPageIdAndByLanguageId($pageId, $languageId)
* @param int $pageId
* @param int $languageId
* @return Document[]
* @throws Exception
*
* @throws DBALDriverException
*/
public function findByPageIdAndByLanguageId(int $pageId, int $languageId): array
{
try {
$this->initializeSearch($pageId, $languageId);
$pageQuery = $this->queryBuilder->buildPageQuery($pageId);
$response = $this->search->search($pageQuery, 0, 10000);
} catch (NoSolrConnectionFoundException|SolrCommunicationException $exception) {
} catch (NoSolrConnectionFoundException|SolrCommunicationException) {
return [];
}
$data = $response->getParsedData();
Expand All @@ -115,8 +117,9 @@ public function findByPageIdAndByLanguageId(int $pageId, int $languageId): array
* @param int $uid
* @param int $pageId
* @param int $languageId
* @return Document[]|array
* @throws Exception
* @return Document[]
*
* @throws DBALDriverException
*/
public function findByTypeAndPidAndUidAndLanguageId(
string $type,
Expand All @@ -128,7 +131,7 @@ public function findByTypeAndPidAndUidAndLanguageId(
$this->initializeSearch($pageId, $languageId);
$recordQuery = $this->queryBuilder->buildRecordQuery($type, $uid, $pageId);
$response = $this->search->search($recordQuery, 0, 10000);
} catch (NoSolrConnectionFoundException|SolrCommunicationException $exception) {
} catch (NoSolrConnectionFoundException|SolrCommunicationException) {
return [];
}
$data = $response->getParsedData();
Expand All @@ -141,6 +144,8 @@ public function findByTypeAndPidAndUidAndLanguageId(
*
* @param int $pageId
* @param int $languageId
*
* @throws DBALDriverException
* @throws NoSolrConnectionFoundException
*/
protected function initializeSearch(int $pageId, int $languageId = 0)
Expand Down
6 changes: 3 additions & 3 deletions Classes/Routing/RoutingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,15 +1147,15 @@ protected function processUriPathArgument(
*/
public function getSiteMatcher(): SiteMatcher
{
return GeneralUtility::makeInstance(SiteMatcher::class, $this->getSiteFinder());
return GeneralUtility::makeInstance(SiteMatcher::class);
}

/**
* Returns the site finder
*
* @return SiteFinder|null
* @return SiteFinder
*/
protected function getSiteFinder(): ?SiteFinder
protected function getSiteFinder(): SiteFinder
{
return GeneralUtility::makeInstance(SiteFinder::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
use ApacheSolrForTypo3\Solr\Domain\Search\ApacheSolrDocument\Repository;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Doctrine\DBAL\Exception as DBALException;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Error\Http\InternalServerErrorException;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Exception as TestingFrameworkCoreException;

class ApacheSolrDocumentRepositoryTest extends IntegrationTest
{
Expand All @@ -29,10 +37,20 @@ class ApacheSolrDocumentRepositoryTest extends IntegrationTest
protected bool $skipImportRootPagesAndTemplatesForConfiguredSites = true;

/**
* @var Repository
* @var Repository|null
*/
protected $apacheSolrDocumentRepository;
protected ?Repository $apacheSolrDocumentRepository = null;

/**
* @throws AspectNotFoundException
* @throws DBALDriverException
* @throws DBALException
* @throws InternalServerErrorException
* @throws NoSuchCacheException
* @throws ServiceUnavailableException
* @throws SiteNotFoundException
* @throws TestingFrameworkCoreException
*/
protected function setUp(): void
{
parent::setUp();
Expand All @@ -50,16 +68,19 @@ protected function setUp(): void
}

/**
* Executed after each test. Emptys solr and checks if the index is empty
* Executed after each test. Empties solr and checks if the index is empty
*/
protected function tearDown(): void
{
$this->cleanUpSolrServerAndAssertEmpty();
unset($this->apacheSolrDocumentRepository);
parent::tearDown();
}

/**
* @test
*
* @throws DBALDriverException
*/
public function canFindByPageIdAndByLanguageId()
{
Expand All @@ -72,6 +93,8 @@ public function canFindByPageIdAndByLanguageId()

/**
* @test
*
* @throws DBALDriverException
*/
public function canReturnEmptyCollectionIfNoConnectionToSolrServerIsEstablished()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace ApacheSolrForTypo3\Solr\Tests\Integration\Domain\Search\ResultSet;

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\InvalidFacetPackageException;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\Option;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\OptionsFacet;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\ResultSetReconstitutionProcessor;
Expand All @@ -39,10 +40,11 @@ class ResultSetReconstitutionProcessorTest extends IntegrationTest
/**
* @test
*
* @throws TestingFrameworkCoreException
* @throws InternalServerErrorException
* @throws ServiceUnavailableException
* @throws SiteNotFoundException
* @throws TestingFrameworkCoreException
* @throws InvalidFacetPackageException
*/
public function canApplyRenderingInstructionsOnOptions()
{
Expand Down Expand Up @@ -95,6 +97,7 @@ public function canApplyRenderingInstructionsOnOptions()
* @test
*
* @throws InternalServerErrorException
* @throws InvalidFacetPackageException
* @throws ServiceUnavailableException
* @throws SiteNotFoundException
* @throws TestingFrameworkCoreException
Expand Down Expand Up @@ -174,7 +177,6 @@ protected function getConfiguredReconstitutionProcessor(array $configuration, Se
$usedSearchRequestMock->expects(self::any())->method('getContextTypoScriptConfiguration')->willReturn($typoScriptConfiguration);
$usedSearchRequestMock->expects(self::any())->method('getActiveFacetNames')->willReturn([]);

$processor = new ResultSetReconstitutionProcessor();
return $processor;
return new ResultSetReconstitutionProcessor();
}
}
13 changes: 13 additions & 0 deletions Tests/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Doctrine\DBAL\Exception as DoctrineDBALException;
use Doctrine\DBAL\Schema\SchemaException;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass;
use ReflectionException;
use ReflectionObject;
Expand All @@ -41,6 +42,7 @@
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\NormalizedParams;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\LanguageService;
Expand Down Expand Up @@ -396,7 +398,18 @@ protected function fakeTSFE(int $pageId, array $feUserGroupArray = [0]): TypoScr
$GLOBALS['TSFE'] = $fakeTSFE;
$this->simulateFrontedUserGroups($feUserGroupArray);

/* @var MockObject|ServerRequest $request */
$request = $GLOBALS['TYPO3_REQUEST'];
$request = $GLOBALS['TYPO3_REQUEST'] =
$request
->withAttribute(
'frontend.controller',
$fakeTSFE
)->withAttribute(
'normalizedParams',
NormalizedParams::createFromRequest($request)
);

$requestHandler = GeneralUtility::makeInstance(RequestHandler::class);
$requestHandler->handle($request);

Expand Down
33 changes: 30 additions & 3 deletions Tests/Integration/TSFETestBootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace ApacheSolrForTypo3\Solr\Tests\Integration;

use DateTimeImmutable;
use Exception;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\DateTimeAspect;
use TYPO3\CMS\Core\Context\VisibilityAspect;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Error\Http\AbstractServerErrorException;
use TYPO3\CMS\Core\Error\Http\InternalServerErrorException;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
Expand All @@ -15,6 +20,7 @@
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Aspect\PreviewAspect;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand All @@ -28,9 +34,12 @@ class TSFETestBootstrapper
* @param string $MP
* @param int $language
* @return TSFEBootstrapResult
*
* @throws SiteNotFoundException
* @throws InternalServerErrorException
* @throws ServiceUnavailableException
* @throws AbstractServerErrorException
* @throws Exception
*/
public function bootstrap(int $pageId, string $MP = '', int $language = 0): TSFEBootstrapResult
{
Expand All @@ -41,7 +50,7 @@ public function bootstrap(int $pageId, string $MP = '', int $language = 0): TSFE
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$request = GeneralUtility::makeInstance(ServerRequest::class);

$pageArguments = GeneralUtility::makeInstance(PageArguments::class, $pageId, 0, ['MP' => $MP]);
$pageArguments = GeneralUtility::makeInstance(PageArguments::class, $pageId, '0', ['MP' => $MP]);
if ($MP !== '') {
[$origPageId, $pageIdToUse] = GeneralUtility::trimExplode('-', $MP);
$site = $siteFinder->getSiteByPageId($pageIdToUse);
Expand All @@ -68,14 +77,32 @@ public function bootstrap(int $pageId, string $MP = '', int $language = 0): TSFE
$TSFE = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $context, $site, $siteLanguage, $pageArguments, $feUser);
$TSFE->set_no_cache('', true);
$GLOBALS['TSFE'] = $TSFE;
$TSFE->clear_preview();

$GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
$GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
$context->setAspect(
'frontend.preview',
GeneralUtility::makeInstance(PreviewAspect::class)
);
$context->setAspect(
'date',
GeneralUtility::makeInstance(
DateTimeAspect::class,
new DateTimeImmutable('@' . $GLOBALS['SIM_EXEC_TIME'])
)
);
$context->setAspect(
'visibility',
GeneralUtility::makeInstance(VisibilityAspect::class)
);

$template = GeneralUtility::makeInstance(TemplateService::class);
$GLOBALS['TSFE']->tmpl = $template;

try {
$GLOBALS['TSFE']->determineId($GLOBALS['TYPO3_REQUEST']);
$GLOBALS['TSFE']->getConfigArray();
$GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TSFE']->getFromCache($request);
$GLOBALS['TSFE']->releaseLocks();
} catch (ImmediateResponseException $e) {
$result->addExceptions($e);
}
Expand Down

0 comments on commit 3d3aae9

Please sign in to comment.