[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Controller / UpdateFromTerControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Controller;
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 use TYPO3\CMS\Components\TestingFramework\Core\AccessibleObjectInterface;
18 use TYPO3\CMS\Extensionmanager\Controller\UpdateFromTerController;
19
20 /**
21 * Update from TER controller test
22 *
23 */
24 class UpdateFromTerControllerTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
25 {
26 /**
27 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
28 */
29 protected $mockObjectManager;
30
31 /**
32 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
33 */
34 protected $repositoryRepositoryMock;
35
36 /**
37 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
38 */
39 protected $extensionRepositoryMock;
40
41 /**
42 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
43 */
44 protected $repositoryHelperMock;
45
46 /**
47 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Lang\LanguageService
48 */
49 protected $languageServiceMock;
50
51 protected function setUp()
52 {
53 $this->mockObjectManager = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class)->getMock();
54 $this->repositoryRepositoryMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class)
55 ->setMethods(['findByUid'])
56 ->setConstructorArgs([$this->mockObjectManager])
57 ->getMock();
58 $this->extensionRepositoryMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class, [], [$this->mockObjectManager]);
59 $this->repositoryHelperMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class, ['updateExtList'], [], '', false);
60 $this->languageServiceMock = $this->getMockBuilder(\TYPO3\CMS\Lang\LanguageService::class)
61 ->setMethods(['__none'])
62 ->getMock();
63 }
64
65 /**
66 * @test
67 * @return void
68 */
69 public function updateExtensionListFromTerCallsUpdateExtListIfExtensionListIsEmpty()
70 {
71 /** @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|UpdateFromTerController $controllerMock */
72 $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, ['getLanguageService']);
73 $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
74
75 $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, ['getLastUpdate']);
76 $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['assign'], [], '', false);
77 $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, ['hasArgument', 'getArgument']);
78 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
79 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
80 $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
81 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(0));
82 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
83 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
84 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
85 $controllerMock->_set('settings', ['repositoryUid' => 1]);
86 $controllerMock->_set('view', $viewMock);
87 $controllerMock->_set('request', $requestMock);
88 $controllerMock->updateExtensionListFromTerAction();
89 }
90
91 /**
92 * @test
93 * @return void
94 */
95 public function updateExtensionListFromTerDoesNotCallsUpdateExtListIfExtensionListIsNotEmpty()
96 {
97 /** @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|UpdateFromTerController $controllerMock */
98 $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, ['getLanguageService']);
99 $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
100
101 $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, ['getLastUpdate']);
102 $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['assign'], [], '', false);
103 $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, ['hasArgument', 'getArgument']);
104 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
105 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
106 $this->repositoryHelperMock->expects($this->never())->method('updateExtList');
107 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
108 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
109 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
110 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
111 $controllerMock->_set('settings', ['repositoryUid' => 1]);
112 $controllerMock->_set('view', $viewMock);
113 $controllerMock->_set('request', $requestMock);
114 $controllerMock->updateExtensionListFromTerAction();
115 }
116
117 /**
118 * @test
119 * @return void
120 */
121 public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet()
122 {
123 /** @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|UpdateFromTerController $controllerMock */
124 $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, ['getLanguageService']);
125 $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
126
127 $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, ['getLastUpdate']);
128 $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, ['assign'], [], '', false);
129 $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, ['hasArgument', 'getArgument']);
130 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
131 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
132 $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
133 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
134 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
135 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
136 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
137 $controllerMock->_set('settings', ['repositoryUid' => 1]);
138 $controllerMock->_set('view', $viewMock);
139 $controllerMock->_set('request', $requestMock);
140 $controllerMock->updateExtensionListFromTerAction(true);
141 }
142 }