[FEATURE] Show only sys_languages in Backend which are available
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Functional / View / PageLayoutViewTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Backend\Tests\Functional\View;
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\Backend\View\PageLayoutView;
20 use TYPO3\CMS\Core\Core\Bootstrap;
21 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25
26 class PageLayoutViewTest extends FunctionalTestCase
27 {
28 /**
29 * @var PageLayoutView|AccessibleObjectInterface
30 */
31 private $subject;
32
33 /**
34 * Sets up this test case.
35 */
36 protected function setUp(): void
37 {
38 parent::setUp();
39
40 $this->setUpBackendUserFromFixture(1);
41 Bootstrap::initializeLanguageObject();
42
43 $this->subject = $this->getAccessibleMock(PageLayoutView::class, ['dummy']);
44 $this->subject->_set('siteLanguages', [
45 0 => new SiteLanguage(0, '', '/', [
46 'title' => 'default',
47 ]),
48 1 => new SiteLanguage(1, '', '/', [
49 'title' => 'german',
50 ]),
51 2 => new SiteLanguage(2, '', '/', [
52 'title' => 'french',
53 ]),
54 3 => new SiteLanguage(3, '', '/', [
55 'title' => 'polish',
56 ]),
57 ]);
58 }
59
60 /**
61 * @test
62 */
63 public function languageSelectorShowsAllAvailableLanguagesForTranslation()
64 {
65 $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/View/Fixtures/LanguageSelectorScenarioDefault.csv');
66
67 $result = $this->subject->languageSelector(17);
68
69 $matches = [];
70
71 preg_match_all('/<option value=.+<\/option>/', $result, $matches);
72 $resultingOptions = GeneralUtility::trimExplode('</option>', $matches[0][0], true);
73 $this->assertCount(4, $resultingOptions);
74 // first entry is the empty option
75 $this->assertStringEndsWith('german', $resultingOptions[1]);
76 $this->assertStringEndsWith('french', $resultingOptions[2]);
77 $this->assertStringEndsWith('polish', $resultingOptions[3]);
78 }
79
80 /**
81 * @test
82 */
83 public function languageSelectorDoesNotOfferLanguageIfTranslationHasBeenDoneAlready()
84 {
85 $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/View/Fixtures/LanguageSelectorScenarioTranslationDone.csv');
86 $result = $this->subject->languageSelector(17);
87
88 $matches = [];
89
90 preg_match_all('/<option value=.+<\/option>/', $result, $matches);
91 $resultingOptions = GeneralUtility::trimExplode('</option>', $matches[0][0], true);
92 $this->assertCount(3, $resultingOptions);
93 // first entry is the empty option
94 $this->assertStringEndsWith('german', $resultingOptions[1]);
95 $this->assertStringEndsWith('french', $resultingOptions[2]);
96 }
97 }