TYPO3 CMS  TYPO3_8-7
UpdateFromTerControllerTest.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 
19 
23 class UpdateFromTerControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
28  protected $mockObjectManager;
29 
34 
39 
44 
49 
50  protected function setUp()
51  {
52  $this->mockObjectManager = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class)->getMock();
53  $this->repositoryRepositoryMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class)
54  ->setMethods(['findByUid'])
55  ->setConstructorArgs([$this->mockObjectManager])
56  ->getMock();
57  $this->extensionRepositoryMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class, [], [$this->mockObjectManager]);
58  $this->repositoryHelperMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class, ['updateExtList'], [], '', false);
59  $this->languageServiceMock = $this->getMockBuilder(\TYPO3\CMS\Lang\LanguageService::class)
60  ->setMethods(['__none'])
61  ->getMock();
62  }
63 
67  public function updateExtensionListFromTerCallsUpdateExtListIfExtensionListIsEmpty()
68  {
70  $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, ['getLanguageService']);
71  $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
72 
73  $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, ['getLastUpdate']);
74  $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['assign'], [], '', false);
75  $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, ['hasArgument', 'getArgument']);
76  $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
77  $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
78  $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
79  $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(0));
80  $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
81  $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
82  $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
83  $controllerMock->_set('settings', ['repositoryUid' => 1]);
84  $controllerMock->_set('view', $viewMock);
85  $controllerMock->_set('request', $requestMock);
86  $controllerMock->updateExtensionListFromTerAction();
87  }
88 
92  public function updateExtensionListFromTerDoesNotCallsUpdateExtListIfExtensionListIsNotEmpty()
93  {
95  $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, ['getLanguageService']);
96  $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
97 
98  $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, ['getLastUpdate']);
99  $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['assign'], [], '', false);
100  $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, ['hasArgument', 'getArgument']);
101  $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
102  $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
103  $this->repositoryHelperMock->expects($this->never())->method('updateExtList');
104  $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
105  $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
106  $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
107  $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
108  $controllerMock->_set('settings', ['repositoryUid' => 1]);
109  $controllerMock->_set('view', $viewMock);
110  $controllerMock->_set('request', $requestMock);
111  $controllerMock->updateExtensionListFromTerAction();
112  }
113 
117  public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet()
118  {
120  $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, ['getLanguageService']);
121  $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
122 
123  $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, ['getLastUpdate']);
124  $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['assign'], [], '', false);
125  $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, ['hasArgument', 'getArgument']);
126  $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
127  $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
128  $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
129  $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
130  $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
131  $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
132  $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
133  $controllerMock->_set('settings', ['repositoryUid' => 1]);
134  $controllerMock->_set('view', $viewMock);
135  $controllerMock->_set('request', $requestMock);
136  $controllerMock->updateExtensionListFromTerAction(true);
137  }
138 }