‪TYPO3CMS  9.5
ExtensionModelUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪ExtensionModelUtilityTest extends UnitTestCase
23 {
27  protected ‪$resetSingletonInstances = true;
28 
33  {
34  $serializedDependencies = serialize([
35  'depends' => [
36  'php' => '5.1.0-0.0.0',
37  'typo3' => '4.2.0-4.4.99',
38  'fn_lib' => ''
39  ]
40  ]);
42  $dependencyUtility = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
43  $objectManagerMock = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
44  $dependencyModelMock = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['dummy']);
45  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
46  $dependencyUtility->_set('objectManager', $objectManagerMock);
47  $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
48  $this->assertTrue($objectStorage instanceof \SplObjectStorage);
49  }
50 
55  {
56  $serializedDependencies = serialize([
57  'depends' => [
58  'php' => '5.1.0-0.0.0',
59  'typo3' => '4.2.0-4.4.99',
60  'fn_lib' => ''
61  ]
62  ]);
64  $dependencyUtility = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
65  $objectManagerMock = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
66  $dependencyModelMock = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['setIdentifier']);
67  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
68  $dependencyUtility->_set('objectManager', $objectManagerMock);
69  $dependencyModelMock->expects($this->at(0))->method('setIdentifier')->with('php');
70  $dependencyModelMock->expects($this->at(1))->method('setIdentifier')->with('typo3');
71  $dependencyModelMock->expects($this->at(2))->method('setIdentifier')->with('fn_lib');
72  $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
73  }
74 
79  {
80  return [
81  'everything ok' => [
82  [
83  'depends' => [
84  'typo3' => '4.2.0-4.4.99'
85  ]
86  ],
87  [
88  '4.2.0',
89  '4.4.99'
90  ]
91  ],
92  'empty high value' => [
93  [
94  'depends' => [
95  'typo3' => '4.2.0-0.0.0'
96  ]
97  ],
98  [
99  '4.2.0',
100  ''
101  ]
102  ],
103  'empty low value' => [
104  [
105  'depends' => [
106  'typo3' => '0.0.0-4.4.99'
107  ]
108  ],
109  [
110  '',
111  '4.4.99'
112  ]
113  ],
114  'only one value' => [
115  [
116  'depends' => [
117  'typo3' => '4.4.99'
118  ]
119  ],
120  [
121  '4.4.99',
122  '',
123  ]
124  ],
125  ];
126  }
127 
134  public function ‪convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
135  {
136  $serializedDependencies = serialize($dependencies);
138  $dependencyUtility = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
139  $objectManagerMock = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
140  $dependencyModelMock = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['setHighestVersion', 'setLowestVersion']);
141  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
142  $dependencyUtility->_set('objectManager', $objectManagerMock);
143  $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
144  $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
145  $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
146  }
147 
152  {
153  $dependencies = [
154  'depends' => ''
155  ];
156  $serializedDependencies = serialize($dependencies);
158  $dependencyUtility = $this->getAccessibleMock(\‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
159  $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
160  $this->assertSame(0, $dependencyObject->count());
161  }
162 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectSetsVersion
‪convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
Definition: ExtensionModelUtilityTest.php:133
‪TYPO3
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility
Definition: DependencyUtilityTest.php:2
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectCanDealWithEmptyStringDependencyValues
‪convertDependenciesToObjectCanDealWithEmptyStringDependencyValues()
Definition: ExtensionModelUtilityTest.php:150
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectSetsVersionDataProvider
‪array convertDependenciesToObjectSetsVersionDataProvider()
Definition: ExtensionModelUtilityTest.php:77
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectsCreatesObjectStorage
‪convertDependenciesToObjectsCreatesObjectStorage()
Definition: ExtensionModelUtilityTest.php:31
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\convertDependenciesToObjectsSetsIdentifier
‪convertDependenciesToObjectsSetsIdentifier()
Definition: ExtensionModelUtilityTest.php:53
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest
Definition: ExtensionModelUtilityTest.php:23
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ExtensionModelUtilityTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ExtensionModelUtilityTest.php:26