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