‪TYPO3CMS  11.5
PageLayoutViewTest.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 
20 use Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Psr\EventDispatcher\EventDispatcherInterface;
30 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
31 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
32 
33 class ‪PageLayoutViewTest extends FunctionalTestCase
34 {
35  use ProphecyTrait;
36 
40  private ‪$subject;
41 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48 
49  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
50  $eventDispatcher->dispatch(Argument::cetera())->willReturnArgument(0);
51 
52  $this->setUpBackendUserFromFixture(1);
54 
55  $site = new ‪Site('test', 1, [
56  'identifier' => 'test',
57  'rootPageId' => 1,
58  'base' => '/',
59  'languages' => [
60  [
61  'languageId' => 0,
62  'locale' => '',
63  'base' => '/',
64  'title' => 'default',
65  ],
66  [
67  'languageId' => 1,
68  'locale' => '',
69  'base' => '/',
70  'title' => 'german',
71  ],
72  [
73  'languageId' => 2,
74  'locale' => '',
75  'base' => '/',
76  'title' => 'french',
77  ],
78  [
79  'languageId' => 3,
80  'locale' => '',
81  'base' => '/',
82  'title' => 'polish',
83  ],
84  ],
85  ]);
86  $this->subject = $this->getAccessibleMock(PageLayoutView::class, ['dummy'], [$eventDispatcher->reveal()]);
87  $this->subject->_set('siteLanguages', $site->getLanguages());
88 
89  ‪$GLOBALS['TYPO3_REQUEST'] = (new ‪ServerRequest('https://www.example.com/'))
90  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
91  ->withAttribute('normalizedParams', new ‪NormalizedParams([], [], '', ''));
92  }
93 
98  {
99  $this->importCSVDataSet(__DIR__ . '/Fixtures/LanguageSelectorScenarioDefault.csv');
100 
101  $result = $this->subject->languageSelector(17);
102 
103  $matches = [];
104 
105  preg_match_all('/<option value=.+<\/option>/', $result, $matches);
106  $resultingOptions = ‪GeneralUtility::trimExplode('</option>', $matches[0][0], true);
107  self::assertCount(4, $resultingOptions);
108  // first entry is the empty option
109  self::assertStringEndsWith('german', $resultingOptions[1]);
110  self::assertStringEndsWith('french', $resultingOptions[2]);
111  self::assertStringEndsWith('polish', $resultingOptions[3]);
112  }
113 
118  {
119  $this->importCSVDataSet(__DIR__ . '/Fixtures/LanguageSelectorScenarioTranslationDone.csv');
120  $result = $this->subject->languageSelector(17);
121 
122  $matches = [];
123 
124  preg_match_all('/<option value=.+<\/option>/', $result, $matches);
125  $resultingOptions = ‪GeneralUtility::trimExplode('</option>', $matches[0][0], true);
126  self::assertCount(3, $resultingOptions);
127  // first entry is the empty option
128  self::assertStringEndsWith('german', $resultingOptions[1]);
129  self::assertStringEndsWith('french', $resultingOptions[2]);
130  }
131 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Tests\Functional\View\PageLayoutViewTest\$subject
‪PageLayoutView AccessibleObjectInterface $subject
Definition: PageLayoutViewTest.php:38
‪TYPO3\CMS\Backend\Tests\Functional\View\PageLayoutViewTest\setUp
‪setUp()
Definition: PageLayoutViewTest.php:43
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Backend\Tests\Functional\View
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Backend\Tests\Functional\View\PageLayoutViewTest
Definition: PageLayoutViewTest.php:34
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\View\PageLayoutViewTest\languageSelectorShowsAllAvailableLanguagesForTranslation
‪languageSelectorShowsAllAvailableLanguagesForTranslation()
Definition: PageLayoutViewTest.php:95
‪TYPO3\CMS\Backend\Tests\Functional\View\PageLayoutViewTest\languageSelectorDoesNotOfferLanguageIfTranslationHasBeenDoneAlready
‪languageSelectorDoesNotOfferLanguageIfTranslationHasBeenDoneAlready()
Definition: PageLayoutViewTest.php:115
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\View\PageLayoutView
Definition: PageLayoutView.php:58
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35