Fix CheckSetupController tests

This commit is contained in:
Lukas Reschke 2016-08-15 17:55:36 +02:00
parent ab9a8ce952
commit 81467f7c4e
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
2 changed files with 27 additions and 29 deletions

View File

@ -206,6 +206,18 @@ class CheckSetupController extends Controller {
return '';
}
/**
* Whether the version is outdated
*
* @return bool
*/
protected function isPhpOutdated() {
if (version_compare(PHP_VERSION, '5.5.0') === -1) {
return true;
}
return false;
}
/**
* Whether the php version is still supported (at time of release)
* according to: https://secure.php.net/supported-versions.php
@ -213,14 +225,7 @@ class CheckSetupController extends Controller {
* @return array
*/
private function isPhpSupported() {
$eol = false;
//PHP 5.4 is EOL on 14 Sep 2015
if (version_compare(PHP_VERSION, '5.5.0') === -1) {
$eol = true;
}
return ['eol' => $eol, 'version' => PHP_VERSION];
return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
}
/**

View File

@ -35,25 +35,12 @@ use OC_Util;
use Test\TestCase;
use OC\IntegrityCheck\Checker;
/**
* Mock version_compare
* @param string $version1
* @param string $version2
* @return int
*/
function version_compare($version1, $version2) {
return CheckSetupControllerTest::$version_compare;
}
/**
* Class CheckSetupControllerTest
*
* @package Tests\Settings\Controller
*/
class CheckSetupControllerTest extends TestCase {
/** @var int */
public static $version_compare;
/** @var CheckSetupController */
private $checkSetupController;
/** @var IRequest */
@ -106,7 +93,7 @@ class CheckSetupControllerTest extends TestCase {
$this->l10n,
$this->checker,
])
->setMethods(['getCurlVersion'])->getMock();
->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock();
}
public function testIsInternetConnectionWorkingDisabledViaConfig() {
@ -233,7 +220,11 @@ class CheckSetupControllerTest extends TestCase {
}
public function testIsPhpSupportedFalse() {
self::$version_compare = -1;
$this->checkSetupController
->expects($this->once())
->method('isPhpOutdated')
->willReturn(true);
$this->assertEquals(
['eol' => true, 'version' => PHP_VERSION],
@ -242,16 +233,15 @@ class CheckSetupControllerTest extends TestCase {
}
public function testIsPhpSupportedTrue() {
self::$version_compare = 0;
$this->checkSetupController
->expects($this->exactly(2))
->method('isPhpOutdated')
->willReturn(false);
$this->assertEquals(
['eol' => false, 'version' => PHP_VERSION],
self::invokePrivate($this->checkSetupController, 'isPhpSupported')
);
self::$version_compare = 1;
$this->assertEquals(
['eol' => false, 'version' => PHP_VERSION],
self::invokePrivate($this->checkSetupController, 'isPhpSupported')
@ -335,7 +325,10 @@ class CheckSetupControllerTest extends TestCase {
->method('linkToDocs')
->with('admin-security')
->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html');
self::$version_compare = -1;
$this->checkSetupController
->expects($this->once())
->method('isPhpOutdated')
->willReturn(true);
$this->urlGenerator->expects($this->at(2))
->method('linkToDocs')
->with('admin-reverse-proxy')