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

Use proper casing
This commit is contained in:
Lukas Reschke 2016-08-15 21:50:43 +02:00 committed by GitHub
commit 63fb17a44f
8 changed files with 92 additions and 114 deletions

View File

@ -233,6 +233,19 @@ 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
@ -240,14 +253,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

@ -57,14 +57,14 @@ class LoginControllerTest extends TestCase {
public function setUp() {
parent::setUp();
$this->request = $this->createMock('\\OCP\\IRequest');
$this->userManager = $this->createMock('\\OCP\\IUserManager');
$this->config = $this->createMock('\\OCP\\IConfig');
$this->session = $this->createMock('\\OCP\\ISession');
$this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock();
$this->userManager = $this->getMockBuilder('\\OCP\\IUserManager')->getMock();
$this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock();
$this->session = $this->getMockBuilder('\\OCP\\ISession')->getMock();
$this->userSession = $this->getMockBuilder('\\OC\\User\\Session')
->disableOriginalConstructor()
->getMock();
$this->urlGenerator = $this->createMock('\\OCP\\IURLGenerator');
$this->urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->getMock();
$this->twoFactorManager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager')
->disableOriginalConstructor()
->getMock();
@ -110,7 +110,7 @@ class LoginControllerTest extends TestCase {
->method('getCookie')
->with('oc_token')
->willReturn('MyLoginToken');
$user = $this->createMock('\\OCP\\IUser');
$user = $this->getMockBuilder('\\OCP\\IUser')->getMock();
$user
->expects($this->once())
->method('getUID')
@ -181,6 +181,7 @@ class LoginControllerTest extends TestCase {
'alt_login' => [],
'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(),
'rememberLoginState' => 0,
'resetPasswordLink' => null,
],
'guest'
);
@ -217,7 +218,7 @@ class LoginControllerTest extends TestCase {
->method('getSystemValue')
->with('lost_password_link')
->willReturn(false);
$user = $this->createMock('\\OCP\\IUser');
$user = $this->getMockBuilder('\\OCP\\IUser')->getMock();
$user
->expects($this->once())
->method('canChangePassword')
@ -239,6 +240,7 @@ class LoginControllerTest extends TestCase {
'alt_login' => [],
'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(),
'rememberLoginState' => 0,
'resetPasswordLink' => false,
],
'guest'
);
@ -255,7 +257,7 @@ class LoginControllerTest extends TestCase {
->method('getSystemValue')
->with('lost_password_link')
->willReturn(false);
$user = $this->createMock('\\OCP\\IUser');
$user = $this->getMockBuilder('\\OCP\\IUser')->getMock();
$user
->expects($this->once())
->method('canChangePassword')
@ -277,6 +279,7 @@ class LoginControllerTest extends TestCase {
'alt_login' => [],
'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(),
'rememberLoginState' => 0,
'resetPasswordLink' => false,
],
'guest'
);
@ -326,9 +329,9 @@ class LoginControllerTest extends TestCase {
public function testLoginWithValidCredentials() {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$password = 'secret';
$indexPageUrl = 'some url';
$indexPageUrl = \OC_Util::getDefaultPageUrl();
$this->request
->expects($this->exactly(2))
@ -360,10 +363,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));
@ -371,7 +370,7 @@ class LoginControllerTest extends TestCase {
public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('jane'));
@ -406,7 +405,7 @@ class LoginControllerTest extends TestCase {
public function testLoginWithoutPassedCsrfCheckAndLoggedIn() {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('jane'));
@ -446,7 +445,7 @@ class LoginControllerTest extends TestCase {
public function testLoginWithValidCredentialsAndRedirectUrl() {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('jane'));
@ -493,7 +492,7 @@ class LoginControllerTest extends TestCase {
public function testLoginWithTwoFactorEnforced() {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('john'));
@ -544,7 +543,7 @@ class LoginControllerTest extends TestCase {
public function testToNotLeakLoginName() {
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('john'));

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

@ -29,31 +29,19 @@ use OCP\AppFramework\Http\RedirectResponse;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
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 */
@ -68,6 +56,8 @@ class CheckSetupControllerTest extends TestCase {
private $util;
/** @var IL10N */
private $l10n;
/** @var ILogger */
private $logger;
/** @var Checker */
private $checker;
@ -95,6 +85,7 @@ class CheckSetupControllerTest extends TestCase {
}));
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
$this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
->setConstructorArgs([
'settings',
@ -105,8 +96,9 @@ class CheckSetupControllerTest extends TestCase {
$this->util,
$this->l10n,
$this->checker,
$this->logger
])
->setMethods(['getCurlVersion'])->getMock();
->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock();
}
public function testIsInternetConnectionWorkingDisabledViaConfig() {
@ -131,12 +123,8 @@ class CheckSetupControllerTest extends TestCase {
$client = $this->getMockBuilder('\OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
->with('https://www.owncloud.org/', []);
$client->expects($this->at(1))
->method('get')
->with('http://www.owncloud.org/', []);
$client->expects($this->any())
->method('get');
$this->clientService->expects($this->once())
->method('newClient')
@ -151,7 +139,7 @@ class CheckSetupControllerTest extends TestCase {
);
}
public function testIsInternetConnectionHttpsFail() {
public function testIsInternetConnectionFail() {
$this->config->expects($this->once())
->method('getSystemValue')
->with('has_internet_connection', true)
@ -159,12 +147,11 @@ class CheckSetupControllerTest extends TestCase {
$client = $this->getMockBuilder('\OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
$client->expects($this->any())
->method('get')
->with('https://www.owncloud.org/', [])
->will($this->throwException(new \Exception()));
$this->clientService->expects($this->once())
$this->clientService->expects($this->exactly(3))
->method('newClient')
->will($this->returnValue($client));
@ -176,33 +163,6 @@ class CheckSetupControllerTest extends TestCase {
);
}
public function testIsInternetConnectionHttpFail() {
$this->config->expects($this->once())
->method('getSystemValue')
->with('has_internet_connection', true)
->will($this->returnValue(true));
$client = $this->getMockBuilder('\OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
->with('https://www.owncloud.org/', []);
$client->expects($this->at(1))
->method('get')
->with('http://www.owncloud.org/', [])
->will($this->throwException(new \Exception()));
$this->clientService->expects($this->once())
->method('newClient')
->will($this->returnValue($client));
$this->assertFalse(
self::invokePrivate(
$this->checkSetupController,
'isInternetConnectionWorking'
)
);
}
public function testIsMemcacheConfiguredFalse() {
$this->config->expects($this->once())
@ -233,7 +193,10 @@ 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,7 +205,10 @@ 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],
@ -250,8 +216,6 @@ class CheckSetupControllerTest extends TestCase {
);
self::$version_compare = 1;
$this->assertEquals(
['eol' => false, 'version' => PHP_VERSION],
self::invokePrivate($this->checkSetupController, 'isPhpSupported')
@ -318,13 +282,17 @@ class CheckSetupControllerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
->with('https://www.owncloud.org/', []);
->with('http://www.nextcloud.com/', [])
->will($this->throwException(new \Exception()));
$client->expects($this->at(1))
->method('get')
->with('http://www.owncloud.org/', [])
->with('http://www.google.com/', [])
->will($this->throwException(new \Exception()));
$this->clientService->expects($this->once())
$client->expects($this->at(2))
->method('get')
->with('http://www.github.com/', [])
->will($this->throwException(new \Exception()));
$this->clientService->expects($this->exactly(3))
->method('newClient')
->will($this->returnValue($client));
$this->urlGenerator->expects($this->at(0))
@ -335,7 +303,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')
@ -373,7 +344,8 @@ class CheckSetupControllerTest extends TestCase {
$this->urlGenerator,
$this->util,
$this->l10n,
$this->checker
$this->checker,
$this->logger
])
->setMethods(null)->getMock();

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