‪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 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪ShortcutButtonTest extends FunctionalTestCase
28 {
29  private const ‪FIXTURES_PATH_PATTERN = __DIR__ . '/../../../Fixtures/%s.html';
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34 
35  $this->setUpBackendUserFromFixture(1);
37  $serverParams = array_replace($_SERVER, ['HTTP_HOST' => 'example.com', 'SCRIPT_NAME' => '/typo3/index.php']);
38  $request = new ‪ServerRequest('http://example.com/typo3/index.php', 'GET', null, $serverParams);
39  ‪$GLOBALS['TYPO3_REQUEST'] = $request
40  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
41  ->withAttribute('normalizedParams', ‪NormalizedParams::createFromServerParams($serverParams));
42  }
43 
47  public function ‪isButtonValid(): void
48  {
49  self::assertFalse((new ‪ShortcutButton())->isValid());
50  self::assertTrue((new ‪ShortcutButton())->setRouteIdentifier('web_list')->isValid());
51  }
52 
57  public function ‪rendersCorrectMarkup(‪ShortcutButton $button, string $expectedMarkupFile): void
58  {
59  self::assertEquals(
60  $this->‪normalizeSpaces(file_get_contents(sprintf(self::FIXTURES_PATH_PATTERN, $expectedMarkupFile))),
61  $this->‪normalizeSpaces($button->‪render())
62  );
63  }
64 
65  public function ‪rendersCorrectMarkupDataProvider(): \Generator
66  {
67  yield 'Recordlist' => [
68  (new ‪ShortcutButton())
69  ->setRouteIdentifier('web_list')
70  ->setDisplayName('Recordlist')
71  ->setCopyUrlToClipboard(false),
72  'RecordList',
73  ];
74  yield 'Recordlist with copyToClipboard action' => [
75  (new ‪ShortcutButton())
76  ->setRouteIdentifier('web_list')
77  ->setDisplayName('Recordlist'),
78  'RecordListCopyToClipboard',
79  ];
80  yield 'Recordlist - single table view' => [
81  (new ‪ShortcutButton())
82  ->setRouteIdentifier('web_list')
83  ->setDisplayName('Recordlist - single table view')
84  ->setCopyUrlToClipboard(false)
85  ->setArguments([
86  'id' => 123,
87  'table' => 'some_table',
88  'GET' => [
89  'clipBoard' => 1,
90  ],
91  ]),
92  'RecordListSingleTable',
93  ];
94  yield 'Recordlist - single table view with copyToClipboard action' => [
95  (new ‪ShortcutButton())
96  ->setRouteIdentifier('web_list')
97  ->setDisplayName('Recordlist - single table view')
98  ->setArguments([
99  'id' => 123,
100  'table' => 'some_table',
101  'GET' => [
102  'clipBoard' => 1,
103  ],
104  ]),
105  'RecordListSingleTableCopyToClipboard',
106  ];
107  yield 'With special route identifier' => [
108  (new ‪ShortcutButton())
109  ->setRouteIdentifier('record_edit')
110  ->setDisplayName('Edit record')
111  ->setCopyUrlToClipboard(false),
112  'SpecialRouteIdentifier',
113  ];
114  yield 'With special route identifier and arguments' => [
115  (new ‪ShortcutButton())
116  ->setRouteIdentifier('record_edit')
117  ->setDisplayName('Edit record')
118  ->setCopyUrlToClipboard(false)
119  ->setArguments([
120  'id' => 123,
121  'edit' => [
122  'pages' => [
123  123 => 'edit',
124  ],
125  'overrideVals' => [
126  'pages' => [
127  'sys_language_uid' => 1,
128  ],
129  ],
130  ],
131  'returnUrl' => 'some/url',
132  ]),
133  'SpecialRouteIdentifierWithArguments',
134  ];
135  yield 'With special route identifier and arguments - copyToClipboard' => [
136  (new ‪ShortcutButton())
137  ->setRouteIdentifier('record_edit')
138  ->setDisplayName('Edit record')
139  ->setArguments([
140  'id' => 123,
141  'edit' => [
142  'pages' => [
143  123 => 'edit',
144  ],
145  'overrideVals' => [
146  'pages' => [
147  'sys_language_uid' => 1,
148  ],
149  ],
150  ],
151  'returnUrl' => 'some/url',
152  ]),
153  'SpecialRouteIdentifierWithArgumentsCopyToClipboard',
154  ];
155  }
156 
166  private function ‪normalizeSpaces(string $html): string
167  {
168  return preg_replace(
169  ['/^\s+(?=<)/m', '/^\s+(?!<)/m', '/\v+/'],
170  ['', ' ', ''],
171  $html
172  );
173  }
174 }
‪TYPO3\CMS\Backend\Tests\Functional\Template\Components\Buttons\Action\ShortcutButtonTest\rendersCorrectMarkupDataProvider
‪rendersCorrectMarkupDataProvider()
Definition: ShortcutButtonTest.php:65
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Backend\Tests\Functional\Template\Components\Buttons\Action\ShortcutButtonTest
Definition: ShortcutButtonTest.php:28
‪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\Functional\Template\Components\Buttons\Action\ShortcutButtonTest\FIXTURES_PATH_PATTERN
‪const FIXTURES_PATH_PATTERN
Definition: ShortcutButtonTest.php:29
‪TYPO3\CMS\Backend\Tests\Functional\Template\Components\Buttons\Action\ShortcutButtonTest\rendersCorrectMarkup
‪rendersCorrectMarkup(ShortcutButton $button, string $expectedMarkupFile)
Definition: ShortcutButtonTest.php:57
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromServerParams
‪static static createFromServerParams(array $serverParams, array $systemConfiguration=null)
Definition: NormalizedParams.php:826
‪TYPO3\CMS\Backend\Tests\Functional\Template\Components\Buttons\Action\ShortcutButtonTest\isButtonValid
‪isButtonValid()
Definition: ShortcutButtonTest.php:47
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Template\Components\Buttons\Action
Definition: ShortcutButtonTest.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.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\Functional\Template\Components\Buttons\Action\ShortcutButtonTest\normalizeSpaces
‪string normalizeSpaces(string $html)
Definition: ShortcutButtonTest.php:166
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35
‪TYPO3\CMS\Backend\Tests\Functional\Template\Components\Buttons\Action\ShortcutButtonTest\setUp
‪setUp()
Definition: ShortcutButtonTest.php:31