Skip to content

Commit

Permalink
[TASK] Improve a couple of test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jul 13, 2024
1 parent 50f8b20 commit c847e4f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Tests/Unit/Integration/HookSubscribers/WizardItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,40 @@ protected function setUp(): void
->getMock();

$GLOBALS['TYPO3_REQUEST'] = $this->getMockBuilder(ServerRequestInterface::class)->getMockForAbstractClass();
$GLOBALS['TYPO3_REQUEST']->method('getQueryParams')->willReturn(['id' => 123, 'colPos' => 12]);
}

public function testDelegatesToWizardItemsManipulator(): void
{
$GLOBALS['TYPO3_REQUEST']->method('getQueryParams')->willReturn(['id' => 123, 'colPos' => 12]);

$pageUid = 123;
$columnPosition = 12;
$controller = $this->getMockBuilder(NewContentElementController::class)
->disableOriginalConstructor()
->getMock();
$items = [];
$this->wizardItemsManipulator->expects(self::once())->method('manipulateWizardItems')->with(
$items,
$pageUid,
$columnPosition
);
$subject = new WizardItems($this->wizardItemsManipulator);
$subject->manipulateWizardItems($items, $controller);
}

public function testReadsPageUidAndColumnPositionFromParentObjectIfNotPresentInRequestArguments(): void
{
$GLOBALS['TYPO3_REQUEST']->method('getQueryParams')->willReturn([]);

$pageUid = 123;
$columnPosition = 12;
$controller = $this->getMockBuilder(NewContentElementController::class)
->disableOriginalConstructor()
->getMock();

$this->setInaccessiblePropertyValue($controller, 'id', $pageUid);
$this->setInaccessiblePropertyValue($controller, 'colPos', $columnPosition);

$items = [];
$this->wizardItemsManipulator->expects(self::once())->method('manipulateWizardItems')->with(
$items,
Expand Down
19 changes: 19 additions & 0 deletions Tests/Unit/Integration/WizardItemsManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use FluidTYPO3\Flux\Utility\ColumnNumberUtility;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;

Expand Down Expand Up @@ -263,4 +264,22 @@ public function testGetWhiteAndBlackListsFromPageAndContentColumn(): void
self::assertSame($expectedWhitelist, $whitelist, 'Whitelist does not match expected value');
self::assertSame($expectedBlacklist, $blacklist, 'Blacklist does not match expected value');
}

public function testManipulateWizardItemsToleratesSiteNotFoundException(): void
{
$this->siteFinder->expects(self::atLeastOnce())
->method('getSiteByPageId')
->willThrowException(new SiteNotFoundException('test'));
$this->subject->manipulateWizardItems([], 1, null);
}

public function testFindParentColumnPositionRecursesToSelfWithVirtualColumnPosition(): void
{
$this->recordService->method('getSingle')->willReturnOnConsecutiveCalls(
['colPos' => 10010],
['colPos' => 4]
);
$output = $this->callInaccessibleMethod($this->subject, 'findParentColumnPosition', 1);
self::assertSame(4, $output);
}
}

0 comments on commit c847e4f

Please sign in to comment.