5cb5712ab054edb283c7a9b51a01ec1051406dd9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Configuration / BackendConfigurationManagerTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Configuration;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager;
19 use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
20 use TYPO3\CMS\Extbase\Service\TypoScriptService;
21
22 /**
23 * Test case
24 */
25 class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
26 {
27 /**
28 * Warning: white box test
29 *
30 * @test
31 */
32 public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound()
33 {
34 $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
35 $mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
36 $backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
37
38 (new ConnectionPool())->getConnectionForTable('sys_template')->insert(
39 'sys_template',
40 [
41 'pid' => 123,
42 'deleted' => 0,
43 'hidden' => 0,
44 'root' => 1
45 ]
46 );
47
48 $actualResult = $backendConfigurationManager->_call('getCurrentPageId');
49 $this->assertEquals(123, $actualResult);
50 }
51
52 /**
53 * Warning: white box test
54 *
55 * @test
56 */
57 public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet()
58 {
59 $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
60 $mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
61 $backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
62
63 (new ConnectionPool())->getConnectionForTable('pages')->insert(
64 'pages',
65 [
66 'deleted' => 0,
67 'hidden' => 0,
68 'is_siteroot' => 1
69 ]
70 );
71
72 $actualResult = $backendConfigurationManager->_call('getCurrentPageId');
73 $this->assertEquals(1, $actualResult);
74 }
75
76 /**
77 * Warning: white box test
78 *
79 * @test
80 */
81 public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound()
82 {
83 $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
84 $mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
85 $backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
86
87 $expectedResult = AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID;
88 $actualResult = $backendConfigurationManager->_call('getCurrentPageId');
89 $this->assertEquals($expectedResult, $actualResult);
90 }
91 }