‪TYPO3CMS  10.4
DashboardPresetRegistryTest.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 ‪DashboardPresetRegistryTest extends UnitTestCase
26 {
30  protected ‪$resetSingletonInstances = true;
31 
33  protected ‪$subject;
34 
35  public function ‪setUp(): void
36  {
37  $this->subject = GeneralUtility::makeInstance(
38  DashboardPresetRegistry::class
39  );
40  }
41 
46  {
47  $presets = $this->subject->getDashboardPresets();
48  self::assertCount(1, $presets);
49 
50  self::assertSame('dashboardPreset-fallback', key($presets));
51  self::assertInstanceOf(DashboardPreset::class, reset($presets));
52  }
53 
58  {
59  $dashboardPreset1 = new ‪DashboardPreset('identifier1', 'title1', 'description1');
60  $dashboardPreset2 = new ‪DashboardPreset('identifier2', 'title2', 'description2');
61 
62  $this->subject->registerDashboardPreset($dashboardPreset1);
63  $this->subject->registerDashboardPreset($dashboardPreset2);
64 
65  foreach ($this->subject->getDashboardPresets() as $identifier => $dashboardPresetObject) {
66  self::assertInstanceOf(DashboardPreset::class, $dashboardPresetObject);
67  }
68  }
69 
73  public function ‪dashboardPresetsGetRegistered(): void
74  {
75  // If no dashboard preset is registered, it will return a fallback preset
76  self::assertCount(1, $this->subject->getDashboardPresets());
77 
78  // Register a first dashboard template. No fallback will be added anymore
79  $dashboardPreset = new DashboardPreset('identifier1', 'title1', 'description1');
80  $this->subject->registerDashboardPreset($dashboardPreset);
81 
82  // Check if 1 dashboard template is found
83  self::assertCount(1, $this->subject->getDashboardPresets());
84 
85  // Register same dashboard template again
86  $this->subject->registerDashboardPreset($dashboardPreset);
87  self::assertCount(1, $this->subject->getDashboardPresets());
88 
89  // Register new dashboard template and check if it is registered successfully
90  $dashboardPreset2 = new DashboardPreset('identifier2', 'title2', 'description2');
91  $this->subject->registerDashboardPreset($dashboardPreset2);
92 
93  $dashboardPresets = $this->subject->getDashboardPresets();
94  self::assertCount(2, $dashboardPresets);
95 
96  // Check if the identifiers are correctly registered
97  self::assertEquals(['identifier1', 'identifier2'], array_keys($dashboardPresets));
98  }
99 }
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest\$subject
‪DashboardPresetRegistry $subject
Definition: DashboardPresetRegistryTest.php:31
‪TYPO3\CMS\Dashboard\DashboardPreset
Definition: DashboardPreset.php:26
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: DashboardPresetRegistryTest.php:29
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest\dashboardPresetsGetRegistered
‪dashboardPresetsGetRegistered()
Definition: DashboardPresetRegistryTest.php:71
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest\setUp
‪setUp()
Definition: DashboardPresetRegistryTest.php:33
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest\withoutRegisteredPresetsOnlyFallbackPresetsIsReturned
‪withoutRegisteredPresetsOnlyFallbackPresetsIsReturned()
Definition: DashboardPresetRegistryTest.php:43
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest
Definition: DashboardPresetRegistryTest.php:26
‪TYPO3\CMS\Dashboard\Tests\Unit
Definition: DashboardPresetRegistryTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Dashboard\Tests\Unit\DashboardPresetRegistryTest\getWidgetsMethodReturnsDashboardPresetsObjects
‪getWidgetsMethodReturnsDashboardPresetsObjects()
Definition: DashboardPresetRegistryTest.php:55
‪TYPO3\CMS\Dashboard\DashboardPresetRegistry
Definition: DashboardPresetRegistry.php:26