‪TYPO3CMS  11.5
ShortcutButtonTest.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 
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 class ‪ShortcutButtonTest extends FunctionalTestCase
25 {
26  private const ‪FIXTURES_PATH_PATTERN = __DIR__ . '/../../../Fixtures/%s.html';
27 
28  protected function ‪setUp(): void
29  {
30  parent::setUp();
31 
32  $this->setUpBackendUserFromFixture(1);
34  }
35 
39  public function ‪isButtonValid(): void
40  {
41  self::assertTrue((new ‪ShortcutButton())->setArguments(['route' => 'web_list'])->isValid());
42  self::assertTrue((new ‪ShortcutButton())->setModuleName('web_list')->isValid());
43  }
44 
49  public function ‪rendersCorrectMarkup(‪ShortcutButton $button, string $expectedMarkupFile): void
50  {
51  self::assertEquals(
52  $this->‪normalizeSpaces(file_get_contents(sprintf(self::FIXTURES_PATH_PATTERN, $expectedMarkupFile))),
53  $this->‪normalizeSpaces($button->‪render())
54  );
55  }
56 
57  public function ‪rendersCorrectMarkupDataProvider(): \Generator
58  {
59  yield 'Recordlist as route path' => [
60  (new ‪ShortcutButton())
61  ->setRouteIdentifier('/module/web/list')
62  ->setDisplayName('Recordlist')
63  ->setCopyUrlToClipboard(false),
64  'RecordList',
65  ];
66  yield 'With special route path' => [
67  (new ‪ShortcutButton())
68  ->setRouteIdentifier('/record/edit')
69  ->setDisplayName('Edit record')
70  ->setCopyUrlToClipboard(false),
71  'SpecialRouteIdentifier',
72  ];
73  yield 'With special route path as Argument' => [
74  (new ‪ShortcutButton())
75  ->setArguments(['route' => '/record/edit'])
76  ->setDisplayName('Edit record')
77  ->setCopyUrlToClipboard(false),
78  'SpecialRouteIdentifier',
79  ];
80  }
81 
91  private function ‪normalizeSpaces(string $html): string
92  {
93  return preg_replace(
94  ['/^\s+(?=<)/m', '/^\s+(?!<)/m', '/\v+/'],
95  ['', ' ', ''],
96  $html
97  );
98  }
99 }
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest\normalizeSpaces
‪string normalizeSpaces(string $html)
Definition: ShortcutButtonTest.php:91
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest\rendersCorrectMarkup
‪rendersCorrectMarkup(ShortcutButton $button, string $expectedMarkupFile)
Definition: ShortcutButtonTest.php:49
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action
Definition: ShortcutButtonTest.php:18
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton
Definition: ShortcutButton.php:51
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest\rendersCorrectMarkupDataProvider
‪rendersCorrectMarkupDataProvider()
Definition: ShortcutButtonTest.php:57
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest\isButtonValid
‪isButtonValid()
Definition: ShortcutButtonTest.php:39
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest
Definition: ShortcutButtonTest.php:25
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\render
‪string render()
Definition: ShortcutButton.php:284
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest\setUp
‪setUp()
Definition: ShortcutButtonTest.php:28
‪TYPO3\CMS\Backend\Tests\FunctionalDeprecated\Template\Components\Buttons\Action\ShortcutButtonTest\FIXTURES_PATH_PATTERN
‪const FIXTURES_PATH_PATTERN
Definition: ShortcutButtonTest.php:26