0d82cfa5a589d5399ea3212a546f052d0f361ca1
[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 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Update from TER controller test
29 *
30 */
31 class UpdateFromTerControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
35 */
36 protected $mockObjectManager;
37
38 /**
39 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
40 */
41 protected $repositoryRepositoryMock;
42
43 /**
44 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
45 */
46 protected $extensionRepositoryMock;
47
48 /**
49 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
50 */
51 protected $repositoryHelperMock;
52
53 public function setUp() {
54 $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
55 $this->repositoryRepositoryMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository', array('findByUid'), array($this->mockObjectManager));
56 $this->extensionRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array(), array($this->mockObjectManager));
57 $this->repositoryHelperMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper', array('updateExtList'), array(), '', FALSE);
58 }
59
60 /**
61 * @test
62 * @return void
63 */
64 public function updateExtensionListFromTerCallsUpdateExtListIfExtensionListIsEmpty() {
65 $controllerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UpdateFromTerController', array('dummy'));
66 $repositoryModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository', array('getLastUpdate'));
67
68 $viewMock = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('assign'), array(), '', FALSE);
69 $requestMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('hasArgument', 'getArgument'));
70 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
71 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
72 $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
73 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(0));
74 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
75 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
76 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
77 $controllerMock->_set('settings', array('repositoryUid' => 1));
78 $controllerMock->_set('view', $viewMock);
79 $controllerMock->_set('request', $requestMock);
80 $controllerMock->updateExtensionListFromTerAction();
81 }
82
83 /**
84 * @test
85 * @return void
86 */
87 public function updateExtensionListFromTerDoesNotCallsUpdateExtListIfExtensionListIsNotEmpty() {
88 $controllerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UpdateFromTerController', array('dummy'));
89 $repositoryModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository', array('getLastUpdate'));
90 $viewMock = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('assign'), array(), '', FALSE);
91 $requestMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('hasArgument', 'getArgument'));
92 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
93 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
94 $this->repositoryHelperMock->expects($this->never())->method('updateExtList');
95 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
96 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
97 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
98 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
99 $controllerMock->_set('settings', array('repositoryUid' => 1));
100 $controllerMock->_set('view', $viewMock);
101 $controllerMock->_set('request', $requestMock);
102 $controllerMock->updateExtensionListFromTerAction();
103 }
104
105 /**
106 * @test
107 * @return void
108 */
109 public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
110 $controllerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UpdateFromTerController', array('dummy'));
111 $repositoryModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository', array('getLastUpdate'));
112 $viewMock = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('assign'), array(), '', FALSE);
113 $requestMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('hasArgument', 'getArgument'));
114 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
115 $this->repositoryRepositoryMock->expects($this->once())->method('findByUid')->with(1)->will($this->returnValue($repositoryModelMock));
116 $this->repositoryHelperMock->expects($this->once())->method('updateExtList');
117 $this->extensionRepositoryMock->expects($this->once())->method('countAll')->will($this->returnValue(100));
118 $controllerMock->_set('extensionRepository', $this->extensionRepositoryMock);
119 $controllerMock->_set('repositoryRepository', $this->repositoryRepositoryMock);
120 $controllerMock->_set('repositoryHelper', $this->repositoryHelperMock);
121 $controllerMock->_set('settings', array('repositoryUid' => 1));
122 $controllerMock->_set('view', $viewMock);
123 $controllerMock->_set('request', $requestMock);
124 $controllerMock->updateExtensionListFromTerAction(TRUE);
125 }
126 }