[BUGFIX] Do not fetch extension list on every request
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Controller / UpdateFromTerControllerTest.php
index 898d044..e06ac77 100644 (file)
@@ -80,9 +80,14 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                        ->method('assign')
                        ->will($this->returnValue($viewMock));
 
+               $lastUpdateDate = new DateTime();
+                       // Wed Jul 25 18:40:02 CEST 2012
+               $lastUpdateDate->setTimestamp(1343234402);
                $repositoryModelMock->expects($this->once())
                        ->method('getLastUpdate')
-                       ->will($this->returnValue(1343234402));
+                       ->will($this->returnValue($lastUpdateDate));
+
+
 
                $repositoryRepositoryMock
                        ->expects($this->once())
@@ -92,7 +97,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
 
                $repositoryHelperMock->expects($this->once())
                        ->method('updateExtList');
-
+                       // Sat Jul 28 18:40:02 CEST 2012
                $GLOBALS['EXEC_TIME'] = 1343493602;
 
                $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
@@ -107,7 +112,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
         * @test
         * @return void
         */
-       public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
+       public function updateExtensionListFromTerDoesNotCallUpdateExtListIfLastUpdateIsLessThan24HoursAgo() {
                $controllerMock = $this->getAccessibleMock(
                        'Tx_Extensionmanager_Controller_UpdateFromTerController',
                        array('dummy')
@@ -134,21 +139,74 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                        array('hasArgument', 'getArgument')
                );
 
-               $requestMock->expects($this->once())
-                       ->method('hasArgument')
-                       ->will($this->returnValue(TRUE));
+               $viewMock->expects($this->any())
+                       ->method('assign')
+                       ->will($this->returnValue($viewMock));
+
+               $lastUpdateDate = new DateTime();
+                       // Wed Jul 25 18:40:02 CEST 2012
+               $lastUpdateDate->setTimestamp(1343493602);
+               $repositoryModelMock->expects($this->once())
+                       ->method('getLastUpdate')
+                       ->will($this->returnValue($lastUpdateDate));
+
+
+
+               $repositoryRepositoryMock
+                       ->expects($this->once())
+                       ->method('findOneByUid')
+                       ->with(1)
+                       ->will($this->returnValue($repositoryModelMock));
+
+               $repositoryHelperMock->expects($this->never())
+                       ->method('updateExtList');
+                       // Sat Jul 28 18:40:02 CEST 2012
+               $GLOBALS['EXEC_TIME'] = 1343493602;
 
-               $requestMock->expects($this->once())
-                       ->method('getArgument')
-                       ->will($this->returnValue(TRUE));
+               $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
+               $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
+               $controllerMock->_set('settings', array('repositoryUid' => 1));
+               $controllerMock->_set('view', $viewMock);
+               $controllerMock->_set('request', $requestMock);
+               $controllerMock->updateExtensionListFromTerAction();
+       }
+
+       /**
+        * @test
+        * @return void
+        */
+       public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
+               $controllerMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Controller_UpdateFromTerController',
+                       array('dummy')
+               );
+               $repositoryRepositoryMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Domain_Repository_RepositoryRepository',
+                       array('findOneByUid')
+               );
+               $repositoryModelMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Domain_Model_Repository',
+                       array('getLastUpdate')
+               );
+               $repositoryHelperMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Utility_Repository_Helper',
+                       array('updateExtList')
+               );
+               $viewMock = $this->getAccessibleMock(
+                       'Tx_Fluid_View_TemplateView',
+                       array('assign')
+               );
 
                $viewMock->expects($this->any())
                        ->method('assign')
                        ->will($this->returnValue($viewMock));
 
+               $lastUpdateDate = new DateTime();
+                       // Wed Jul 25 18:40:02 CEST 2012
+               $lastUpdateDate->setTimestamp(1343234402);
                $repositoryModelMock->expects($this->once())
                        ->method('getLastUpdate')
-                       ->will($this->returnValue(1343493602));
+                       ->will($this->returnValue($lastUpdateDate));
 
                $repositoryRepositoryMock
                        ->expects($this->once())
@@ -159,6 +217,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                $repositoryHelperMock->expects($this->once())
                        ->method('updateExtList');
 
+                       // Sat Jul 28 18:40:02 CEST 2012
                $GLOBALS['EXEC_TIME'] = 1343493602;
 
                $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
@@ -166,7 +225,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                $controllerMock->_set('settings', array('repositoryUid' => 1));
                $controllerMock->_set('view', $viewMock);
                $controllerMock->_set('request', $requestMock);
-               $controllerMock->updateExtensionListFromTerAction();
+               $controllerMock->updateExtensionListFromTerAction(TRUE);
        }
 }
 ?>
\ No newline at end of file