[TASK] Use real ObjectManager stubs in unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Utility / ExtensionModelUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
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
19 /**
20 * Test for ExtensionModelUtilityTest
21 */
22 class ExtensionModelUtilityTest extends UnitTestCase
23 {
24 /**
25 * @var bool Reset singletons created by subject
26 */
27 protected $resetSingletonInstances = true;
28
29 /**
30 * @test
31 */
32 public function convertDependenciesToObjectsCreatesObjectStorage()
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 ]);
41 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
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
51 /**
52 * @test
53 */
54 public function convertDependenciesToObjectsSetsIdentifier()
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 ]);
63 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
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
75 /**
76 * @return array
77 */
78 public function convertDependenciesToObjectSetsVersionDataProvider()
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
128 /**
129 * @test
130 * @dataProvider convertDependenciesToObjectSetsVersionDataProvider
131 * @param array $dependencies
132 * @param array $returnValue
133 */
134 public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
135 {
136 $serializedDependencies = serialize($dependencies);
137 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
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
148 /**
149 * @test
150 */
151 public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues()
152 {
153 $dependencies = [
154 'depends' => ''
155 ];
156 $serializedDependencies = serialize($dependencies);
157 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
158 $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
159 $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
160 $this->assertSame(0, $dependencyObject->count());
161 }
162 }