‪TYPO3CMS  10.4
ExtensionModelUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪ExtensionModelUtilityTest extends UnitTestCase
27 {
31  protected ‪$resetSingletonInstances = true;
32 
37  {
38  $serializedDependencies = serialize([
39  'depends' => [
40  'php' => '5.1.0-0.0.0',
41  'typo3' => '4.2.0-4.4.99',
42  'fn_lib' => ''
43  ]
44  ]);
46  $dependencyUtility = new ‪ExtensionModelUtility();
47  $objectManagerMock = $this->createMock(ObjectManager::class);
48  $objectManagerMock->method('get')->willReturn(new ‪Dependency());
49  $dependencyUtility->injectObjectManager($objectManagerMock);
50  $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
51  self::assertInstanceOf(\SplObjectStorage::class, $objectStorage);
52  }
53 
57  public function ‪convertDependenciesToObjectsSetsIdentifier(): void
58  {
59  $serializedDependencies = serialize([
60  'depends' => [
61  'php' => '5.1.0-0.0.0',
62  'typo3' => '4.2.0-4.4.99',
63  'fn_lib' => ''
64  ]
65  ]);
66 
67  $dependencyUtility = new ‪ExtensionModelUtility();
68  $objectManagerMock = $this->createMock(ObjectManager::class);
69  // ensure we get a new dependency on subsequent calls
70  $objectManagerMock->method('get')->willReturnCallback(
71  static function () {
72  return new ‪Dependency();
73  }
74  );
75  $dependencyUtility->injectObjectManager($objectManagerMock);
76  $dependencyObjects = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
77  $identifiers = [];
78  foreach ($dependencyObjects as $resultingDependency) {
79  $identifiers[] = $resultingDependency->getIdentifier();
80  }
81  self::assertSame($identifiers, ['php', 'typo3', 'fn_lib']);
82  }
83 
88  {
89  return [
90  'everything ok' => [
91  [
92  'depends' => [
93  'typo3' => '4.2.0-4.4.99'
94  ]
95  ],
96  [
97  '4.2.0',
98  '4.4.99'
99  ]
100  ],
101  'empty high value' => [
102  [
103  'depends' => [
104  'typo3' => '4.2.0-0.0.0'
105  ]
106  ],
107  [
108  '4.2.0',
109  ''
110  ]
111  ],
112  'empty low value' => [
113  [
114  'depends' => [
115  'typo3' => '0.0.0-4.4.99'
116  ]
117  ],
118  [
119  '',
120  '4.4.99'
121  ]
122  ],
123  'only one value' => [
124  [
125  'depends' => [
126  'typo3' => '4.4.99'
127  ]
128  ],
129  [
130  '4.4.99',
131  '',
132  ]
133  ],
134  ];
135  }
136 
143  public function ‪convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue): void
144  {
145  $serializedDependencies = serialize($dependencies);
146  $dependencyUtility = new ‪ExtensionModelUtility();
147  $objectManagerMock = $this->createMock(ObjectManager::class);
148  // ensure we get a new dependency on subsequent calls
149  $objectManagerMock->method('get')->willReturnCallback(
150  static function () {
151  return new ‪Dependency();
152  }
153  );
154  $dependencyUtility->injectObjectManager($objectManagerMock);
155  $dependencyObjects = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
156  foreach ($dependencyObjects as $resultingDependency) {
157  self::assertSame($returnValue[0], $resultingDependency->getLowestVersion());
158  self::assertSame($returnValue[1], $resultingDependency->getHighestVersion());
159  }
160  }
161 
166  {
167  $dependencies = [
168  'depends' => ''
169  ];
170  $serializedDependencies = serialize($dependencies);
171  $dependencyObject = (new ‪ExtensionModelUtility())->convertDependenciesToObjects($serializedDependencies);
172  self::assertSame(0, $dependencyObject->count());
173  }
174 }
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency
Definition: Dependency.php:26
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectSetsVersion
‪convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
Definition: ExtensionModelUtilityTest.php:142
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility
Definition: DependencyUtilityTest.php:16
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
Definition: ExtensionModelUtility.php:28
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectCanDealWithEmptyStringDependencyValues
‪convertDependenciesToObjectCanDealWithEmptyStringDependencyValues()
Definition: ExtensionModelUtilityTest.php:164
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectSetsVersionDataProvider
‪array convertDependenciesToObjectSetsVersionDataProvider()
Definition: ExtensionModelUtilityTest.php:86
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectsCreatesObjectStorage
‪convertDependenciesToObjectsCreatesObjectStorage()
Definition: ExtensionModelUtilityTest.php:35
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectsSetsIdentifier
‪convertDependenciesToObjectsSetsIdentifier()
Definition: ExtensionModelUtilityTest.php:56
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest
Definition: ExtensionModelUtilityTest.php:27
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ExtensionModelUtilityTest.php:30
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28