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