‪TYPO3CMS  10.4
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 Prophecy\Argument;
21 use Psr\Http\Message\ServerRequestInterface;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 class ‪PreviewModuleTest extends UnitTestCase
30 {
31  public function ‪simulateDateDataProvider(): array
32  {
33  return [
34  'timestamp' => [
35  (string)(new \DateTime('2018-01-01 12:00:15 UTC'))->getTimestamp(),
36  (int)(new \DateTime('2018-01-01 12:00:15 UTC'))->getTimestamp(),
37  (int)(new \DateTime('2018-01-01 12:00:00 UTC'))->getTimestamp(),
38  ],
39  'timestamp_1970' => [
40  (string)(new \DateTime('1970-01-01 00:00:15 UTC'))->getTimestamp(),
41  (int)(new \DateTime('1970-01-01 00:00:60 UTC'))->getTimestamp(),
42  (int)(new \DateTime('1970-01-01 00:00:60 UTC'))->getTimestamp(),
43  ],
44  ];
45  }
46 
54  public function ‪initializeFrontendPreviewSetsDateForSimulation(string $dateToSimulate, int $expectedExecTime, int $expectedAccessTime): void
55  {
56  $this->resetSingletonInstances = true;
57  $request = $this->prophesize(ServerRequestInterface::class);
58  $configurationService = $this->prophesize(ConfigurationService::class);
59  $configurationService->getMainConfiguration()->willReturn([]);
60  $configurationService->getConfigurationOption('preview', 'simulateDate')->willReturn($dateToSimulate);
61  $configurationService->getConfigurationOption('preview', Argument::any())->willReturn('');
62 
63  GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
64 
65  $previewModule = new ‪PreviewModule();
66  $previewModule->enrich($request->reveal());
67 
68  self::assertSame(‪$GLOBALS['SIM_EXEC_TIME'], $expectedExecTime, 'EXEC_TIME');
69  self::assertSame(‪$GLOBALS['SIM_ACCESS_TIME'], $expectedAccessTime, 'ACCESS_TIME');
70  }
71 
76  {
77  $this->resetSingletonInstances = true;
78  $request = $this->prophesize(ServerRequestInterface::class);
79  $request->getQueryParams()->willReturn([]);
80  $request->getAttribute('frontend.user')->willReturn($this->prophesize(FrontendUserAuthentication::class)->reveal());
81  $configurationService = $this->prophesize(ConfigurationService::class);
82  $configurationService->getMainConfiguration()->willReturn([]);
83  $configurationService->getConfigurationOption('preview', 'showHiddenPages')->willReturn('0');
84  $configurationService->getConfigurationOption('preview', 'simulateDate')->willReturn('0');
85  $configurationService->getConfigurationOption('preview', 'showHiddenRecords')->willReturn('0');
86  $configurationService->getConfigurationOption('preview', 'showFluidDebug')->willReturn('0');
87  $configurationService->getConfigurationOption('preview', 'simulateUserGroup')->willReturn('1');
88  $context = $this->prophesize(Context::class);
89  GeneralUtility::setSingletonInstance(Context::class, $context->reveal());
90 
91  GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
92 
93  $previewModule = new ‪PreviewModule();
94  $previewModule->enrich($request->reveal());
95 
96  $context->setAspect('frontend.user', Argument::any())->shouldHaveBeenCalled();
97  }
98 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\initializeFrontendPreviewSetsDateForSimulation
‪initializeFrontendPreviewSetsDateForSimulation(string $dateToSimulate, int $expectedExecTime, int $expectedAccessTime)
Definition: PreviewModuleTest.php:54
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules
Definition: PreviewModuleTest.php:18
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest
Definition: PreviewModuleTest.php:30
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:34
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\initializeFrontendPreviewSetsUsergroupForSimulation
‪initializeFrontendPreviewSetsUsergroupForSimulation()
Definition: PreviewModuleTest.php:75
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\simulateDateDataProvider
‪simulateDateDataProvider()
Definition: PreviewModuleTest.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Modules\PreviewModule
Definition: PreviewModule.php:39
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46