‪TYPO3CMS  11.5
PreviewModuleTest.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 TYPO3\CMS\Adminpanel\Modules\PreviewModule;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 class ‪PreviewModuleTest extends UnitTestCase
29 {
30  protected ‪$resetSingletonInstances = true;
31 
32  public function ‪simulateDateDataProvider(): array
33  {
34  return [
35  'timestamp' => [
36  (string)(new \DateTime('2018-01-01 12:00:15 UTC'))->getTimestamp(),
37  (new \DateTime('2018-01-01 12:00:15 UTC'))->getTimestamp(),
38  (new \DateTime('2018-01-01 12:00:00 UTC'))->getTimestamp(),
39  ],
40  'timestamp_1970' => [
41  (string)(new \DateTime('1970-01-01 00:00:15 UTC'))->getTimestamp(),
42  (new \DateTime('1970-01-01 00:00:60 UTC'))->getTimestamp(),
43  (new \DateTime('1970-01-01 00:00:60 UTC'))->getTimestamp(),
44  ],
45  ];
46  }
47 
52  public function ‪initializeFrontendPreviewSetsDateForSimulation(string $dateToSimulate, int $expectedExecTime, int $expectedAccessTime): void
53  {
54  $configurationService = $this->getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock();
55  $configurationService->expects(self::once())->method('getMainConfiguration')->willReturn([]);
56  $valueMap = [
57  ['preview', 'showHiddenPages', ''],
58  ['preview', 'simulateDate', $dateToSimulate],
59  ['preview', 'simulateUserGroup', ''],
60  ['preview', 'showScheduledRecords', ''],
61  ['preview', 'showHiddenRecords', ''],
62  ['preview', 'showFluidDebug', ''],
63  ];
64  $configurationService->method('getConfigurationOption')->withAnyParameters()->willReturnMap($valueMap);
65 
66  GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService);
67 
68  $previewModule = new PreviewModule();
69  $previewModule->enrich(new ‪ServerRequest());
70 
71  self::assertSame(‪$GLOBALS['SIM_EXEC_TIME'], $expectedExecTime, 'EXEC_TIME');
72  self::assertSame(‪$GLOBALS['SIM_ACCESS_TIME'], $expectedAccessTime, 'ACCESS_TIME');
73  }
74 
79  {
80  $request = (new ‪ServerRequest())->withAttribute('frontend.user', $this->getMockBuilder(FrontendUserAuthentication::class)->getMock());
81 
82  $configurationService = $this->getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock();
83  $configurationService->expects(self::once())->method('getMainConfiguration')->willReturn([]);
84  $valueMap = [
85  ['preview', 'showHiddenPages', '0'],
86  ['preview', 'simulateDate', '0'],
87  ['preview', 'simulateUserGroup', '1'],
88  ['preview', 'showScheduledRecords', '0'],
89  ['preview', 'showHiddenRecords', '0'],
90  ['preview', 'showFluidDebug', '0'],
91  ];
92  $configurationService->method('getConfigurationOption')->withAnyParameters()->willReturnMap($valueMap);
93  GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService);
94 
95  $context = $this->getMockBuilder(Context::class)->getMock();
96  $context->method('hasAspect')->with('frontend.preview')->willReturn(false);
97  $context->expects(self::any())->method('setAspect')
98  ->withConsecutive(
99  ['date', self::anything()],
100  ['visibility', self::anything()],
101  ['visibility', self::anything()],
102  ['frontend.user', self::anything()],
103  ['frontend.preview', self::anything()],
104  );
105  GeneralUtility::setSingletonInstance(Context::class, $context);
106 
107  $previewModule = new PreviewModule();
108  $previewModule->enrich($request);
109  }
110 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\initializeFrontendPreviewSetsDateForSimulation
‪initializeFrontendPreviewSetsDateForSimulation(string $dateToSimulate, int $expectedExecTime, int $expectedAccessTime)
Definition: PreviewModuleTest.php:52
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules
Definition: PreviewModuleTest.php:18
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\initializeFrontendPreviewSetsUserGroupForSimulation
‪initializeFrontendPreviewSetsUserGroupForSimulation()
Definition: PreviewModuleTest.php:78
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest
Definition: PreviewModuleTest.php:29
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:34
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\simulateDateDataProvider
‪simulateDateDataProvider()
Definition: PreviewModuleTest.php:32
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: PreviewModuleTest.php:30
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50