TYPO3 CMS  TYPO3_8-7
UpdateExtensionListTaskTest.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 UpdateExtensionListTaskTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $singletonInstances = [];
26 
30  protected $repositoryHelper;
31 
35  protected function setUp()
36  {
37  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
38  $this->markTestSkipped('Tests need EXT:scheduler loaded.');
39  }
41  $this->repositoryHelper = $this->createMock(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class);
42  }
43 
47  protected function tearDown()
48  {
50  parent::tearDown();
51  }
52 
57  {
58  $taskMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class)->getMock();
59  $this->assertInstanceOf(\TYPO3\CMS\Scheduler\Task\AbstractTask::class, $taskMock);
60  }
61 
66  {
67  $this->repositoryHelper
68  ->expects($this->once())
69  ->method('updateExtList');
70 
71  $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManager::class)->getMock();
72  $objectManagerMock
73  ->expects($this->at(0))
74  ->method('get')
75  ->with(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class)
76  ->will($this->returnValue($this->repositoryHelper));
77 
78  $persistenceManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->getMock();
79  $objectManagerMock
80  ->expects($this->at(1))
81  ->method('get')
82  ->will($this->returnValue($persistenceManagerMock));
83 
84  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
85 
86  $task = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class)
87  ->setMethods(['dummy'])
88  ->disableOriginalConstructor()
89  ->getMock();
90  $task->execute();
91  }
92 
96  public function executeCallsPersistAllOnPersistenceManager()
97  {
98  $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManager::class)->getMock();
99  $objectManagerMock
100  ->expects($this->at(0))
101  ->method('get')
102  ->with(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class)
103  ->will($this->returnValue($this->repositoryHelper));
104 
105  $persistenceManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->getMock();
106  $persistenceManagerMock
107  ->expects($this->once())
108  ->method('persistAll');
109 
110  $objectManagerMock
111  ->expects($this->at(1))
112  ->method('get')
113  ->will($this->returnValue($persistenceManagerMock));
114 
115  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
116 
118  $task = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class)
119  ->setMethods(['dummy'])
120  ->disableOriginalConstructor()
121  ->getMock();
122  $task->execute();
123  }
124 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)