|
8 | 8 | * LICENSE.md file that was distributed with this source code.
|
9 | 9 | */
|
10 | 10 |
|
| 11 | +use FluidTYPO3\Vhs\Tests\Fixtures\Classes\DummyQueryBuilder; |
11 | 12 | use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
|
12 | 13 | use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTestCase;
|
| 14 | +use FluidTYPO3\Vhs\ViewHelpers\Condition\Page\IsLanguageViewHelper; |
| 15 | +use TYPO3\CMS\Core\Context\Context; |
| 16 | +use TYPO3\CMS\Core\Context\LanguageAspect; |
| 17 | +use TYPO3\CMS\Core\Database\ConnectionPool; |
13 | 18 | use TYPO3\CMS\Core\Database\DatabaseConnection;
|
14 |
| -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
| 19 | +use TYPO3\CMS\Core\Utility\GeneralUtility; |
| 20 | +use TYPO3\CMS\Core\Utility\VersionNumberUtility; |
| 21 | +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
15 | 22 |
|
16 | 23 | /**
|
17 | 24 | * Class IsLanguageViewHelperTest
|
18 | 25 | */
|
19 | 26 | class IsLanguageViewHelperTest extends AbstractViewHelperTestCase
|
20 | 27 | {
|
21 |
| - public function testRender() |
| 28 | + protected function setUp(): void |
22 | 29 | {
|
23 |
| - $GLOBALS['TYPO3_DB'] = $this->getMockBuilder(DatabaseConnection::class)->setMethods(['exec_SELECTgetSingleRow'])->disableOriginalConstructor()->getMock(); |
24 |
| - $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue(false)); |
25 |
| - |
26 |
| - $GLOBALS['TSFE'] = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock(); |
27 |
| - $GLOBALS['TSFE']->expects($this->any())->method('__get')->with('sys_language_uid')->willReturn(0); |
28 |
| - |
29 |
| - $arguments = [ |
30 |
| - 'then' => 'then', |
31 |
| - 'else' => 'else', |
32 |
| - 'language' => 0 |
33 |
| - ]; |
34 |
| - $result = $this->executeViewHelper($arguments); |
35 |
| - $this->assertEquals('then', $result); |
| 30 | + $language = $this->getMockBuilder(LanguageAspect::class) |
| 31 | + ->onlyMethods(['getId']) |
| 32 | + ->disableOriginalConstructor() |
| 33 | + ->getMock(); |
| 34 | + $language->method('getId')->willReturn(123); |
| 35 | + |
| 36 | + $context = $this->getMockBuilder(Context::class) |
| 37 | + ->onlyMethods(['getAspect']) |
| 38 | + ->disableOriginalConstructor() |
| 39 | + ->getMock(); |
| 40 | + $context->method('getAspect')->with('language')->willReturn($language); |
| 41 | + |
| 42 | + $this->singletonInstances[Context::class] = $context; |
| 43 | + |
| 44 | + parent::setUp(); |
| 45 | + } |
| 46 | + |
| 47 | + public function testWithLanguageAsStringLocale(): void |
| 48 | + { |
| 49 | + $queryBuilder = new DummyQueryBuilder($this); |
| 50 | + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4', '>=')) { |
| 51 | + $queryBuilder->result->method('fetchAssociative')->willReturn(['uid' => 123]); |
| 52 | + } else { |
| 53 | + $queryBuilder->result->method('fetch')->willReturn(['uid' => 123]); |
| 54 | + } |
| 55 | + |
| 56 | + $connectionPool = $this->getMockBuilder(ConnectionPool::class) |
| 57 | + ->onlyMethods(['getQueryBuilderForTable']) |
| 58 | + ->disableOriginalConstructor() |
| 59 | + ->getMock(); |
| 60 | + $connectionPool->method('getQueryBuilderForTable')->willReturn($queryBuilder); |
| 61 | + |
| 62 | + GeneralUtility::addInstance(ConnectionPool::class, $connectionPool); |
| 63 | + |
| 64 | + $renderingContext = $this->getMockBuilder(RenderingContextInterface::class)->getMock(); |
| 65 | + self::assertTrue( |
| 66 | + IsLanguageViewHelper::verdict(['language' => 'en', 'defaultTitle' => 'en'], $renderingContext) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + public function testWithLanguageAsUid(): void |
| 71 | + { |
| 72 | + $renderingContext = $this->getMockBuilder(RenderingContextInterface::class)->getMock(); |
| 73 | + self::assertTrue( |
| 74 | + IsLanguageViewHelper::verdict(['language' => 123, 'defaultTitle' => 'en'], $renderingContext) |
| 75 | + ); |
36 | 76 | }
|
37 | 77 | }
|
0 commit comments