‪TYPO3CMS  9.5
AspectFactoryTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use PHPUnit\Framework\MockObject\MockObject;
20 use Prophecy\Prophecy\ObjectProphecy;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 class ‪AspectFactoryTest extends UnitTestCase
30 {
34  protected ‪$subject;
35 
39  protected ‪$languageProphecy;
40 
44  protected ‪$siteProphecy;
45 
50 
54  protected ‪$aspectMockClass;
55 
56  protected function ‪setUp()
57  {
58  parent::setUp();
59  $this->languageProphecy = $this->prophesize(
60  SiteLanguage::class
61  );
62  $this->siteProphecy = $this->prophesize(
63  Site::class
64  );
65  $this->persistedMockClass = $this->getMockClass(
66  PersistedMappableAspectInterface::class
67  );
68  $this->aspectMockClass = $this->getMockClass(
69  AspectInterface::class
70  );
71  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects'] = [
72  'Persisted' => ‪$this->persistedMockClass,
73  'Aspect' => ‪$this->aspectMockClass,
74  ];
76  $contextMock = $this->getMockBuilder(Context::class)
77  ->disableOriginalConstructor()
78  ->getMock();
79  $this->subject = new ‪AspectFactory($contextMock);
80  }
81 
82  protected function ‪tearDown()
83  {
84  unset($this->subject, $this->languageProphecy, $this->persistedMockClass, $this->aspectMockClass);
85  parent::tearDown();
86  }
87 
92  {
93  $this->expectException(\InvalidArgumentException::class);
94  $this->expectExceptionCode(1538079481);
95  $this->subject->createAspects(
96  ['a' => []],
97  $this->languageProphecy->reveal(),
98  $this->siteProphecy->reveal()
99  );
100  }
101 
106  {
107  $this->expectException(\OutOfRangeException::class);
108  $this->expectExceptionCode(1538079482);
109  $this->subject->createAspects(
110  ['a' => ['type' => 'Undefined']],
111  $this->languageProphecy->reveal(),
112  $this->siteProphecy->reveal()
113  );
114  }
115 
119  public function ‪aspectsDataProvider(): array
120  {
121  return [
122  'single aspect' => [
123  [
124  'a' => ['type' => 'Aspect'],
125  ],
126  [
127  'a' => AspectInterface::class,
128  ],
129  ],
130  'both non-persisted' => [
131  [
132  'a' => ['type' => 'Aspect'],
133  'b' => ['type' => 'Aspect'],
134  ],
135  [
136  'a' => AspectInterface::class,
137  'b' => AspectInterface::class,
138  ],
139  ],
140  'both persisted' => [
141  [
142  'a' => ['type' => 'Persisted'],
143  'b' => ['type' => 'Persisted'],
144  ],
145  [
146  'a' => PersistedMappableAspectInterface::class,
147  'b' => PersistedMappableAspectInterface::class,
148  ],
149  ],
150  // persisted shall be sorted to the end
151  'first persisted, second non-persisted' => [
152  [
153  'a' => ['type' => 'Persisted'],
154  'b' => ['type' => 'Aspect'],
155  ],
156  [
157  'b' => AspectInterface::class,
158  'a' => PersistedMappableAspectInterface::class,
159  ],
160  ],
161  // persisted shall be sorted to the end
162  'many persisted, many non-persisted' => [
163  [
164  'a' => ['type' => 'Persisted'],
165  'b' => ['type' => 'Aspect'],
166  'c' => ['type' => 'Persisted'],
167  'd' => ['type' => 'Aspect'],
168  ],
169  [
170  'b' => AspectInterface::class,
171  'd' => AspectInterface::class,
172  'a' => PersistedMappableAspectInterface::class,
173  'c' => PersistedMappableAspectInterface::class,
174  ],
175  ],
176  ];
177  }
178 
186  public function ‪aspectsAreCreatedAndSorted(array $settings, array $expectation)
187  {
188  $aspects = $this->subject->createAspects(
189  $settings,
190  $this->languageProphecy->reveal(),
191  $this->siteProphecy->reveal()
192  );
193  static::assertSame(array_keys($aspects), array_keys($expectation));
194  array_walk($aspects, function ($aspect, $key) use ($expectation) {
195  static::assertInstanceOf($expectation[$key], $aspect);
196  });
197  }
198 }
‪TYPO3\CMS\Core\Routing\Aspect\AspectInterface
Definition: AspectInterface.php:23
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\$aspectMockClass
‪string $aspectMockClass
Definition: AspectFactoryTest.php:49
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest
Definition: AspectFactoryTest.php:30
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\setUp
‪setUp()
Definition: AspectFactoryTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\createAspectsThrowsExceptionOnUnregisteredType
‪createAspectsThrowsExceptionOnUnregisteredType()
Definition: AspectFactoryTest.php:100
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\aspectsDataProvider
‪array aspectsDataProvider()
Definition: AspectFactoryTest.php:114
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:25
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\$subject
‪AspectFactory $subject
Definition: AspectFactoryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\$siteProphecy
‪Site ObjectProphecy $siteProphecy
Definition: AspectFactoryTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\$persistedMockClass
‪string $persistedMockClass
Definition: AspectFactoryTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\tearDown
‪tearDown()
Definition: AspectFactoryTest.php:77
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\createAspectsThrowsExceptionOnMissingType
‪createAspectsThrowsExceptionOnMissingType()
Definition: AspectFactoryTest.php:86
‪TYPO3\CMS\Core\Routing\Aspect\AspectFactory
Definition: AspectFactory.php:32
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\aspectsAreCreatedAndSorted
‪aspectsAreCreatedAndSorted(array $settings, array $expectation)
Definition: AspectFactoryTest.php:181
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer\AspectFactoryTest\$languageProphecy
‪SiteLanguage ObjectProphecy $languageProphecy
Definition: AspectFactoryTest.php:37
‪TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface
Definition: PersistedMappableAspectInterface.php:24
‪TYPO3\CMS\Core\Tests\Unit\Routing\Enhancer
Definition: AspectFactoryTest.php:4