[BUGFIX] Fix getSiteFinder() mocking in SiteProcessorTest
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / DataProcessing / SiteProcessorTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Frontend\Tests\Unit\DataProcessing;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\Exception\SiteNotFoundException;
20 use TYPO3\CMS\Core\Site\Entity\Site;
21 use TYPO3\CMS\Core\Site\SiteFinder;
22 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
23 use TYPO3\CMS\Frontend\DataProcessing\SiteProcessor;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Testcase
28 */
29 class SiteProcessorTest extends UnitTestCase
30 {
31
32 /**
33 * @test
34 */
35 public function siteIsRetrieved(): void
36 {
37 $processorConfiguration = ['as' => 'variable'];
38 $mockedContentObjectRenderer = $this->getAccessibleMock(ContentObjectRenderer::class, ['stdWrapValue'], [], '', false);
39 $mockedContentObjectRenderer->expects($this->any())->method('stdWrapValue')->with('as', $processorConfiguration, 'site')->willReturn('variable');
40
41 $site = new Site('site123', 123, []);
42
43 $subject = $this->getAccessibleMock(SiteProcessor::class, ['getCurrentSite'], []);
44 $subject->expects($this->any())->method('getCurrentSite')->willReturn($site);
45
46 $processedData = $subject->process($mockedContentObjectRenderer, [], $processorConfiguration, []);
47
48 $this->assertEquals($site, $processedData['variable']);
49 }
50
51 /**
52 * @test
53 */
54 public function nullIsProvidedIfSiteCouldNotBeRetrieved(): void
55 {
56 $processorConfiguration = ['as' => 'variable'];
57 $mockedContentObjectRenderer = $this->getAccessibleMock(ContentObjectRenderer::class, ['stdWrapValue'], [], '', false);
58 $mockedContentObjectRenderer->expects($this->any())->method('stdWrapValue')->with('as', $processorConfiguration, 'site')->willReturn('variable');
59
60 $finderMock = $this->getMockBuilder(SiteFinder::class)->disableOriginalConstructor()->getMock();
61 $finderMock->expects($this->any())->method('getSiteByPageId')->willThrowException(new SiteNotFoundException('message', 1550670118));
62
63 $subject = $this->getAccessibleMock(SiteProcessor::class, ['getSiteFinder', 'getCurrentPageId'], []);
64 $subject->expects($this->any())->method('getSiteFinder')->willReturn($finderMock);
65 $subject->expects($this->any())->method('getCurrentPageId')->willReturn(1);
66
67 $processedData = $subject->process($mockedContentObjectRenderer, [], $processorConfiguration, []);
68
69 $this->assertNull($processedData['variable']);
70 }
71 }