TYPO3 CMS  TYPO3_6-2
ExtensionModelUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
21 
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  ));
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 
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  ));
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 
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 
127  public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue) {
128  $serializedDependencies = serialize($dependencies);
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 
143  public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues() {
144  $dependencies = array(
145  'depends' => ''
146  );
147  $serializedDependencies = serialize($dependencies);
149  $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
150  $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
151  $this->assertSame(0, $dependencyObject->count());
152  }
153 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)