‪TYPO3CMS  ‪main
ShortcutControllerTest.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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
29 use TYPO3\CMS\Core\Package\PackageManager;
31 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
32 
33 final class ‪ShortcutControllerTest extends FunctionalTestCase
34 {
37 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41 
42  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_be_shortcuts.csv');
43  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
44  $backendUser = $this->setUpBackendUser(1);
45  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
46 
47  $this->subject = new ‪ShortcutController(
48  $this->get(ShortcutToolbarItem::class),
49  $this->get(ShortcutRepository::class),
50  new ‪BackendViewFactory($this->get(RenderingContextFactory::class), $this->get(PackageManager::class))
51  );
52  $this->request = (new ‪ServerRequest('https://example.com/typo3/'))->withAttribute('normalizedParams', new ‪NormalizedParams([], [], '', ''));
53  ‪$GLOBALS['TYPO3_REQUEST'] = ‪$this->request;
54  }
55 
56  #[DataProvider('addShortcutTestDataProvide')]
57  #[Test]
58  public function ‪addShortcutTest(array $parsedBody, string $expectedResponseBody, int $expectedResponseStatus): void
59  {
60  ‪$request = $this->request->‪withParsedBody($parsedBody);
61  $response = $this->subject->addAction(‪$request);
62  self::assertEquals($expectedResponseBody, $response->getBody());
63  self::assertEquals($expectedResponseStatus, $response->getStatusCode());
64  }
65 
66  public static function ‪addShortcutTestDataProvide(): \Generator
67  {
68  yield 'No route defined' => [
69  [],
70  json_encode(['result' => 'missingRoute'], JSON_THROW_ON_ERROR),
71  400,
72  ];
73  yield 'Existing data as parsed body' => [
74  [
75  'routeIdentifier' => 'web_layout',
76  'arguments' => '{"id":"123"}',
77  ],
78  json_encode(['result' => 'alreadyExists'], JSON_THROW_ON_ERROR),
79  200,
80  ];
81  yield 'Invalid route identifier' => [
82  [
83  'routeIdentifier' => 'invalid_route_identifier',
84  ],
85  json_encode(['result' => 'failed'], JSON_THROW_ON_ERROR),
86  500,
87  ];
88  yield 'New data as parsed body' => [
89  [
90  'routeIdentifier' => 'web_list',
91  'arguments' => '{"id":"123","GET":{"clipBoard":"1"}}',
92  ],
93  json_encode(['result' => 'success'], JSON_THROW_ON_ERROR),
94  201,
95  ];
96  }
97 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository
Definition: ShortcutRepository.php:44
‪TYPO3\CMS\Backend\Controller\ShortcutController
Definition: ShortcutController.php:36
‪TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest\$subject
‪ShortcutController $subject
Definition: ShortcutControllerTest.php:35
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest\addShortcutTestDataProvide
‪static addShortcutTestDataProvide()
Definition: ShortcutControllerTest.php:66
‪TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest\addShortcutTest
‪addShortcutTest(array $parsedBody, string $expectedResponseBody, int $expectedResponseStatus)
Definition: ShortcutControllerTest.php:58
‪TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem
Definition: ShortcutToolbarItem.php:35
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest
Definition: ShortcutControllerTest.php:34
‪TYPO3\CMS\Core\Http\ServerRequest\withParsedBody
‪static withParsedBody($data)
Definition: ServerRequest.php:250
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest\setUp
‪setUp()
Definition: ShortcutControllerTest.php:38
‪TYPO3\CMS\Backend\Tests\Functional\Controller
Definition: BackendControllerTest.php:18
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38
‪TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest\$request
‪ServerRequest $request
Definition: ShortcutControllerTest.php:36