98a1a5011559ec11912cfe9e95f1e2a58dc8be62
[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 * Copyright notice
6 *
7 * (c) 2012
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Test for ExtensionModelUtilityTest
29 */
30 class ExtensionModelUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
31
32 /**
33 * @test
34 * @return void
35 */
36 public function convertDependenciesToObjectsCreatesObjectStorage() {
37 $serializedDependencies = serialize(array(
38 'depends' => array(
39 'php' => '5.1.0-0.0.0',
40 'typo3' => '4.2.0-4.4.99',
41 'fn_lib' => ''
42 )
43 ));
44 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
45 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
46 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
47 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('dummy'));
48 $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
49 $dependencyUtility->_set('objectManager', $objectManagerMock);
50 $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
51 $this->assertTrue($objectStorage instanceof \SplObjectStorage);
52 }
53
54 /**
55 * @test
56 * @return void
57 */
58 public function convertDependenciesToObjectsSetsIdentifier() {
59 $serializedDependencies = serialize(array(
60 'depends' => array(
61 'php' => '5.1.0-0.0.0',
62 'typo3' => '4.2.0-4.4.99',
63 'fn_lib' => ''
64 )
65 ));
66 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
67 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
68 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
69 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setIdentifier'));
70 $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
71 $dependencyUtility->_set('objectManager', $objectManagerMock);
72 $dependencyModelMock->expects($this->at(0))->method('setIdentifier')->with('php');
73 $dependencyModelMock->expects($this->at(1))->method('setIdentifier')->with('typo3');
74 $dependencyModelMock->expects($this->at(2))->method('setIdentifier')->with('fn_lib');
75 $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
76 }
77
78 /**
79 * @return array
80 */
81 public function convertDependenciesToObjectSetsVersionDataProvider() {
82 return array(
83 'everything ok' => array(
84 array(
85 'depends' => array(
86 'typo3' => '4.2.0-4.4.99'
87 )
88 ),
89 array(
90 '4.2.0',
91 '4.4.99'
92 )
93 ),
94 'empty high value' => array(
95 array(
96 'depends' => array(
97 'typo3' => '4.2.0-0.0.0'
98 )
99 ),
100 array(
101 '4.2.0',
102 ''
103 )
104 ),
105 'empty low value' => array(
106 array(
107 'depends' => array(
108 'typo3' => '0.0.0-4.4.99'
109 )
110 ),
111 array(
112 '',
113 '4.4.99'
114 )
115 ),
116 'only one value' => array(
117 array(
118 'depends' => array(
119 'typo3' => '4.4.99'
120 )
121 ),
122 array(
123 '4.4.99',
124 '',
125 )
126 ),
127 );
128 }
129
130 /**
131 * @test
132 * @dataProvider convertDependenciesToObjectSetsVersionDataProvider
133 * @param array $dependencies
134 * @param array $returnValue
135 * @return void
136 */
137 public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue) {
138 $serializedDependencies = serialize($dependencies);
139 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
140 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
141 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
142 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setHighestVersion', 'setLowestVersion'));
143 $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
144 $dependencyUtility->_set('objectManager', $objectManagerMock);
145 $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
146 $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
147 $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
148 }
149
150 /**
151 * @test
152 */
153 public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues() {
154 $dependencies = array(
155 'depends' => ''
156 );
157 $serializedDependencies = serialize($dependencies);
158 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
159 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
160 $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
161 $this->assertSame(0, $dependencyObject->count());
162 }
163 }