Skip to content

Commit

Permalink
[FIX] tests for TYPO3 13 @ 2024.07.02
Browse files Browse the repository at this point in the history
  • Loading branch information
dkd-kaehm committed Jul 3, 2024
1 parent 4c13753 commit 47901bf
Show file tree
Hide file tree
Showing 50 changed files with 296 additions and 351 deletions.
23 changes: 19 additions & 4 deletions Classes/Domain/Index/Queue/UpdateHandler/DataUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function handleMovedPage(int $uid, ?int $previousParentId = null): void
$this->applyPageChangesToQueue($uid);

if ($previousParentId !== null) {
$pageRecord = BackendUtility::getRecord('pages', $uid);
$pageRecord = $this->getRecord('pages', $uid);
if ($pageRecord !== null && (int)$pageRecord['pid'] !== $previousParentId) {
$treePageIds = $this->getSubPageIds($uid);
$this->updatePageIdItems($treePageIds);
Expand Down Expand Up @@ -386,8 +386,8 @@ protected function processPageRecord(int $uid, int $pid, array $updatedFields =
$this->mountPageUpdater->update($uid);

// We need to get the full record to find out if this is a page translation
$fullRecord = BackendUtility::getRecord('pages', $uid);
if ($fullRecord['sys_language_uid'] > 0) {
$fullRecord = $this->getRecord('pages', $uid);
if (($fullRecord['sys_language_uid'] ?? null) > 0) {
$uid = (int)$fullRecord['l10n_parent'];
}

Expand Down Expand Up @@ -491,7 +491,7 @@ protected function getConfigurationPageId(string $recordTable, int $recordPageId
*/
protected function getIsTranslationParentRecordEnabled(string $recordTable, int $recordUid): bool
{
$l10nParentRecord = (array)BackendUtility::getRecord($recordTable, $recordUid, '*', '', false);
$l10nParentRecord = (array)$this->getRecord($recordTable, $recordUid, '*', '', false);
return $this->tcaService->isEnabledRecord($recordTable, $l10nParentRecord);
}

Expand Down Expand Up @@ -548,4 +548,19 @@ protected function getSiteRepository(): SiteRepository
{
return GeneralUtility::makeInstance(SiteRepository::class);
}

/**
* Wraps {@link BackendUtility::getRecord()}
*
* Purpose: Unit-Tests
*/
protected function getRecord(
string $table,
int|string $uid,
string $fields = '*',
string $where = '',
bool $useDeleteClause = true,
): ?array {
return BackendUtility::getRecord($table, $uid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@

namespace ApacheSolrForTypo3\Solr\Event\Indexing;

use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Allows to add more documents to the Solr index.
*
* Previously used with
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments']
*/
class BeforePageDocumentIsProcessedForIndexingEvent extends BeforeDocumentIsProcessedForIndexingEvent
{
}
class BeforePageDocumentIsProcessedForIndexingEvent extends BeforeDocumentIsProcessedForIndexingEvent {}
1 change: 0 additions & 1 deletion Classes/IndexQueue/AbstractIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
Expand Down
10 changes: 5 additions & 5 deletions Classes/System/Solr/Service/AbstractSolrService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
abstract class AbstractSolrService
{
protected static array $pingCache = [];

protected TypoScriptConfiguration $configuration;

protected SolrLogManager $logger;

protected Client $client;

public function __construct(Client $client, $typoScriptConfiguration = null, $logManager = null)
{
public function __construct(
Client $client,
TypoScriptConfiguration $typoScriptConfiguration = null,
SolrLogManager $logManager = null,
) {
$this->client = $client;
$this->configuration = $typoScriptConfiguration ?? Util::getSolrConfiguration();
$this->logger = $logManager ?? GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
Expand Down
1 change: 1 addition & 0 deletions Tests/Integration/Backend/SettingsPreviewOnPluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected function getFakePageContentPreviewRenderingEvent(string $table = 'tt_c
{
return new PageContentPreviewRenderingEvent(
$table,
(string)($record[(string)($GLOBALS['TCA'][$table]['ctrl']['type'] ?? '')] ?? ''),
$record,
$this->createMock(PageLayoutContext::class)
);
Expand Down
15 changes: 9 additions & 6 deletions Tests/Integration/Domain/Index/Queue/QueueItemRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -108,7 +108,8 @@ public function canFindItems(): void
public function canFindItemsAndModifyViaEventListener(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/pages_and_news_queueitems.csv');
$eventDispatcher = new MockEventDispatcher();
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);

$queueItemRepository = GeneralUtility::makeInstance(QueueItemRepository::class, null, $eventDispatcher);
$items = $queueItemRepository->findItems([], ['pages']);

Expand All @@ -117,11 +118,13 @@ public function canFindItemsAndModifyViaEventListener(): void
self::assertSame(2, count($items));
self::assertSame('pages', $firstItem->getType(), 'First item has unexpected type');

$eventDispatcher->addListener(function(AfterRecordsForIndexQueueItemsHaveBeenRetrievedEvent $event): void {
if ($event->getTable() === 'pages') {
$event->setRecords([]);
$eventDispatcher->expects(self::once())->method('dispatch')->willReturnCallback(
static function(AfterRecordsForIndexQueueItemsHaveBeenRetrievedEvent $event): void {
if ($event->getTable() === 'pages') {
$event->setRecords([]);
}
}
});
);

$items = $queueItemRepository->findItems([], ['pages']);
self::assertCount(0, $items);
Expand Down
2 changes: 2 additions & 0 deletions Tests/Unit/Backend/SettingsPreviewOnPluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function doesNotPrintPreviewOnNonExtSolrPlugins(): void
'tt_content',
[
'list_type' => 'some_other_CE',
//'CType' => '',
]
)
);
Expand All @@ -74,6 +75,7 @@ protected function getFakePageContentPreviewRenderingEvent(
$pageLayoutContextMock = $this->createMock(PageLayoutContext::class);
return new PageContentPreviewRenderingEvent(
$table,
(string)($record[(string)($GLOBALS['TCA'][$table]['ctrl']['type'] ?? '')] ?? ''),
$record,
$pageLayoutContextMock
);
Expand Down
4 changes: 3 additions & 1 deletion Tests/Unit/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Psr\Http\Message\StreamFactoryInterface;
use Symfony\Component\DependencyInjection\Container;
use Traversable;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down Expand Up @@ -67,6 +68,7 @@ protected function setUp(): void
$container->set(RequestFactoryInterface::class, $this->createMock(RequestFactoryInterface::class));
$container->set(StreamFactoryInterface::class, $this->createMock(StreamFactoryInterface::class));
$container->set(EventDispatcherInterface::class, $this->createMock(EventDispatcherInterface::class));
$container->set(SiteFinder::class, $this->createMock(SiteFinder::class));
GeneralUtility::setContainer($container);

parent::setUp();
Expand Down Expand Up @@ -119,7 +121,7 @@ public static function connectDataProvider(): Traversable
}

/**
* Tests the connect
* Tests the connection
*/
#[DataProvider('connectDataProvider')]
#[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@

/**
* Testcase for IndexQueueModuleController
*
* @property IndexAdministrationModuleController|MockObject $controller
*/
class IndexAdministrationModuleControllerTest extends AbstractModuleController
class IndexAdministrationModuleControllerTest extends SetUpSolrModuleControllerTestCase
{
/**
* @var IndexAdministrationModuleController|MockObject
*/
protected $controller;

protected function setUp(): void
{
parent::setUpConcreteModuleController(IndexAdministrationModuleController::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,30 @@
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\ConfigurationAwareRecordService;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\Statistic\QueueStatisticsRepository;
use ApacheSolrForTypo3\Solr\Event\IndexQueue\AfterIndexQueueItemHasBeenMarkedForReindexingEvent;
use ApacheSolrForTypo3\Solr\FrontendEnvironment;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;

/**
* Testcase for IndexQueueModuleController
*
* @property IndexQueueModuleController|MockObject $controller
*/
class IndexQueueModuleControllerTest extends AbstractModuleController
class IndexQueueModuleControllerTest extends SetUpSolrModuleControllerTestCase
{
protected Queue|MockObject $indexQueueMock;

/**
* @var IndexQueueModuleController|MockObject
*/
protected $controller;

protected MockEventDispatcher $eventDispatcher;
protected EventDispatcherInterface|MockObject $eventDispatcher;

protected function setUp(): void
{
parent::setUpConcreteModuleController(
IndexQueueModuleController::class,
['addIndexQueueFlashMessage']
);
$this->eventDispatcher = new MockEventDispatcher();
$this->eventDispatcher = new NoopEventDispatcher();
$this->indexQueueMock = $this->getMockBuilder(Queue::class)
->onlyMethods(['updateOrAddItemForAllRelatedRootPages'])
->setConstructorArgs([
Expand Down Expand Up @@ -78,10 +74,6 @@ public function requeueDocumentActionIsTriggeringReIndexOnIndexQueue(): void
#[Test]
public function hookIsTriggeredWhenRegistered(): void
{
$this->eventDispatcher->addListener(function(AfterIndexQueueItemHasBeenMarkedForReindexingEvent $event) {
$event->setUpdateCount(5);
});

$this->indexQueueMock->expects(self::once())->method('updateOrAddItemForAllRelatedRootPages')->willReturn(0);

$this->assertQueueUpdateIsTriggeredFor('tx_solr_file', 88);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace ApacheSolrForTypo3\Solr\Tests\Unit\Controller\Backend\Search;

use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Controller\Backend\Search\AbstractModuleController as ModuleController;
use ApacheSolrForTypo3\Solr\Controller\Backend\Search\AbstractModuleController as AbstractSolrModuleController;
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
Expand All @@ -28,13 +28,9 @@
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;

abstract class AbstractModuleController extends SetUpUnitTestCase
abstract class SetUpSolrModuleControllerTestCase extends SetUpUnitTestCase
{
/**
* @var ModuleController|MockObject
*/
protected $controller;

protected AbstractSolrModuleController|MockObject $controller;
protected Site|MockObject $selectedSiteMock;
protected ConnectionManager|MockObject $connectionManagerMock;

Expand All @@ -46,7 +42,8 @@ protected function setUpConcreteModuleController(
array $mockMethods = ['addFlashMessage']
): void {
$this->selectedSiteMock = $this->createMock(Site::class);
/** @var ModuleController|MockObject $subject */
/** @var AbstractSolrModuleController|MockObject $subject */
/** @noinspection PhpUnitInvalidMockingEntityInspection The dg/bypass-finals is used in project */
$subject = $this->getMockBuilder($concreteModuleControllerClass)
->setConstructorArgs(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DataUpdateHandlerTest extends SetUpUpdateHandler
{
private const DUMMY_PAGE_ID = 10;

protected DataUpdateHandler $dataUpdateHandler;
protected DataUpdateHandler|MockObject $dataUpdateHandler;

protected MountPagesUpdater|MockObject $mountPagesUpdaterMock;

Expand All @@ -55,17 +55,31 @@ protected function setUp(): void
$this->dataHandlerMock = $this->createMock(DataHandler::class);
$this->loggerMock = $this->createMock(SolrLogManager::class);

$this->dataUpdateHandler = new DataUpdateHandler(
$this->recordServiceMock,
$this->frontendEnvironmentMock,
$this->tcaServiceMock,
$this->indexQueueMock,
$this->mountPagesUpdaterMock,
$this->rootPageResolverMock,
$this->pagesRepositoryMock,
$this->dataHandlerMock,
$this->loggerMock
$this->dataUpdateHandler = $this->getAccessibleMock(
DataUpdateHandler::class,
[
'getRecord',
],
[
$this->recordServiceMock,
$this->frontendEnvironmentMock,
$this->tcaServiceMock,
$this->indexQueueMock,
$this->mountPagesUpdaterMock,
$this->rootPageResolverMock,
$this->pagesRepositoryMock,
$this->dataHandlerMock,
$this->loggerMock,
]
);
$this->dataUpdateHandler
->expects(self::any())
->method('getRecord')
->willReturn([
'uid' => self::DUMMY_PAGE_ID,
'title' => 'dummy page on which dummy ce is placed',
'sys_language_uid' => 0,
]);

$this->dataHandlerMock
->expects(self::any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Index\Queue\UpdateHandler\EventListener;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\AbstractBaseEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\DelayedProcessingEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\DelayedProcessingQueuingFinishedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent;
Expand All @@ -25,14 +24,11 @@

/**
* Testcase for the DelayedProcessingEventListener
*
* @property DelayedProcessingEventListener $listener
*/
class DelayedProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var DelayedProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

#[Test]
public function canHandleEvents(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Index\Queue\UpdateHandler\EventListener;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\DataUpdateHandler;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\AbstractBaseEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\ProcessingFinishedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\ImmediateProcessingEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\ContentElementDeletedEvent;
Expand All @@ -36,14 +35,11 @@

/**
* Testcase for the ImmediateProcessingEventListener
*
* @property ImmediateProcessingEventListener $listener
*/
class ImmediateProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var ImmediateProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

protected function setUp(): void
{
if (!class_exists('SolrUnitTestsInvalidDataUpdateEvent')) {
Expand Down