Merge pull request #884 from nextcloud/stable10-use-proper-test-execution

[stable10] Use proper casing
This commit is contained in:
Lukas Reschke 2016-08-15 21:50:38 +02:00 committed by GitHub
commit 716adb8462
8 changed files with 58 additions and 60 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

@ -19,6 +19,16 @@
*
*/
namespace OC\Core\Controller;
/**
* Overwrite is_uploaded_file in the OC\Core\Controller namespace to allow
* proper unit testing of the postAvatar call.
*/
function is_uploaded_file($filename) {
return file_exists($filename);
}
namespace Tests\Core\Controller;
use OC\Core\Application;
@ -31,14 +41,6 @@ use OCP\IAvatar;
use Punic\Exception;
use Test\Traits\UserTrait;
/**
* Overwrite is_uploaded_file in this namespace to allow proper unit testing of
* the postAvatar call.
*/
function is_uploaded_file($filename) {
return file_exists($filename);
}
/**
* Class AvatarControllerTest
*
@ -68,19 +70,19 @@ class AvatarControllerTest extends \Test\TestCase {
$app = new Application;
$this->container = $app->getContainer();
$this->container['AppName'] = 'core';
$this->container['AvatarManager'] = $this->getMock('OCP\IAvatarManager');
$this->container['AvatarManager'] = $this->getMockBuilder('OCP\IAvatarManager')->getMock();
$this->container['Cache'] = $this->getMockBuilder('OC\Cache\File')
->disableOriginalConstructor()->getMock();
$this->container['L10N'] = $this->getMock('OCP\IL10N');
$this->container['L10N'] = $this->getMockBuilder('OCP\IL10N')->getMock();
$this->container['L10N']->method('t')->will($this->returnArgument(0));
$this->container['UserManager'] = $this->getMock('OCP\IUserManager');
$this->container['UserSession'] = $this->getMock('OCP\IUserSession');
$this->container['Request'] = $this->getMock('OCP\IRequest');
$this->container['UserFolder'] = $this->getMock('OCP\Files\Folder');
$this->container['Logger'] = $this->getMock('OCP\ILogger');
$this->container['UserManager'] = $this->getMockBuilder('OCP\IUserManager')->getMock();
$this->container['UserSession'] = $this->getMockBuilder('OCP\IUserSession')->getMock();
$this->container['Request'] = $this->getMockBuilder('OCP\IRequest')->getMock();
$this->container['UserFolder'] = $this->getMockBuilder('OCP\Files\Folder')->getMock();
$this->container['Logger'] = $this->getMockBuilder('OCP\ILogger')->getMock();
$this->avatarMock = $this->getMock('OCP\IAvatar');
$this->userMock = $this->getMock('OCP\IUser');
$this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock();
$this->userMock = $this->getMockBuilder('OCP\IUser')->getMock();
$this->avatarController = $this->container['AvatarController'];
@ -91,7 +93,7 @@ class AvatarControllerTest extends \Test\TestCase {
->willReturnMap([['userId', $this->userMock]]);
$this->container['UserSession']->method('getUser')->willReturn($this->userMock);
$this->avatarFile = $this->getMock('OCP\Files\File');
$this->avatarFile = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->avatarFile->method('getContent')->willReturn('image data');
$this->avatarFile->method('getMimeType')->willReturn('image type');
$this->avatarFile->method('getEtag')->willReturn('my etag');
@ -326,7 +328,7 @@ class AvatarControllerTest extends \Test\TestCase {
* Test posting avatar from existing folder
*/
public function testPostAvatarFromNoFile() {
$file = $this->getMock('OCP\Files\Node');
$file = $this->getMockBuilder('OCP\Files\Node')->getMock();
$this->container['UserFolder']
->method('get')
->with('folder')

View File

@ -181,6 +181,7 @@ class LoginControllerTest extends TestCase {
'alt_login' => [],
'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(),
'rememberLoginState' => 0,
'resetPasswordLink' => null,
],
'guest'
);
@ -239,6 +240,7 @@ class LoginControllerTest extends TestCase {
'alt_login' => [],
'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(),
'rememberLoginState' => 0,
'resetPasswordLink' => false,
],
'guest'
);
@ -277,6 +279,7 @@ class LoginControllerTest extends TestCase {
'alt_login' => [],
'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(),
'rememberLoginState' => 0,
'resetPasswordLink' => false,
],
'guest'
);
@ -324,7 +327,7 @@ class LoginControllerTest extends TestCase {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->getMock('\OCP\IUser');
$password = 'secret';
$indexPageUrl = 'some url';
$indexPageUrl = \OC_Util::getDefaultPageUrl();
$this->request
->expects($this->exactly(2))
@ -352,10 +355,6 @@ class LoginControllerTest extends TestCase {
->method('isTwoFactorAuthenticated')
->with($user)
->will($this->returnValue(false));
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('files.view.index')
->will($this->returnValue($indexPageUrl));
$expected = new \OCP\AppFramework\Http\RedirectResponse($indexPageUrl);
$this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null));

View File

@ -13,7 +13,7 @@ class TemplatesTest extends \Test\TestCase {
public function test404() {
$template = \OC::$SERVERROOT . '/core/templates/404.php';
$href = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
$expectedHtml = "<ul><li class='error'>\n\t\t\tFile not found<br><p class='hint'>The specified document has not been found on the server.</p>\n<p class='hint'><a href='$href'>You can click here to return to ownCloud.</a></p>\n\t\t</li></ul>";
$expectedHtml = "<ul><li class='error'>\n\t\t\tFile not found<br><p class='hint'>The specified document has not been found on the server.</p>\n<p class='hint'><a href='$href'>You can click here to return to Nextcloud.</a></p>\n\t\t</li></ul>";
$this->assertTemplate($expectedHtml, $template);
}

View File

@ -91,6 +91,7 @@ class AuthSettingsControllerTest extends TestCase {
'lastActivity' => null,
'type' => null,
'canDelete' => false,
'current' => true,
],
[
'id' => 200,

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')

View File

@ -8,9 +8,8 @@
>
<testsuite name='ownCloud'>
<directory suffix='.php'>lib/</directory>
<directory suffix='.php'>settings/</directory>
<directory suffix='.php'>core/</directory>
<directory suffix='.php'>ocs-provider/</directory>
<directory suffix='.php'>Settings/</directory>
<directory suffix='.php'>Core/</directory>
<file>apps.php</file>
</testsuite>
<!-- filters for code coverage -->

View File

@ -2,9 +2,8 @@
<phpunit bootstrap="bootstrap.php">
<testsuite name='ownCloud'>
<directory suffix='.php'>lib/</directory>
<directory suffix='.php'>settings/</directory>
<directory suffix='.php'>core/</directory>
<directory suffix='.php'>ocs-provider/</directory>
<directory suffix='.php'>Settings/</directory>
<directory suffix='.php'>Core/</directory>
<file>apps.php</file>
</testsuite>
<!-- filters for code coverage -->