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