‪TYPO3CMS  11.5
ShortcutRepositoryTest.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 
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 class ‪ShortcutRepositoryTest extends FunctionalTestCase
29 {
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35  $this->importCSVDataSet(__DIR__ . '/../Fixtures/ShortcutsBase.csv');
36 
37  $this->setUpBackendUserFromFixture(1);
39 
40  $this->subject = new ‪ShortcutRepository(
41  GeneralUtility::makeInstance(ConnectionPool::class),
42  GeneralUtility::makeInstance(IconFactory::class),
43  GeneralUtility::makeInstance(ModuleLoader::class)
44  );
45  }
46 
56  public function ‪shortcutExistsTest(string $routeIdentifier, array $arguments, int $userid, bool $exists): void
57  {
58  ‪$GLOBALS['BE_USER']->user['uid'] = $userid;
59  self::assertEquals($exists, $this->subject->shortcutExists($routeIdentifier, json_encode($arguments)));
60  }
61 
62  public function ‪shortcutExistsTestDataProvider(): \Generator
63  {
64  yield 'Shortcut exists' => [
65  'web_list',
66  ['id' => 123, 'GET' => ['clipBoard' => 1]],
67  1,
68  true,
69  ];
70  yield 'Not this user' => [
71  'web_list',
72  ['id' => 123, 'GET' => ['clipBoard' => 1]],
73  2,
74  false,
75  ];
76  yield 'Wrong route identifer' => [
77  'web_layout',
78  ['id' => 123, 'GET' => ['clipBoard' => 1]],
79  1,
80  false,
81  ];
82  yield 'Wrong arguments' => [
83  'web_list',
84  ['id' => 321, 'GET' => ['clipBoard' => 1]],
85  1,
86  false,
87  ];
88  }
89 
93  public function ‪addShortcutTest(): void
94  {
95  foreach ($this->‪getShortcutsToAdd() as $shortcut) {
96  $this->subject->addShortcut(
97  $shortcut['routeIdentifier'],
98  json_encode($shortcut['arguments']),
99  $shortcut['title']
100  );
101  }
102 
103  $this->assertCSVDataSet(__DIR__ . '/../Fixtures/ShortcutsAddedResult.csv');
104  }
105 
106  public function ‪getShortcutsToAdd(): array
107  {
108  return [
109  'Basic shortcut with all information' => [
110  'routeIdentifier' => 'web_list',
111  'arguments' => ['id' => 111, 'GET' => ['clipBoard' => 1]],
112  'title' => 'Recordlist of id 111',
113  ],
114  // @todo Below is deprecated functionality which only provides backwards compatibility for v11. Remove in v12!
115  'FormEngine without title' => [
116  'routeIdentifier' => 'record_edit',
117  'arguments' => ['edit' => ['pages' => [112 => 'edit']]],
118  'title' => '',
119  ],
120  // @todo Below is deprecated functionality which only provides backwards compatibility for v11. Remove in v12!
121  'Page Layout without title' => [
122  'routeIdentifier' => 'web_layout',
123  'arguments' => [],
124  'title' => '',
125  ],
126  ];
127  }
128 
134  public function ‪getShortcutsByGroupTest(): void
135  {
136  $expected = [
137  1 => [
138  'table' => null,
139  'recordid' => null,
140  'groupLabel' => 'Pages',
141  'type' => 'other',
142  'icon' => 'data-identifier="module-list"',
143  'label' => 'Recordlist',
144  'href' => '/typo3/module/web/list?token=%s&id=123&GET%5BclipBoard%5D=1',
145  ],
146  2 => [
147  'table' => 'tt_content',
148  'recordid' => 113,
149  'groupLabel' => null,
150  'type' => 'edit',
151  'label' => 'Edit Content',
152  'icon' => 'data-identifier="mimetypes-x-content-text"',
153  'href' => '/typo3/record/edit?token=%s&edit%5Btt_content%5D%5B113%5D=edit',
154  ],
155  3 => [
156  'table' => 'tt_content',
157  'recordid' => 117,
158  'groupLabel' => null,
159  'type' => 'new',
160  'label' => 'Create Content',
161  'icon' => 'data-identifier="mimetypes-x-content-text"',
162  'href' => '/typo3/record/edit?token=%s&edit%5Btt_content%5D%5B117%5D=new',
163  ],
164  7 => [
165  'table' => null,
166  'recordid' => null,
167  'groupLabel' => null,
168  'type' => 'other',
169  'label' => 'Page content',
170  'icon' => 'data-identifier="module-page"',
171  'href' => '/typo3/module/web/layout?token=%s&id=123',
172  ],
173  ];
174 
175  $shortcuts = $this->subject->getShortcutsByGroup(1);
176  self::assertCount(count($expected), $shortcuts);
177 
178  foreach ($shortcuts as $shortcut) {
179  $id = (int)$shortcut['raw']['uid'];
180  self::assertEquals(1, $shortcut['group']);
181  self::assertEquals($expected[$id]['table'], $shortcut['table'] ?? null);
182  self::assertEquals($expected[$id]['recordid'], $shortcut['recordid'] ?? null);
183  self::assertEquals($expected[$id]['groupLabel'], $shortcut['groupLabel'] ?? null);
184  self::assertEquals($expected[$id]['type'], $shortcut['type']);
185  self::assertEquals($expected[$id]['label'], $shortcut['label']);
186  self::assertStringContainsString($expected[$id]['icon'], $shortcut['icon']);
187  self::assertStringMatchesFormat($expected[$id]['href'], $shortcut['href']);
188  }
189  }
190 }
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\getShortcutsByGroupTest
‪getShortcutsByGroupTest()
Definition: ShortcutRepositoryTest.php:134
‪TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository
Definition: ShortcutRepository.php:45
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut
Definition: ShortcutRepositoryTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\getShortcutsToAdd
‪getShortcutsToAdd()
Definition: ShortcutRepositoryTest.php:106
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\addShortcutTest
‪addShortcutTest()
Definition: ShortcutRepositoryTest.php:93
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest
Definition: ShortcutRepositoryTest.php:29
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Backend\Module\ModuleLoader
Definition: ModuleLoader.php:34
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\shortcutExistsTestDataProvider
‪shortcutExistsTestDataProvider()
Definition: ShortcutRepositoryTest.php:62
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\setUp
‪setUp()
Definition: ShortcutRepositoryTest.php:32
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\$subject
‪ShortcutRepository $subject
Definition: ShortcutRepositoryTest.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Functional\Backend\Shortcut\ShortcutRepositoryTest\shortcutExistsTest
‪shortcutExistsTest(string $routeIdentifier, array $arguments, int $userid, bool $exists)
Definition: ShortcutRepositoryTest.php:56