[!!!][TASK] Extract testing framework for TYPO3
[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\Components\TestingFramework\Core\UnitTestCase
22 {
23 /**
24 * @var array A backup of registered singleton instances
25 */
26 protected $singletonInstances = [];
27
28 /**
29 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
30 */
31 protected $repositoryHelper;
32
33 /**
34 * Set up
35 */
36 protected function setUp()
37 {
38 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
39 $this->markTestSkipped('Tests need EXT:scheduler loaded.');
40 }
41 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
42 $this->repositoryHelper = $this->createMock(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class);
43 }
44
45 /**
46 * Tear down
47 */
48 protected function tearDown()
49 {
50 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
51 parent::tearDown();
52 }
53
54 /**
55 * @test
56 */
57 public function updateExtensionListTaskIsInstanceOfAbstractTask()
58 {
59 $taskMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class)->getMock();
60 $this->assertInstanceOf(\TYPO3\CMS\Scheduler\Task\AbstractTask::class, $taskMock);
61 }
62
63 /**
64 * @test
65 */
66 public function executeCallsUpdateExtListOfRepositoryHelper()
67 {
68 $this->repositoryHelper
69 ->expects($this->once())
70 ->method('updateExtList');
71
72 $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManager::class)->getMock();
73 $objectManagerMock
74 ->expects($this->at(0))
75 ->method('get')
76 ->with(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class)
77 ->will($this->returnValue($this->repositoryHelper));
78
79 $persistenceManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->getMock();
80 $objectManagerMock
81 ->expects($this->at(1))
82 ->method('get')
83 ->will($this->returnValue($persistenceManagerMock));
84
85 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
86
87 $task = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class)
88 ->setMethods(['dummy'])
89 ->disableOriginalConstructor()
90 ->getMock();
91 $task->execute();
92 }
93
94 /**
95 * @test
96 */
97 public function executeCallsPersistAllOnPersistenceManager()
98 {
99 $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManager::class)->getMock();
100 $objectManagerMock
101 ->expects($this->at(0))
102 ->method('get')
103 ->with(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class)
104 ->will($this->returnValue($this->repositoryHelper));
105
106 $persistenceManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->getMock();
107 $persistenceManagerMock
108 ->expects($this->once())
109 ->method('persistAll');
110
111 $objectManagerMock
112 ->expects($this->at(1))
113 ->method('get')
114 ->will($this->returnValue($persistenceManagerMock));
115
116 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
117
118 /** @var \TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask|PHPUnit_Framework_MockObject_MockObject $task */
119 $task = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class)
120 ->setMethods(['dummy'])
121 ->disableOriginalConstructor()
122 ->getMock();
123 $task->execute();
124 }
125 }