From ec9a4e63d07f3630e3c159851d75382d0e598a72 Mon Sep 17 00:00:00 2001 From: Jigal van Hemert <jigal.van.hemert@typo3.org> Date: Sun, 23 Jun 2013 20:50:20 +0200 Subject: [PATCH] [TASK] Add unit tests for "outdated" extensions 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 --- .../Tests/Unit/Report/ExtensionStatusTest.php | 150 +++++++++++++++++- 1 file changed, 148 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Report/ExtensionStatusTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Report/ExtensionStatusTest.php index edc85f8820b8..513120237df1 100644 --- a/typo3/sysext/extensionmanager/Tests/Unit/Report/ExtensionStatusTest.php +++ b/typo3/sysext/extensionmanager/Tests/Unit/Report/ExtensionStatusTest.php @@ -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 -- GitLab