eacd4d10957f3d2805a08ca49b156b5a63e087ba
[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 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 * @package Extension Manager
29 * @subpackage Tests
30 */
31 class UpdateFromTerControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
32
33 /**
34 * Enable backup of global and system variables
35 *
36 * @var boolean
37 */
38 protected $backupGlobals = TRUE;
39
40 /**
41 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
42 * because resource types cannot be handled during serializing
43 *
44 * @var array
45 */
46 protected $backupGlobalsBlacklist = array('TYPO3_DB');
47
48 /**
49 * @test
50 * @return void
51 */
52 public function updateExtensionListFromTerCallsUpdateExtListIfLastUpdateIsMoreThan24HoursAgo() {
53 $controllerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UpdateFromTerController', array('dummy'));
54 $repositoryRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository', array('findOneByUid'));
55 $repositoryModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository', array('getLastUpdate'));
56 $repositoryHelperMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper', array('updateExtList'));
57 $viewMock = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('assign'));
58 $requestMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('hasArgument', 'getArgument'));
59 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
60 $lastUpdateDate = new \DateTime();
61 // Wed Jul 25 18:40:02 CEST 2012
62 $lastUpdateDate->setTimestamp(1343234402);
63 $repositoryModelMock->expects($this->once())->method('getLastUpdate')->will($this->returnValue($lastUpdateDate));
64 $repositoryRepositoryMock->expects($this->once())->method('findOneByUid')->with(1)->will($this->returnValue($repositoryModelMock));
65 $repositoryHelperMock->expects($this->once())->method('updateExtList');
66 // Sat Jul 28 18:40:02 CEST 2012
67 $GLOBALS['EXEC_TIME'] = 1343493602;
68 $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
69 $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
70 $controllerMock->_set('settings', array('repositoryUid' => 1));
71 $controllerMock->_set('view', $viewMock);
72 $controllerMock->_set('request', $requestMock);
73 $controllerMock->updateExtensionListFromTerAction();
74 }
75
76 /**
77 * @test
78 * @return void
79 */
80 public function updateExtensionListFromTerDoesNotCallUpdateExtListIfLastUpdateIsLessThan24HoursAgo() {
81 $controllerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UpdateFromTerController', array('dummy'));
82 $repositoryRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository', array('findOneByUid'));
83 $repositoryModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository', array('getLastUpdate'));
84 $repositoryHelperMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper', array('updateExtList'));
85 $viewMock = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('assign'));
86 $requestMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('hasArgument', 'getArgument'));
87 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
88 $lastUpdateDate = new \DateTime();
89 // Wed Jul 25 18:40:02 CEST 2012
90 $lastUpdateDate->setTimestamp(1343493602);
91 $repositoryModelMock->expects($this->once())->method('getLastUpdate')->will($this->returnValue($lastUpdateDate));
92 $repositoryRepositoryMock->expects($this->once())->method('findOneByUid')->with(1)->will($this->returnValue($repositoryModelMock));
93 $repositoryHelperMock->expects($this->never())->method('updateExtList');
94 // Sat Jul 28 18:40:02 CEST 2012
95 $GLOBALS['EXEC_TIME'] = 1343493602;
96 $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
97 $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
98 $controllerMock->_set('settings', array('repositoryUid' => 1));
99 $controllerMock->_set('view', $viewMock);
100 $controllerMock->_set('request', $requestMock);
101 $controllerMock->updateExtensionListFromTerAction();
102 }
103
104 /**
105 * @test
106 * @return void
107 */
108 public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
109 $controllerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UpdateFromTerController', array('dummy'));
110 $repositoryRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository', array('findOneByUid'));
111 $repositoryModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Repository', array('getLastUpdate'));
112 $repositoryHelperMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper', array('updateExtList'));
113 $viewMock = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('assign'));
114 $viewMock->expects($this->any())->method('assign')->will($this->returnValue($viewMock));
115 $lastUpdateDate = new \DateTime();
116 // Wed Jul 25 18:40:02 CEST 2012
117 $lastUpdateDate->setTimestamp(1343234402);
118 $repositoryModelMock->expects($this->once())->method('getLastUpdate')->will($this->returnValue($lastUpdateDate));
119 $repositoryRepositoryMock->expects($this->once())->method('findOneByUid')->with(1)->will($this->returnValue($repositoryModelMock));
120 $repositoryHelperMock->expects($this->once())->method('updateExtList');
121 // Sat Jul 28 18:40:02 CEST 2012
122 $GLOBALS['EXEC_TIME'] = 1343493602;
123 $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
124 $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
125 $controllerMock->_set('settings', array('repositoryUid' => 1));
126 $controllerMock->_set('view', $viewMock);
127 $controllerMock->_set('request', $requestMock);
128 $controllerMock->updateExtensionListFromTerAction(TRUE);
129 }
130
131 }
132
133
134 ?>