Skip to content

Commit

Permalink
ci: add more tests (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnorre authored Oct 10, 2024
1 parent 512c81a commit eedd9af
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ infection.log
/Tests/.phpunit.cache/
/Infection/
/LOGGER-HTML
.Logs
reports/
report/
tools/
Expand Down
1 change: 0 additions & 1 deletion Classes/Helper/Sleeper/SystemSleeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

/*
* @internal
* @codeCoverageIgnore
*/
final class SystemSleeper implements SleeperInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Tests\Functional\Configuration;

/*
* (c) 2024- Tomas Norre Mikkelsen <[email protected]>
*
* This file is part of the TYPO3 Crawler Extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use AOE\Crawler\Configuration\ExtensionConfigurationProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class ExtensionConfigurationProviderTest extends FunctionalTestCase
{
public function testExceptionIsThrownAndCatchedIfExtensionNotLoaded(): void
{
$subject = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class);

self::assertIsArray($subject->getExtensionConfiguration());
self::assertEmpty($subject->getExtensionConfiguration());
}
}
69 changes: 69 additions & 0 deletions Tests/Functional/ContextMenu/ItemProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/*
* (c) 2024- Tomas Norre Mikkelsen <[email protected]>
*
* This file is part of the TYPO3 Crawler Extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace AOE\Crawler\Tests\Functional\ContextMenu;

use AOE\Crawler\ContextMenu\ItemProvider;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class ItemProviderTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['typo3conf/ext/crawler'];
private $oldBackendUser;

protected function setUp(): void
{
parent::setUp();
$mockedLanguageService = self::getAccessibleMock(LanguageService::class, ['sL'], [], '', false);
$mockedLanguageService->expects($this->any())->method('sL')->willReturn('language string');
$GLOBALS['LANG'] = $mockedLanguageService;
$this->oldBackendUser = $GLOBALS['BE_USER'] ?? null;
$backendUserStub = $this->createStub(BackendUserAuthentication::class);
$GLOBALS['BE_USER'] = $backendUserStub;
}

protected function tearDown(): void
{
if ($this->oldBackendUser) {
$GLOBALS['BE_USER'] = $this->oldBackendUser;
} else {
unset($GLOBALS['BE_USER']);
}
}

#[Test]
public function addItemsContactsItems(): void
{
$newItems = [
'other-ext' => [
'type' => 'item',
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:contextMenu.label',
'iconIdentifier' => 'tx-other-ext',
'callbackAction' => 'other-ext-callback',
],
];

$subject = new ItemProvider();
self::assertArrayHasKey('crawler', $subject->addItems($newItems));
self::assertArrayHasKey('other-ext', $subject->addItems($newItems));
}
}
37 changes: 37 additions & 0 deletions Tests/Unit/Helper/SystemSleeperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* (c) 2024- Tomas Norre Mikkelsen <[email protected]>
*
* This file is part of the TYPO3 Crawler Extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace AOE\Crawler\Tests\Unit\Helper;

use AOE\Crawler\Helper\Sleeper\SystemSleeper;
use PHPUnit\Framework\Attributes\CoversClass;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

#[CoversClass(SystemSleeper::class)]
class SystemSleeperTest extends UnitTestCase
{
public function testSystemSleeper(): void
{
$startTime = date('s');
$subject = new SystemSleeper();
$subject->sleep(1);
$endTime = date('s');
self::assertEquals(1, $endTime - $startTime);
}
}
36 changes: 36 additions & 0 deletions Tests/Unit/Hooks/DataHandlerHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,40 @@ public function ensureThatPageIdArrayIsConvertedToInteger(): void
$dataHandler
);
}

#[\PHPUnit\Framework\Attributes\Test]
public function ensureEarlyReturnIfPageIdsToBeFlushedFromCacheEmpty(): void
{
$mockedDataHandlerHook = $this->createPartialMock(
DataHandlerHook::class,
['getQueueRepository', 'getQueueService', 'getPageRepository']
);

$queueService = $this->prophesize(QueueService::class);
$queueService->addPageToQueue()->shouldNotBeCalled();

$queueRepository = $this->prophesize(QueueRepository::class);
$queueRepository->isPageInQueue()->shouldNotBeCalled();

$pageRepository = $this->prophesize(PageRepository::class);
$pageRepository->getPage()->shouldNotBeCalled();

$mockedDataHandlerHook->method('getQueueRepository')->willReturn($queueRepository->reveal());
$mockedDataHandlerHook->method('getQueueService')->willReturn($queueService->reveal());
$mockedDataHandlerHook->method('getPageRepository')->willReturn($pageRepository->reveal());

$cacheManager = $this->prophesize(CacheManager::class);
$cacheManager->getCache(Argument::any())->willReturn($this->prophesize(FrontendInterface::class)->reveal());
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal());

$dataHandler = new DataHandler();

self::assertNull($mockedDataHandlerHook->addFlushedPagesToCrawlerQueue(
[
'table' => 'pages',
'pageIdArray' => [],
],
$dataHandler
));
}
}

0 comments on commit eedd9af

Please sign in to comment.