[TASK] Add unit tests for "outdated" extensions 46/21646/2
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 23 Jun 2013 18:50:20 +0000 (20:50 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 24 Jun 2013 19:03:58 +0000 (21:03 +0200)
Follow up with unit tests for the extended reports.

Change-Id: I097d1241722fdaf57a4a57b6d90f32359e8168f5
Resolves: #49350
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Reviewed-on: https://review.typo3.org/21646
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/extensionmanager/Tests/Unit/Report/ExtensionStatusTest.php

index edc85f8..5131202 100644 (file)
@@ -51,9 +51,9 @@ class ExtensionStatusTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
-       public function getStatusReturnArrayContainsThreeEntries() {
+       public function getStatusReturnArrayContainsFiveEntries() {
                $report = new Report\ExtensionStatus();
-               $this->assertSame(3, count($report->getStatus()));
+               $this->assertSame(5, count($report->getStatus()));
        }
 
        /**
@@ -300,5 +300,151 @@ class ExtensionStatusTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $existingResult = $result->existing;
                $this->assertSame(\TYPO3\CMS\Reports\Status::WARNING, $existingResult->getSeverity());
        }
+
+       /**
+        * @test
+        */
+       public function getSecurityStatusOfExtensionsReturnsOkForLoadedExtensionIfNoOutdatedExtensionIsLoaded() {
+               /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
+               $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
+               $mockTerObject
+                       ->expects($this->any())
+                       ->method('getVersion')
+                       ->will($this->returnValue('1.0.6'));
+               $mockTerObject
+                       ->expects($this->atLeastOnce())
+                       ->method('getReviewState')
+                       ->will($this->returnValue(0));
+               $mockExtensionList = array(
+                       'enetcache' => array(
+                               'installed' => TRUE,
+                               'terObject' => $mockTerObject
+                       ),
+               );
+               /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
+               $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
+               $mockListUtility
+                       ->expects($this->once())
+                       ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
+                       ->will($this->returnValue($mockExtensionList));
+
+               /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'));
+               $mockReport->_set('listUtility', $mockListUtility);
+
+               $result = $mockReport->_call('getSecurityStatusOfExtensions');
+               /** @var $loadedResult \TYPO3\CMS\Reports\Status */
+               $loadedResult = $result->loadedoutdated;
+               $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $loadedResult->getSeverity());
+       }
+
+       /**
+        * @test
+        */
+       public function getSecurityStatusOfExtensionsReturnsErrorForLoadedExtensionIfOutdatedExtensionIsLoaded() {
+               /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
+               $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
+               $mockTerObject
+                       ->expects($this->any())
+                       ->method('getVersion')
+                       ->will($this->returnValue('1.0.6'));
+               $mockTerObject
+                       ->expects($this->atLeastOnce())
+                       ->method('getReviewState')
+                       ->will($this->returnValue(-2));
+               $mockExtensionList = array(
+                       'enetcache' => array(
+                               'installed' => TRUE,
+                               'terObject' => $mockTerObject
+                       ),
+               );
+               /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
+               $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
+               $mockListUtility
+                       ->expects($this->once())
+                       ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
+                       ->will($this->returnValue($mockExtensionList));
+
+               /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'));
+               $mockReport->_set('listUtility', $mockListUtility);
+
+               $result = $mockReport->_call('getSecurityStatusOfExtensions');
+               /** @var $loadedResult \TYPO3\CMS\Reports\Status */
+               $loadedResult = $result->loadedoutdated;
+               $this->assertSame(\TYPO3\CMS\Reports\Status::WARNING, $loadedResult->getSeverity());
+       }
+
+       /**
+        * @test
+        */
+       public function getSecurityStatusOfExtensionsReturnsOkForExistingExtensionIfNoOutdatedExtensionExists() {
+               /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
+               $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
+               $mockTerObject
+                       ->expects($this->any())
+                       ->method('getVersion')
+                       ->will($this->returnValue('1.0.6'));
+               $mockTerObject
+                       ->expects($this->atLeastOnce())
+                       ->method('getReviewState')
+                       ->will($this->returnValue(0));
+               $mockExtensionList = array(
+                       'enetcache' => array(
+                               'terObject' => $mockTerObject
+                       ),
+               );
+               /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
+               $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
+               $mockListUtility
+                       ->expects($this->once())
+                       ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
+                       ->will($this->returnValue($mockExtensionList));
+
+               /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'));
+               $mockReport->_set('listUtility', $mockListUtility);
+
+               $result = $mockReport->_call('getSecurityStatusOfExtensions');
+               /** @var $existingResult \TYPO3\CMS\Reports\Status */
+               $existingResult = $result->existingoutdated;
+               $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $existingResult->getSeverity());
+       }
+
+       /**
+        * @test
+        */
+       public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists() {
+               /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */
+               $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
+               $mockTerObject
+                       ->expects($this->any())
+                       ->method('getVersion')
+                       ->will($this->returnValue('1.0.6'));
+               $mockTerObject
+                       ->expects($this->atLeastOnce())
+                       ->method('getReviewState')
+                       ->will($this->returnValue(-2));
+               $mockExtensionList = array(
+                       'enetcache' => array(
+                               'terObject' => $mockTerObject
+                       ),
+               );
+               /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */
+               $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
+               $mockListUtility
+                       ->expects($this->once())
+                       ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
+                       ->will($this->returnValue($mockExtensionList));
+
+               /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'));
+               $mockReport->_set('listUtility', $mockListUtility);
+
+               $result = $mockReport->_call('getSecurityStatusOfExtensions');
+               /** @var $existingResult \TYPO3\CMS\Reports\Status */
+               $existingResult = $result->existingoutdated;
+               $this->assertSame(\TYPO3\CMS\Reports\Status::WARNING, $existingResult->getSeverity());
+       }
 }
 ?>
\ No newline at end of file