‪TYPO3CMS  10.4
WidgetGroupRegistryTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪WidgetGroupRegistryTest extends UnitTestCase
26 {
30  protected ‪$resetSingletonInstances = true;
31 
33  protected ‪$subject;
34 
35  public function ‪setUp(): void
36  {
37  $this->subject = GeneralUtility::makeInstance(
38  WidgetGroupRegistry::class
39  );
40  }
41 
45  public function ‪initiallyZeroWidgetGroupsAreRegistered(): void
46  {
47  self::assertCount(0, $this->subject->getWidgetGroups());
48  }
49 
53  public function ‪getWidgetsMethodReturnsWidgetGroupObjects(): void
54  {
55  $widgetGroup1 = new ‪WidgetGroup('identifier1', 'title1');
56  $widgetGroup2 = new ‪WidgetGroup('identifier2', 'title2');
57 
58  $this->subject->registerWidgetGroup($widgetGroup1);
59  $this->subject->registerWidgetGroup($widgetGroup2);
60 
61  // Check if all registered widget groups contains an instance of WidgetGroup
62  foreach ($this->subject->getWidgetGroups() as $identifier => $widgetGroupObject) {
63  self::assertInstanceOf(WidgetGroup::class, $widgetGroupObject);
64  }
65  }
66 
70  public function ‪widgetGroupsGetRegistered(): void
71  {
72  self::assertCount(0, $this->subject->getWidgetGroups());
73 
74  // Register a first widget group
75  $widgetGroup = new WidgetGroup('identifier', 'title');
76  $this->subject->registerWidgetGroup($widgetGroup);
77 
78  // Check if 1 widget group is found
79  self::assertCount(1, $this->subject->getWidgetGroups());
80 
81  // Register same widget group again
82  $this->subject->registerWidgetGroup($widgetGroup);
83  self::assertCount(1, $this->subject->getWidgetGroups());
84 
85  // Register new widget group and check if it is registered successfully
86  $widgetGroup2 = new WidgetGroup('identifier2', 'title2');
87  $this->subject->registerWidgetGroup($widgetGroup2);
88 
89  $widgetGroups = $this->subject->getWidgetGroups();
90  self::assertCount(2, $widgetGroups);
91 
92  // Check if the identifiers are correctly registered
93  self::assertEquals(['identifier', 'identifier2'], array_keys($widgetGroups));
94  }
95 
100  {
101  $widgetGroup1 = new WidgetGroup('identifier1', 'title1');
102  $widgetGroup2 = new WidgetGroup('identifier2', 'title2');
103 
104  $this->subject->registerWidgetGroup($widgetGroup1);
105  $this->subject->registerWidgetGroup($widgetGroup2);
106 
107  $alternativeWidgetGroupRepository = GeneralUtility::makeInstance(
108  WidgetGroupRegistry::class
109  );
110 
111  self::assertEquals(
112  $this->subject->getWidgetGroups(),
113  $alternativeWidgetGroupRepository->getWidgetGroups()
114  );
115  }
116 }
‪TYPO3\CMS\Dashboard\WidgetGroupRegistry
Definition: WidgetGroupRegistry.php:26
‪TYPO3\CMS\Dashboard\WidgetGroup
Definition: WidgetGroup.php:26
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\initiallyZeroWidgetGroupsAreRegistered
‪initiallyZeroWidgetGroupsAreRegistered()
Definition: WidgetGroupRegistryTest.php:43
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\alternativeRepositoryObjectReturnsSameResults
‪alternativeRepositoryObjectReturnsSameResults()
Definition: WidgetGroupRegistryTest.php:97
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\$subject
‪WidgetGroupRegistry $subject
Definition: WidgetGroupRegistryTest.php:31
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: WidgetGroupRegistryTest.php:29
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest
Definition: WidgetGroupRegistryTest.php:26
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\widgetGroupsGetRegistered
‪widgetGroupsGetRegistered()
Definition: WidgetGroupRegistryTest.php:68
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\getWidgetsMethodReturnsWidgetGroupObjects
‪getWidgetsMethodReturnsWidgetGroupObjects()
Definition: WidgetGroupRegistryTest.php:51
‪TYPO3\CMS\Dashboard\Tests\Unit\WidgetGroupRegistryTest\setUp
‪setUp()
Definition: WidgetGroupRegistryTest.php:33
‪TYPO3\CMS\Dashboard\Tests\Unit
Definition: DashboardPresetRegistryTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46