‪TYPO3CMS  11.5
IfHasStateViewHelperTest.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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 class ‪IfHasStateViewHelperTest extends FunctionalTestCase
27 {
31  protected ‪$initializeDatabase = false;
32 
33  protected ‪StandaloneView ‪$view;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
39  $this->view->getRenderingContext()->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
40  $this->view->setTemplatePathAndFilename('EXT:backend/Tests/Functional/ViewHelpers/Fixtures/Mfa/IfHasStateViewHelper.html');
41  $this->view->assign('provider', $this->get(MfaProviderRegistry::class)->getProvider('totp'));
42  }
43 
47  public function ‪renderReturnsInactive(): void
48  {
49  ‪$GLOBALS['BE_USER'] = $this->‪getBackendUser();
50  $result = $this->view->render();
51 
52  self::assertStringNotContainsString('isActive', $result);
53  self::assertStringContainsString('isInactive', $result);
54  self::assertStringNotContainsString('isLocked', $result);
55  self::assertStringNotContainsString('isUnlocked', $result);
56  }
60  public function ‪renderReturnsActive(): void
61  {
62  ‪$GLOBALS['BE_USER'] = $this->‪getBackendUser(true);
63  $result = $this->view->render();
64 
65  self::assertStringContainsString('isActive', $result);
66  self::assertStringNotContainsString('isInactive', $result);
67  self::assertStringNotContainsString('isLocked', $result);
68  self::assertStringContainsString('isUnlocked', $result);
69  }
73  public function ‪renderReturnsLocked(): void
74  {
75  ‪$GLOBALS['BE_USER'] = $this->‪getBackendUser(true, true);
76  $result = $this->view->render();
77 
78  self::assertStringContainsString('isActive', $result);
79  self::assertStringNotContainsString('isInactive', $result);
80  self::assertStringContainsString('isLocked', $result);
81  self::assertStringNotContainsString('isUnlocked', $result);
82  }
83 
84  protected function ‪getBackendUser(bool $activeProvider = false, bool $lockedProvider = false): ‪BackendUserAuthentication
85  {
86  $backendUser = new ‪BackendUserAuthentication();
87  $mfa = [
88  'totp' => [
89  'secret' => 'KRMVATZTJFZUC53FONXW2ZJB',
90  ],
91  ];
92 
93  if ($activeProvider) {
94  $mfa['totp']['active'] = true;
95  }
96  if ($lockedProvider) {
97  $mfa['totp']['attempts'] = 3;
98  }
99 
100  $backendUser->user['mfa'] = json_encode($mfa);
101  return $backendUser;
102  }
103 }
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\setUp
‪setUp()
Definition: IfHasStateViewHelperTest.php:34
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: IfHasStateViewHelperTest.php:30
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\getBackendUser
‪getBackendUser(bool $activeProvider=false, bool $lockedProvider=false)
Definition: IfHasStateViewHelperTest.php:83
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\renderReturnsInactive
‪renderReturnsInactive()
Definition: IfHasStateViewHelperTest.php:46
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa
Definition: IfHasStateViewHelperTest.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\renderReturnsActive
‪renderReturnsActive()
Definition: IfHasStateViewHelperTest.php:59
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\$view
‪StandaloneView $view
Definition: IfHasStateViewHelperTest.php:32
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest\renderReturnsLocked
‪renderReturnsLocked()
Definition: IfHasStateViewHelperTest.php:72
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Mfa\IfHasStateViewHelperTest
Definition: IfHasStateViewHelperTest.php:27
‪TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry
Definition: MfaProviderRegistry.php:28