[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 /**
18 * Test for ExtensionModelUtilityTest
19 */
20 class ExtensionModelUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @test
24 * @return void
25 */
26 public function convertDependenciesToObjectsCreatesObjectStorage() {
27 $serializedDependencies = serialize(array(
28 'depends' => array(
29 'php' => '5.1.0-0.0.0',
30 'typo3' => '4.2.0-4.4.99',
31 'fn_lib' => ''
32 )
33 ));
34 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
35 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
36 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
37 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('dummy'));
38 $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
39 $dependencyUtility->_set('objectManager', $objectManagerMock);
40 $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
41 $this->assertTrue($objectStorage instanceof \SplObjectStorage);
42 }
43
44 /**
45 * @test
46 * @return void
47 */
48 public function convertDependenciesToObjectsSetsIdentifier() {
49 $serializedDependencies = serialize(array(
50 'depends' => array(
51 'php' => '5.1.0-0.0.0',
52 'typo3' => '4.2.0-4.4.99',
53 'fn_lib' => ''
54 )
55 ));
56 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
57 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
58 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
59 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setIdentifier'));
60 $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
61 $dependencyUtility->_set('objectManager', $objectManagerMock);
62 $dependencyModelMock->expects($this->at(0))->method('setIdentifier')->with('php');
63 $dependencyModelMock->expects($this->at(1))->method('setIdentifier')->with('typo3');
64 $dependencyModelMock->expects($this->at(2))->method('setIdentifier')->with('fn_lib');
65 $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
66 }
67
68 /**
69 * @return array
70 */
71 public function convertDependenciesToObjectSetsVersionDataProvider() {
72 return array(
73 'everything ok' => array(
74 array(
75 'depends' => array(
76 'typo3' => '4.2.0-4.4.99'
77 )
78 ),
79 array(
80 '4.2.0',
81 '4.4.99'
82 )
83 ),
84 'empty high value' => array(
85 array(
86 'depends' => array(
87 'typo3' => '4.2.0-0.0.0'
88 )
89 ),
90 array(
91 '4.2.0',
92 ''
93 )
94 ),
95 'empty low value' => array(
96 array(
97 'depends' => array(
98 'typo3' => '0.0.0-4.4.99'
99 )
100 ),
101 array(
102 '',
103 '4.4.99'
104 )
105 ),
106 'only one value' => array(
107 array(
108 'depends' => array(
109 'typo3' => '4.4.99'
110 )
111 ),
112 array(
113 '4.4.99',
114 '',
115 )
116 ),
117 );
118 }
119
120 /**
121 * @test
122 * @dataProvider convertDependenciesToObjectSetsVersionDataProvider
123 * @param array $dependencies
124 * @param array $returnValue
125 * @return void
126 */
127 public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue) {
128 $serializedDependencies = serialize($dependencies);
129 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
130 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
131 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
132 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setHighestVersion', 'setLowestVersion'));
133 $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
134 $dependencyUtility->_set('objectManager', $objectManagerMock);
135 $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
136 $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
137 $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
138 }
139
140 /**
141 * @test
142 */
143 public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues() {
144 $dependencies = array(
145 'depends' => ''
146 );
147 $serializedDependencies = serialize($dependencies);
148 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
149 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
150 $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
151 $this->assertSame(0, $dependencyObject->count());
152 }
153 }