[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Task / UpdateExtensionListTaskTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Task;
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 case
19 *
20 */
21 class UpdateExtensionListTaskTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
22
23 /**
24 * @var array A backup of registered singleton instances
25 */
26 protected $singletonInstances = array();
27
28 /**
29 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
30 */
31 protected $repositoryHelper;
32
33 /**
34 * Set up
35 */
36 public function setUp() {
37 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
38 $this->markTestSkipped('Tests need EXT:scheduler loaded.');
39 }
40 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
41 $this->repositoryHelper = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper', array(), array(), '', FALSE);
42 }
43
44 /**
45 * Tear down
46 */
47 public function tearDown() {
48 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
49 parent::tearDown();
50 }
51
52 /**
53 * @test
54 */
55 public function updateExtensionListTaskIsInstanceOfAbstractTask() {
56 $taskMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Task\\UpdateExtensionListTask');
57 $this->assertInstanceOf('TYPO3\\CMS\\Scheduler\\Task\\AbstractTask', $taskMock);
58 }
59
60 /**
61 * @test
62 */
63 public function executeCallsUpdateExtListOfRepositoryHelper() {
64 $this->repositoryHelper
65 ->expects($this->once())
66 ->method('updateExtList');
67
68 $objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
69 $objectManagerMock
70 ->expects($this->at(0))
71 ->method('get')
72 ->with('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper')
73 ->will($this->returnValue($this->repositoryHelper));
74
75 $persistenceManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
76 $objectManagerMock
77 ->expects($this->at(1))
78 ->method('get')
79 ->will($this->returnValue($persistenceManagerMock));
80
81 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', $objectManagerMock);
82
83 $task = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Task\\UpdateExtensionListTask', array('dummy'), array(), '', FALSE);
84 $task->execute();
85 }
86
87 /**
88 * @test
89 */
90 public function executeCallsPersistAllOnPersistenceManager() {
91 $objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
92 $objectManagerMock
93 ->expects($this->at(0))
94 ->method('get')
95 ->with('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper')
96 ->will($this->returnValue($this->repositoryHelper));
97
98 $persistenceManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
99 $persistenceManagerMock
100 ->expects($this->once())
101 ->method('persistAll');
102
103 $objectManagerMock
104 ->expects($this->at(1))
105 ->method('get')
106 ->will($this->returnValue($persistenceManagerMock));
107
108 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', $objectManagerMock);
109
110 $task = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Task\\UpdateExtensionListTask', array('dummy'), array(), '', FALSE);
111 $task->execute();
112 }
113 }