‪TYPO3CMS  9.5
SiteProcessorTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪SiteProcessorTest extends UnitTestCase
30 {
31 
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 
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  $matcherMock = $this->getMockBuilder(SiteMatcher::class)->disableOriginalConstructor()->getMock();
61  $matcherMock->expects($this->any())->method('matchByPageId')->willThrowException(new ‪SiteNotFoundException('message', 1550670118));
62 
63  $subject = $this->getAccessibleMock(SiteProcessor::class, ['getMatcher', 'getCurrentPageId'], []);
64  $subject->expects($this->any())->method('getMatcher')->willReturn($matcherMock);
65  $subject->expects($this->any())->method('getCurrentPageId')->willReturn(1);
66 
67  $processedData = $subject->process($mockedContentObjectRenderer, [], $processorConfiguration, []);
68 
69  $this->assertNull($processedData['variable']);
70  }
71 }
‪TYPO3\CMS\Frontend\DataProcessing\SiteProcessor
Definition: SiteProcessor.php:38
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:25
‪TYPO3\CMS\Frontend\Tests\Unit\DataProcessing\SiteProcessorTest
Definition: SiteProcessorTest.php:30
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Frontend\Tests\Unit\DataProcessing\SiteProcessorTest\siteIsRetrieved
‪siteIsRetrieved()
Definition: SiteProcessorTest.php:35
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Frontend\Tests\Unit\DataProcessing
Definition: SiteProcessorTest.php:4
‪TYPO3\CMS\Core\Routing\SiteMatcher
Definition: SiteMatcher.php:53
‪TYPO3\CMS\Frontend\Tests\Unit\DataProcessing\SiteProcessorTest\nullIsProvidedIfSiteCouldNotBeRetrieved
‪nullIsProvidedIfSiteCouldNotBeRetrieved()
Definition: SiteProcessorTest.php:54