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