TYPO3 CMS  TYPO3_7-6
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 
22 {
26  protected $singletonInstances = [];
27 
31  protected $repositoryHelper;
32 
36  protected function setUp()
37  {
38  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
39  $this->markTestSkipped('Tests need EXT:scheduler loaded.');
40  }
42  $this->repositoryHelper = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class, [], [], '', false);
43  }
44 
48  protected function tearDown()
49  {
51  parent::tearDown();
52  }
53 
58  {
59  $taskMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class);
60  $this->assertInstanceOf(\TYPO3\CMS\Scheduler\Task\AbstractTask::class, $taskMock);
61  }
62 
67  {
68  $this->repositoryHelper
69  ->expects($this->once())
70  ->method('updateExtList');
71 
72  $objectManagerMock = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
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->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
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->getMock(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class, ['dummy'], [], '', false);
88  $task->execute();
89  }
90 
95  {
96  $objectManagerMock = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
97  $objectManagerMock
98  ->expects($this->at(0))
99  ->method('get')
100  ->with(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class)
101  ->will($this->returnValue($this->repositoryHelper));
102 
103  $persistenceManagerMock = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
104  $persistenceManagerMock
105  ->expects($this->once())
106  ->method('persistAll');
107 
108  $objectManagerMock
109  ->expects($this->at(1))
110  ->method('get')
111  ->will($this->returnValue($persistenceManagerMock));
112 
113  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
114 
115  $task = $this->getMock(\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class, ['dummy'], [], '', false);
116  $task->execute();
117  }
118 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)