[FOLLOWUP][BUGFIX] Extension Manager: Use JsonView directly
[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\Core\Tests\AccessibleObjectInterface;
18 use TYPO3\CMS\Extensionmanager\Controller\UpdateFromTerController;
19
20 /**
21 * Update from TER controller test
22 *
23 */
24 class UpdateFromTerControllerTest extends \TYPO3\CMS\Core\Tests\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->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
54 $this->repositoryRepositoryMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class, array('findByUid'), array($this->mockObjectManager));
55 $this->extensionRepositoryMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class, array(), array($this->mockObjectManager));
56 $this->repositoryHelperMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class, array('updateExtList'), array(), '', false);
57 $this->languageServiceMock = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, array('__none'));
58 }
59
60 /**
61 * @test
62 * @return void
63 */
64 public function updateExtensionListFromTerCallsUpdateExtListIfExtensionListIsEmpty()
65 {
66 /** @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|UpdateFromTerController $controllerMock */
67 $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, array('getLanguageService'));
68 $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
69
70 $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, array('getLastUpdate'));
71 $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, array('assign'), array(), '', false);
72 $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, array('hasArgument', 'getArgument'));
73 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
74 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
75 $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
76 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(0));
77 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
78 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
79 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
80 $controllerMock->_set('settings', array('repositoryUid' => 1));
81 $controllerMock->_set('view', $viewMock);
82 $controllerMock->_set('request', $requestMock);
83 $controllerMock->updateExtensionListFromTerAction();
84 }
85
86 /**
87 * @test
88 * @return void
89 */
90 public function updateExtensionListFromTerDoesNotCallsUpdateExtListIfExtensionListIsNotEmpty()
91 {
92 /** @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|UpdateFromTerController $controllerMock */
93 $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, array('getLanguageService'));
94 $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
95
96 $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, array('getLastUpdate'));
97 $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, array('assign'), array(), '', false);
98 $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, array('hasArgument', 'getArgument'));
99 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
100 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
101 $this->repositoryHelperMock->expects($this->never())->method('updateExtList');
102 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
103 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
104 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
105 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
106 $controllerMock->_set('settings', array('repositoryUid' => 1));
107 $controllerMock->_set('view', $viewMock);
108 $controllerMock->_set('request', $requestMock);
109 $controllerMock->updateExtensionListFromTerAction();
110 }
111
112 /**
113 * @test
114 * @return void
115 */
116 public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet()
117 {
118 /** @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|UpdateFromTerController $controllerMock */
119 $controllerMock = $this->getAccessibleMock(UpdateFromTerController::class, array('getLanguageService'));
120 $controllerMock->expects($this->any())->method('getLanguageService')->will($this->returnValue($this->languageServiceMock));
121
122 $repositoryModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Repository::class, array('getLastUpdate'));
123 $viewMock = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, array('assign'), array(), '', false);
124 $requestMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Request::class, array('hasArgument', 'getArgument'));
125 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
126 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
127 $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
128 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
129 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
130 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
131 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
132 $controllerMock->_set('settings', array('repositoryUid' => 1));
133 $controllerMock->_set('view', $viewMock);
134 $controllerMock->_set('request', $requestMock);
135 $controllerMock->updateExtensionListFromTerAction(true);
136 }
137 }