TYPO3 CMS  TYPO3_8-7
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 
20 class ExtensionModelUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  public function convertDependenciesToObjectsCreatesObjectStorage()
26  {
27  $serializedDependencies = serialize([
28  'depends' => [
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::class, ['dummy']);
36  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
37  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['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 
47  public function convertDependenciesToObjectsSetsIdentifier()
48  {
49  $serializedDependencies = serialize([
50  'depends' => [
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::class, ['dummy']);
58  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
59  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['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  {
73  return [
74  'everything ok' => [
75  [
76  'depends' => [
77  'typo3' => '4.2.0-4.4.99'
78  ]
79  ],
80  [
81  '4.2.0',
82  '4.4.99'
83  ]
84  ],
85  'empty high value' => [
86  [
87  'depends' => [
88  'typo3' => '4.2.0-0.0.0'
89  ]
90  ],
91  [
92  '4.2.0',
93  ''
94  ]
95  ],
96  'empty low value' => [
97  [
98  'depends' => [
99  'typo3' => '0.0.0-4.4.99'
100  ]
101  ],
102  [
103  '',
104  '4.4.99'
105  ]
106  ],
107  'only one value' => [
108  [
109  'depends' => [
110  'typo3' => '4.4.99'
111  ]
112  ],
113  [
114  '4.4.99',
115  '',
116  ]
117  ],
118  ];
119  }
120 
127  public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue)
128  {
129  $serializedDependencies = serialize($dependencies);
131  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
132  $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
133  $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['setHighestVersion', 'setLowestVersion']);
134  $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
135  $dependencyUtility->_set('objectManager', $objectManagerMock);
136  $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
137  $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
138  $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
139  }
140 
144  public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues()
145  {
146  $dependencies = [
147  'depends' => ''
148  ];
149  $serializedDependencies = serialize($dependencies);
151  $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
152  $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
153  $this->assertSame(0, $dependencyObject->count());
154  }
155 }