TYPO3 CMS  TYPO3_7-6
ExtensionModelUtilityTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
26  public function convertDependenciesToObjectsCreatesObjectStorage()
27  {
28  $serializedDependencies = serialize([
29  'depends' => [
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, ['dummy']);
37  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
38  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['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([
52  'depends' => [
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, ['dummy']);
60  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
61  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['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 [
76  'everything ok' => [
77  [
78  'depends' => [
79  'typo3' => '4.2.0-4.4.99'
80  ]
81  ],
82  [
83  '4.2.0',
84  '4.4.99'
85  ]
86  ],
87  'empty high value' => [
88  [
89  'depends' => [
90  'typo3' => '4.2.0-0.0.0'
91  ]
92  ],
93  [
94  '4.2.0',
95  ''
96  ]
97  ],
98  'empty low value' => [
99  [
100  'depends' => [
101  'typo3' => '0.0.0-4.4.99'
102  ]
103  ],
104  [
105  '',
106  '4.4.99'
107  ]
108  ],
109  'only one value' => [
110  [
111  'depends' => [
112  'typo3' => '4.4.99'
113  ]
114  ],
115  [
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, ['dummy']);
135  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
136  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['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 = [
150  'depends' => ''
151  ];
152  $serializedDependencies = serialize($dependencies);
154  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
155  $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
156  $this->assertSame(0, $dependencyObject->count());
157  }
158 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)