‪TYPO3CMS  11.5
DashboardWidgetPassTest.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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Prophecy\Prophecy\ObjectProphecy;
23 use Symfony\Component\DependencyInjection\ContainerBuilder;
24 use Symfony\Component\DependencyInjection\Definition;
25 use Symfony\Component\DependencyInjection\Reference;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 class ‪DashboardWidgetPassTest extends UnitTestCase
32 {
33  use ProphecyTrait;
34 
36 
38  protected ObjectProphecy ‪$container;
39 
41  protected ObjectProphecy ‪$widgetRegistryDefinition;
42 
43  public function ‪setUp(): void
44  {
45  parent::setUp();
46 
47  $this->subject = new ‪DashboardWidgetPass('dashboard.widget');
48  $this->container = $this->prophesize(ContainerBuilder::class);
49  $this->widgetRegistryDefinition = $this->prophesize(Definition::class);
50  }
51 
55  public function ‪doesNothingIfWidgetRegistryIsUnknown(): void
56  {
57  $this->container->hasDefinition(WidgetRegistry::class)->willReturn(false);
58  $this->container->findTaggedServiceIds('dashboard.widget')->shouldNotBeCalled();
59 
60  $this->subject->process($this->container->reveal());
61  }
62 
66  public function ‪doesNothingIfNoWidgetsAreTagged(): void
67  {
68  $this->container->hasDefinition(WidgetRegistry::class)->willReturn(true);
69  $this->container->findDefinition(WidgetRegistry::class)->willReturn($this->widgetRegistryDefinition->reveal());
70  $this->container->findTaggedServiceIds('dashboard.widget')->willReturn([])->shouldBeCalled();
71  $this->widgetRegistryDefinition->addMethodCall()->shouldNotBeCalled();
72 
73  $this->subject->process($this->container->reveal());
74  }
75 
79  public function ‪makesWidgetPublic(): void
80  {
81  $this->container->hasDefinition(WidgetRegistry::class)->willReturn(true);
82  $this->container->findDefinition(WidgetRegistry::class)->willReturn($this->widgetRegistryDefinition->reveal());
83  $this->container->findTaggedServiceIds('dashboard.widget')->willReturn(['NewsWidget' => []]);
84  $definition = $this->prophesize(Definition::class);
85  $this->container->findDefinition('NewsWidget')->willReturn($definition->reveal());
86  $definition->setPublic(true)->shouldBeCalled();
87 
88  $this->subject->process($this->container->reveal());
89  }
90 
95  {
96  $this->container->hasDefinition(WidgetRegistry::class)->willReturn(true);
97  $this->container->findDefinition(WidgetRegistry::class)->willReturn($this->widgetRegistryDefinition->reveal());
98  $definition = $this->prophesize(Definition::class);
99  $this->container->findDefinition('dashboard.widget.t3news')->willReturn($definition->reveal());
100  $definition->setPublic(true);
101  $definition->setArgument('$configuration', Argument::that(static function ($argument) {
102  return $argument instanceof Reference && (string)$argument === 't3newsWidgetConfiguration';
103  }));
104 
105  $this->container->findTaggedServiceIds('dashboard.widget')->willReturn([
106  'dashboard.widget.t3news' => [
107  [
108  'identifier' => 't3news',
109  'groupNames' => 'typo3',
110  'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.title',
111  'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.description',
112  ],
113  ],
114  ]);
115  $this->container->addDefinitions(Argument::that(static function (array $widgetConfigurationDefinitions) {
116  $definition = $widgetConfigurationDefinitions['t3newsWidgetConfiguration'];
117  /* @var Definition $definition */
118  return $definition instanceof Definition
119  && $definition->getClass() === WidgetConfiguration::class
120  && $definition->getArgument('$identifier') === 't3news'
121  && $definition->getArgument('$groupNames') === ['typo3']
122  && $definition->getArgument('$title') === 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.title'
123  && $definition->getArgument('$description') === 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.description'
124  && $definition->getArgument('$iconIdentifier') === 'content-dashboard'
125  && $definition->getArgument('$height') === 'small'
126  && $definition->getArgument('$width') === 'small'
127  ;
128  }))->shouldBeCalled();
129  $this->widgetRegistryDefinition->addMethodCall(
130  'registerWidget',
131  [
132  't3newsWidgetConfiguration',
133  ]
134  )->shouldBeCalled();
135 
136  $this->subject->process($this->container->reveal());
137  }
138 
142  public function ‪registersWidgetToMultipleGroupsByComma(): void
143  {
144  $this->container->hasDefinition(WidgetRegistry::class)->willReturn(true);
145  $this->container->findDefinition(WidgetRegistry::class)->willReturn($this->widgetRegistryDefinition->reveal());
146  $definition = $this->prophesize(Definition::class);
147  $this->container->findDefinition('dashboard.widget.t3news')->willReturn($definition->reveal());
148  $definition->setPublic(true);
149  $definition->setArgument('$configuration', Argument::that(static function ($argument) {
150  return $argument instanceof Reference && (string)$argument === 't3newsWidgetConfiguration';
151  }));
152 
153  $this->container->findTaggedServiceIds('dashboard.widget')->willReturn([
154  'dashboard.widget.t3news' => [
155  [
156  'identifier' => 't3news',
157  'groupNames' => 'typo3, general',
158  'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.title',
159  'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.description',
160  ],
161  ],
162  ]);
163  $this->container->addDefinitions(Argument::that(static function (array $widgetConfigurationDefinitions) {
164  $definition = $widgetConfigurationDefinitions['t3newsWidgetConfiguration'];
165  /* @var Definition $definition */
166  return $definition instanceof Definition
167  && $definition->getClass() === WidgetConfiguration::class
168  && $definition->getArgument('$groupNames') === ['typo3', 'general']
169  ;
170  }))->shouldBeCalled();
171  $this->widgetRegistryDefinition->addMethodCall(
172  'registerWidget',
173  [
174  't3newsWidgetConfiguration',
175  ]
176  )->shouldBeCalled();
177 
178  $this->subject->process($this->container->reveal());
179  }
180 
185  {
186  $this->container->hasDefinition(WidgetRegistry::class)->willReturn(true);
187  $this->container->findDefinition(WidgetRegistry::class)->willReturn($this->widgetRegistryDefinition->reveal());
188  $definition = $this->prophesize(Definition::class);
189  $this->container->findDefinition('dashboard.widget.t3news')->willReturn($definition->reveal());
190  $definition->setPublic(true);
191  $definition->setArgument('$configuration', Argument::that(static function ($argument) {
192  return $argument instanceof Reference && (string)$argument === 't3newsWidgetConfiguration';
193  }));
194 
195  $this->container->findTaggedServiceIds('dashboard.widget')->willReturn([
196  'dashboard.widget.t3news' => [
197  [
198  'identifier' => 't3news',
199  'groupNames' => 'typo3',
200  'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.title',
201  'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.description',
202  'iconIdentifier' => 'some-icon',
203  'height' => 'large',
204  'width' => 'medium',
205  ],
206  ],
207  ]);
208  $this->container->addDefinitions(Argument::that(static function (array $widgetConfigurationDefinitions) {
209  $definition = $widgetConfigurationDefinitions['t3newsWidgetConfiguration'];
210  /* @var Definition $definition */
211  return $definition instanceof Definition
212  && $definition->getClass() === WidgetConfiguration::class
213  && $definition->getArgument('$identifier') === 't3news'
214  && $definition->getArgument('$groupNames') === ['typo3']
215  && $definition->getArgument('$title') === 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.title'
216  && $definition->getArgument('$description') === 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.t3news.description'
217  && $definition->getArgument('$iconIdentifier') === 'some-icon'
218  && $definition->getArgument('$height') === 'large'
219  && $definition->getArgument('$width') === 'medium'
220  ;
221  }))->shouldBeCalled();
222  $this->widgetRegistryDefinition->addMethodCall(
223  'registerWidget',
224  [
225  't3newsWidgetConfiguration',
226  ]
227  )->shouldBeCalled();
228 
229  $this->subject->process($this->container->reveal());
230  }
231 }
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\makesWidgetPublic
‪makesWidgetPublic()
Definition: DashboardWidgetPassTest.php:78
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection
Definition: DashboardWidgetPassTest.php:18
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\$widgetRegistryDefinition
‪ObjectProphecy $widgetRegistryDefinition
Definition: DashboardWidgetPassTest.php:40
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\registersWidgetToMultipleGroupsByComma
‪registersWidgetToMultipleGroupsByComma()
Definition: DashboardWidgetPassTest.php:141
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\$subject
‪DashboardWidgetPass $subject
Definition: DashboardWidgetPassTest.php:34
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\$container
‪ObjectProphecy $container
Definition: DashboardWidgetPassTest.php:37
‪TYPO3\CMS\Dashboard\Widgets\WidgetConfiguration
Definition: WidgetConfiguration.php:21
‪TYPO3\CMS\Dashboard\WidgetRegistry
Definition: WidgetRegistry.php:31
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\registersTaggedWidgetWithMaximumConfigurationInRegistry
‪registersTaggedWidgetWithMaximumConfigurationInRegistry()
Definition: DashboardWidgetPassTest.php:183
‪TYPO3\CMS\Dashboard\DependencyInjection\DashboardWidgetPass
Definition: DashboardWidgetPass.php:32
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest
Definition: DashboardWidgetPassTest.php:32
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\doesNothingIfNoWidgetsAreTagged
‪doesNothingIfNoWidgetsAreTagged()
Definition: DashboardWidgetPassTest.php:65
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\registersTaggedWidgetWithMinimumConfigurationInRegistry
‪registersTaggedWidgetWithMinimumConfigurationInRegistry()
Definition: DashboardWidgetPassTest.php:93
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\doesNothingIfWidgetRegistryIsUnknown
‪doesNothingIfWidgetRegistryIsUnknown()
Definition: DashboardWidgetPassTest.php:54
‪TYPO3\CMS\Dashboard\Tests\Unit\DependencyInjection\DashboardWidgetPassTest\setUp
‪setUp()
Definition: DashboardWidgetPassTest.php:42