‪TYPO3CMS  9.5
PreviewModuleTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 use Prophecy\Argument;
7 use Psr\Http\Message\ServerRequestInterface;
14 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
15 
16 class ‪PreviewModuleTest extends UnitTestCase
17 {
18  public function ‪simulateDateDataProvider(): array
19  {
20  return [
21  'timestamp' => [
22  (new \DateTime('2018-01-01 12:00:15 UTC'))->getTimestamp(),
23  (int)(new \DateTime('2018-01-01 12:00:15 UTC'))->getTimestamp(),
24  (int)(new \DateTime('2018-01-01 12:00:00 UTC'))->getTimestamp(),
25  ],
26  'timestamp_1970' => [
27  (string)(new \DateTime('1970-01-01 00:00:15 UTC'))->getTimestamp(),
28  (int)(new \DateTime('1970-01-01 00:00:60 UTC'))->getTimestamp(),
29  (int)(new \DateTime('1970-01-01 00:00:60 UTC'))->getTimestamp(),
30  ],
31  ];
32  }
33 
41  public function ‪initializeFrontendPreviewSetsDateForSimulation(string $dateToSimulate, int $expectedExecTime, int $expectedAccessTime): void
42  {
43  $this->resetSingletonInstances = true;
44  $request = $this->prophesize(ServerRequestInterface::class);
45  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
46  ‪$GLOBALS['TSFE'] = $tsfe->reveal();
47  $configurationService = $this->prophesize(ConfigurationService::class);
48  $configurationService->getMainConfiguration()->willReturn([]);
49  $configurationService->getConfigurationOption('preview', 'simulateDate')->willReturn($dateToSimulate);
50  $configurationService->getConfigurationOption('preview', Argument::any())->willReturn('');
51 
52  GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
53 
54  $previewModule = new ‪PreviewModule();
55  $previewModule->initializeModule($request->reveal());
56 
57  self::assertSame(‪$GLOBALS['SIM_EXEC_TIME'], $expectedExecTime, 'EXEC_TIME');
58  self::assertSame(‪$GLOBALS['SIM_ACCESS_TIME'], $expectedAccessTime, 'ACCESS_TIME');
59  }
60 
65  {
66  $this->resetSingletonInstances = true;
67  $request = $this->prophesize(ServerRequestInterface::class);
68  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
69  $feUser = $this->prophesize(FrontendUserAuthentication::class);
70  $tsfe->fe_user = $feUser->reveal();
71  ‪$GLOBALS['TSFE'] = $tsfe->reveal();
72  $configurationService = $this->prophesize(ConfigurationService::class);
73  $configurationService->getMainConfiguration()->willReturn([]);
74  $configurationService->getConfigurationOption('preview', 'showHiddenPages')->willReturn('0');
75  $configurationService->getConfigurationOption('preview', 'simulateDate')->willReturn('0');
76  $configurationService->getConfigurationOption('preview', 'showHiddenRecords')->willReturn('0');
77  $configurationService->getConfigurationOption('preview', 'showFluidDebug')->willReturn('0');
78  $configurationService->getConfigurationOption('preview', 'simulateUserGroup')->willReturn('1');
79  $context = $this->prophesize(Context::class);
80  GeneralUtility::setSingletonInstance(Context::class, $context->reveal());
81 
82  GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
83 
84  $previewModule = new ‪PreviewModule();
85  $previewModule->initializeModule($request->reveal());
86 
87  $context->setAspect('frontend.user', Argument::any())->shouldHaveBeenCalled();
88  }
89 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\initializeFrontendPreviewSetsDateForSimulation
‪initializeFrontendPreviewSetsDateForSimulation(string $dateToSimulate, int $expectedExecTime, int $expectedAccessTime)
Definition: PreviewModuleTest.php:41
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules
Definition: PreviewModuleTest.php:4
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest
Definition: PreviewModuleTest.php:17
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:33
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\initializeFrontendPreviewSetsUsergroupForSimulation
‪initializeFrontendPreviewSetsUsergroupForSimulation()
Definition: PreviewModuleTest.php:64
‪TYPO3\CMS\Adminpanel\Tests\Unit\Modules\PreviewModuleTest\simulateDateDataProvider
‪simulateDateDataProvider()
Definition: PreviewModuleTest.php:18
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Modules\PreviewModule
Definition: PreviewModule.php:38
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45