‪TYPO3CMS  ‪main
ExtensionTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 final class ‪ExtensionTest extends UnitTestCase
29 {
34  {
35  return [
36  'empty string' => [
37  '',
38  4,
39  ],
40  'existing category string' => [
41  'plugin',
42  3,
43  ],
44  'not existing category string' => [
45  'foo',
46  4,
47  ],
48  'string number 3' => [
49  '3',
50  3,
51  ],
52  'integer 3' => [
53  3,
54  3,
55  ],
56  'string number not in range -1' => [
57  '-1',
58  4,
59  ],
60  'integer not in range -1' => [
61  -1,
62  4,
63  ],
64  'string number not in range 11' => [
65  '11',
66  4,
67  ],
68  'integer not in range 11' => [
69  11,
70  4,
71  ],
72  'object' => [
73  new \stdClass(),
74  4,
75  ],
76  'array' => [
77  [],
78  4,
79  ],
80  ];
81  }
82 
87  #[DataProvider('getCategoryIndexFromStringOrNumberReturnsIndexDataProvider')]
88  #[Test]
89  public function ‪getCategoryIndexFromStringOrNumberReturnsIndex($input, $expected): void
90  {
91  $extension = new ‪Extension();
92  self::assertEquals($expected, $extension->getCategoryIndexFromStringOrNumber($input));
93  }
94  #[Test]
96  {
97  $serializedDependencies = [
98  'depends' => [
99  'php' => '5.1.0-0.0.0',
100  'typo3' => '4.2.0-4.4.99',
101  'fn_lib' => '',
102  ],
103  ];
104  $dependencyObjects = ‪Extension::createFromExtensionArray(['key' => 'no-name', 'constraints' => $serializedDependencies])->getDependencies();
105  self::assertInstanceOf(\SplObjectStorage::class, $dependencyObjects);
106  }
107 
108  #[Test]
110  {
111  $serializedDependencies = [
112  'depends' => [
113  'php' => '5.1.0-0.0.0',
114  'typo3' => '4.2.0-4.4.99',
115  'fn_lib' => '',
116  ],
117  ];
118 
119  $dependencyObjects = ‪Extension::createFromExtensionArray(['key' => 'no-name', 'constraints' => $serializedDependencies])->getDependencies();
120  $identifiers = [];
121  foreach ($dependencyObjects as $resultingDependency) {
122  $identifiers[] = $resultingDependency->getIdentifier();
123  }
124  self::assertSame($identifiers, ['php', 'typo3', 'fn_lib']);
125  }
126 
128  {
129  return [
130  'everything ok' => [
131  [
132  'depends' => [
133  'typo3' => '4.2.0-4.4.99',
134  ],
135  ],
136  [
137  '4.2.0',
138  '4.4.99',
139  ],
140  ],
141  'empty high value' => [
142  [
143  'depends' => [
144  'typo3' => '4.2.0-0.0.0',
145  ],
146  ],
147  [
148  '4.2.0',
149  '',
150  ],
151  ],
152  'empty low value' => [
153  [
154  'depends' => [
155  'typo3' => '0.0.0-4.4.99',
156  ],
157  ],
158  [
159  '',
160  '4.4.99',
161  ],
162  ],
163  'only one value' => [
164  [
165  'depends' => [
166  'typo3' => '4.4.99',
167  ],
168  ],
169  [
170  '4.4.99',
171  '',
172  ],
173  ],
174  ];
175  }
176 
177  #[DataProvider('convertDependenciesToObjectSetsVersionDataProvider')]
178  #[Test]
179  public function ‪convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue): void
180  {
181  $serializedDependencies = serialize($dependencies);
182  $dependencyObjects = ‪Extension::createFromExtensionArray(['key' => 'no-name', 'constraints' => $serializedDependencies])->getDependencies();
183  foreach ($dependencyObjects as $resultingDependency) {
184  self::assertSame($returnValue[0], $resultingDependency->getLowestVersion());
185  self::assertSame($returnValue[1], $resultingDependency->getHighestVersion());
186  }
187  }
188 
189  #[Test]
191  {
192  $dependencies = [
193  'depends' => '',
194  ];
195  $serializedDependencies = serialize($dependencies);
196  $dependencyObjects = ‪Extension::createFromExtensionArray(['key' => 'no-name', 'constraints' => $serializedDependencies])->getDependencies();
197  self::assertSame(0, $dependencyObjects->count());
198  }
199 
200  #[Test]
201  public function ‪getDistributionImageTest(): void
202  {
203  $imageUrl = 'https://example.org/path/to/image.png';
204 
205  $extension = new ‪Extension();
206  $extension->setDistributionImage($imageUrl);
207 
208  self::assertEquals(
209  $imageUrl,
210  $extension->getDistributionImage()
211  );
212  }
213 
214  #[Test]
215  public function ‪getDistributionWelcomeImageTest(): void
216  {
217  $imageUrl = 'https://example.org/path/to/image.png';
218 
219  $extension = new ‪Extension();
220  $extension->setDistributionWelcomeImage($imageUrl);
221 
222  self::assertEquals(
223  $imageUrl,
224  $extension->getDistributionWelcomeImage()
225  );
226  }
227 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model
Definition: DependencyTest.php:18
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:30
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\convertDependenciesToObjectCanDealWithEmptyStringDependencyValues
‪convertDependenciesToObjectCanDealWithEmptyStringDependencyValues()
Definition: ExtensionTest.php:190
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\getDistributionImageTest
‪getDistributionImageTest()
Definition: ExtensionTest.php:201
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest
Definition: ExtensionTest.php:29
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\convertDependenciesToObjectsCreatesObjectStorage
‪convertDependenciesToObjectsCreatesObjectStorage()
Definition: ExtensionTest.php:95
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\createFromExtensionArray
‪static createFromExtensionArray(array $extensionArray)
Definition: Extension.php:418
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\convertDependenciesToObjectSetsVersionDataProvider
‪static convertDependenciesToObjectSetsVersionDataProvider()
Definition: ExtensionTest.php:127
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\getCategoryIndexFromStringOrNumberReturnsIndex
‪getCategoryIndexFromStringOrNumberReturnsIndex($input, $expected)
Definition: ExtensionTest.php:89
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\convertDependenciesToObjectsSetsIdentifier
‪convertDependenciesToObjectsSetsIdentifier()
Definition: ExtensionTest.php:109
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\getCategoryIndexFromStringOrNumberReturnsIndexDataProvider
‪static getCategoryIndexFromStringOrNumberReturnsIndexDataProvider()
Definition: ExtensionTest.php:33
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\getDistributionWelcomeImageTest
‪getDistributionWelcomeImageTest()
Definition: ExtensionTest.php:215
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model\ExtensionTest\convertDependenciesToObjectSetsVersion
‪convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
Definition: ExtensionTest.php:179