TYPO3  7.6
ExtensionModelUtilityTest.php
Go to the documentation of this file.
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 
20 class ExtensionModelUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
21 {
26  public function convertDependenciesToObjectsCreatesObjectStorage()
27  {
28  $serializedDependencies = serialize(array(
29  'depends' => array(
30  'php' => '5.1.0-0.0.0',
31  'typo3' => '4.2.0-4.4.99',
32  'fn_lib' => ''
33  )
34  ));
36  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, array('dummy'));
37  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, array('get'));
38  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, array('dummy'));
39  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
40  $dependencyUtility->_set('objectManager', $objectManagerMock);
41  $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
42  $this->assertTrue($objectStorage instanceof \SplObjectStorage);
43  }
44 
49  public function convertDependenciesToObjectsSetsIdentifier()
50  {
51  $serializedDependencies = serialize(array(
52  'depends' => array(
53  'php' => '5.1.0-0.0.0',
54  'typo3' => '4.2.0-4.4.99',
55  'fn_lib' => ''
56  )
57  ));
59  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, array('dummy'));
60  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, array('get'));
61  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, array('setIdentifier'));
62  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
63  $dependencyUtility->_set('objectManager', $objectManagerMock);
64  $dependencyModelMock->expects($this->at(0))->method('setIdentifier')->with('php');
65  $dependencyModelMock->expects($this->at(1))->method('setIdentifier')->with('typo3');
66  $dependencyModelMock->expects($this->at(2))->method('setIdentifier')->with('fn_lib');
67  $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
68  }
69 
74  {
75  return array(
76  'everything ok' => array(
77  array(
78  'depends' => array(
79  'typo3' => '4.2.0-4.4.99'
80  )
81  ),
82  array(
83  '4.2.0',
84  '4.4.99'
85  )
86  ),
87  'empty high value' => array(
88  array(
89  'depends' => array(
90  'typo3' => '4.2.0-0.0.0'
91  )
92  ),
93  array(
94  '4.2.0',
95  ''
96  )
97  ),
98  'empty low value' => array(
99  array(
100  'depends' => array(
101  'typo3' => '0.0.0-4.4.99'
102  )
103  ),
104  array(
105  '',
106  '4.4.99'
107  )
108  ),
109  'only one value' => array(
110  array(
111  'depends' => array(
112  'typo3' => '4.4.99'
113  )
114  ),
115  array(
116  '4.4.99',
117  '',
118  )
119  ),
120  );
121  }
122 
130  public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
131  {
132  $serializedDependencies = serialize($dependencies);
134  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, array('dummy'));
135  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, array('get'));
136  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, array('setHighestVersion', 'setLowestVersion'));
137  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
138  $dependencyUtility->_set('objectManager', $objectManagerMock);
139  $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
140  $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
141  $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
142  }
143 
147  public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues()
148  {
149  $dependencies = array(
150  'depends' => ''
151  );
152  $serializedDependencies = serialize($dependencies);
154  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, array('dummy'));
155  $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
156  $this->assertSame(0, $dependencyObject->count());
157  }
158 }