‪TYPO3CMS  ‪main
ModifyNewContentElementWizardItemsEventTest.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;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪ModifyNewContentElementWizardItemsEventTest extends UnitTestCase
26 {
28 
29  protected function ‪setUp(): void
30  {
31  parent::setUp();
32 
33  $this->subject = new ‪ModifyNewContentElementWizardItemsEvent(
34  [
35  'aItem' => [
36  'aKey' => 'aValue',
37  ],
38  'bItem' => [],
39  'cItem' => [],
40  ],
41  [
42  '_thePath' => '/',
43  ],
44  1,
45  2,
46  3
47  );
48  }
49 
50  #[Test]
51  public function ‪wizardItemsModifyTest(): void
52  {
53  self::assertCount(3, $this->subject->getWizardItems());
54  self::assertTrue($this->subject->hasWizardItem('aItem'));
55  self::assertEquals(['aKey' => 'aValue'], $this->subject->getWizardItem('aItem'));
56 
57  self::assertFalse($this->subject->removeWizardItem('dItem'));
58  self::assertTrue($this->subject->removeWizardItem('aItem'));
59 
60  self::assertCount(2, $this->subject->getWizardItems());
61  self::assertFalse($this->subject->hasWizardItem('aItem'));
62  self::assertNull($this->subject->getWizardItem('aItem'));
63 
64  $items = $this->subject->getWizardItems();
65  $items['dItem'] = ['dKey' => 'dValue'];
66  $this->subject->setWizardItems($items);
67 
68  self::assertCount(3, $this->subject->getWizardItems());
69  self::assertTrue($this->subject->hasWizardItem('dItem'));
70  self::assertEquals(['dKey' => 'dValue'], $this->subject->getWizardItem('dItem'));
71 
72  self::assertEquals(['_thePath' => '/'], $this->subject->getPageInfo());
73  self::assertEquals(1, $this->subject->getColPos());
74  self::assertEquals(2, $this->subject->getSysLanguage());
75  self::assertEquals(3, $this->subject->getUidPid());
76  }
77 
78  public static function ‪addWizardItemTestDataProvider(): iterable
79  {
80  yield 'Change an existing item configuration' => [
81  'aItem',
82  [
83  'aKey' => 'anotherValue',
84  'aAKey' => 'aAnotherValue',
85  ],
86  [],
87  [
88  'aItem' => [
89  'aKey' => 'anotherValue',
90  'aAKey' => 'aAnotherValue',
91  ],
92  'bItem' => [],
93  'cItem' => [],
94  ],
95  ];
96  yield 'Relocate an existing item before' => [
97  'bItem',
98  [],
99  ['before' => 'aItem'],
100  [
101  'bItem' => [],
102  'aItem' => [
103  'aKey' => 'aValue',
104  ],
105  'cItem' => [],
106  ],
107  ];
108  yield 'Relocate an existing item after' => [
109  'aItem',
110  [],
111  ['after' => 'bItem'],
112  [
113  'bItem' => [],
114  'aItem' => [],
115  'cItem' => [],
116  ],
117  ];
118  yield 'Relocate while changing item configuration' => [
119  'aItem',
120  [
121  'aKey' => 'anotherValue',
122  'aAKey' => 'aAnotherValue',
123  ],
124  ['after' => 'cItem'],
125  [
126  'bItem' => [],
127  'cItem' => [],
128  'aItem' => [
129  'aKey' => 'anotherValue',
130  'aAKey' => 'aAnotherValue',
131  ],
132  ],
133  ];
134  yield 'Invalid position reference' => [
135  'aItem',
136  ['aKey' => 'aValue'],
137  ['after' => 'cItem'],
138  [
139  'aItem' => [
140  'aKey' => 'aValue',
141  ],
142  'bItem' => [],
143  'cItem' => [],
144  ],
145  ];
146  yield 'Add new item' => [
147  'dItem',
148  [],
149  [],
150  [
151  'aItem' => [
152  'aKey' => 'aValue',
153  ],
154  'bItem' => [],
155  'cItem' => [],
156  'dItem' => [],
157  ],
158  ];
159  yield 'Add new item before' => [
160  'dItem',
161  [],
162  ['before' => 'bItem'],
163  [
164  'aItem' => [
165  'aKey' => 'aValue',
166  ],
167  'dItem' => [],
168  'bItem' => [],
169  'cItem' => [],
170  ],
171  ];
172  yield 'Add new item after' => [
173  'dItem',
174  [],
175  ['after' => 'aItem'],
176  [
177  'aItem' => [
178  'aKey' => 'aValue',
179  ],
180  'dItem' => [],
181  'bItem' => [],
182  'cItem' => [],
183  ],
184  ];
185  yield 'Add new item before with configuration' => [
186  'dItem',
187  ['dKey' => 'dValue'],
188  ['before' => 'aItem'],
189  [
190  'dItem' => [
191  'dKey' => 'dValue',
192  ],
193  'aItem' => [
194  'aKey' => 'aValue',
195  ],
196  'bItem' => [],
197  'cItem' => [],
198  ],
199  ];
200  yield 'Add new item with configuration and invalid position' => [
201  'dItem',
202  ['dKey' => 'dValue'],
203  ['after' => 'eItem'],
204  [
205  'aItem' => [
206  'aKey' => 'aValue',
207  ],
208  'bItem' => [],
209  'cItem' => [],
210  'dItem' => [
211  'dKey' => 'dValue',
212  ],
213  ],
214  ];
215  }
216 
217  #[DataProvider('addWizardItemTestDataProvider')]
218  #[Test]
219  public function ‪addWizardItemTest(string ‪$identifier, array $configuration, array $position, array $expected): void
220  {
221  $this->subject->setWizardItem(‪$identifier, $configuration, $position);
222  self::assertEquals($expected, $this->subject->getWizardItems());
223  }
224 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event
Definition: AfterPageTreeItemsPreparedEventTest.php:18
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent
Definition: ModifyNewContentElementWizardItemsEvent.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event\ModifyNewContentElementWizardItemsEventTest\addWizardItemTestDataProvider
‪static addWizardItemTestDataProvider()
Definition: ModifyNewContentElementWizardItemsEventTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event\ModifyNewContentElementWizardItemsEventTest\wizardItemsModifyTest
‪wizardItemsModifyTest()
Definition: ModifyNewContentElementWizardItemsEventTest.php:51
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event\ModifyNewContentElementWizardItemsEventTest
Definition: ModifyNewContentElementWizardItemsEventTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event\ModifyNewContentElementWizardItemsEventTest\$subject
‪ModifyNewContentElementWizardItemsEvent $subject
Definition: ModifyNewContentElementWizardItemsEventTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event\ModifyNewContentElementWizardItemsEventTest\addWizardItemTest
‪addWizardItemTest(string $identifier, array $configuration, array $position, array $expected)
Definition: ModifyNewContentElementWizardItemsEventTest.php:219
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Event\ModifyNewContentElementWizardItemsEventTest\setUp
‪setUp()
Definition: ModifyNewContentElementWizardItemsEventTest.php:29
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37