From db34a8c861d731884041c9161badbc447279338e Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:00:35 +0200 Subject: [PATCH 1/8] Use proper casing --- tests/phpunit-autotest.xml | 5 ++--- tests/phpunit.xml.dist | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml index 07de887c8c..301f63a375 100644 --- a/tests/phpunit-autotest.xml +++ b/tests/phpunit-autotest.xml @@ -8,9 +8,8 @@ > lib/ - settings/ - core/ - ocs-provider/ + Settings/ + Core/ apps.php diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist index 19fa38209a..d3a5897dfa 100644 --- a/tests/phpunit.xml.dist +++ b/tests/phpunit.xml.dist @@ -2,9 +2,8 @@ lib/ - settings/ - core/ - ocs-provider/ + Settings/ + Core/ apps.php From 18388a01f54c66c8e2bc5574f321a1ff7a5e0abd Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:15:14 +0200 Subject: [PATCH 2/8] Add reference to current user --- tests/Settings/Controller/AuthSettingsControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Settings/Controller/AuthSettingsControllerTest.php b/tests/Settings/Controller/AuthSettingsControllerTest.php index 1705cb5ddf..b57aea0930 100644 --- a/tests/Settings/Controller/AuthSettingsControllerTest.php +++ b/tests/Settings/Controller/AuthSettingsControllerTest.php @@ -91,6 +91,7 @@ class AuthSettingsControllerTest extends TestCase { 'lastActivity' => null, 'type' => null, 'canDelete' => false, + 'current' => true, ], [ 'id' => 200, From 349f5e4a607b70997c0276c2ce28658de5643e04 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:19:50 +0200 Subject: [PATCH 3/8] Fix template test --- tests/Core/Templates/TemplatesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/Templates/TemplatesTest.php b/tests/Core/Templates/TemplatesTest.php index 03565411a1..cd1502fd22 100644 --- a/tests/Core/Templates/TemplatesTest.php +++ b/tests/Core/Templates/TemplatesTest.php @@ -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 = ""; + $expectedHtml = ""; $this->assertTemplate($expectedHtml, $template); } From ab9a8ce952c28750e990bccae65217bd84e5eb87 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:19:32 +0200 Subject: [PATCH 4/8] Fix tests for LoginController --- tests/Core/Controller/LoginControllerTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index f09f3c9811..86bf4d8fdf 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -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 = 'http://localhost/index.php/apps/files/'; $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)); From 81467f7c4e1b658c29860aa818d6420eb7e3360d Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:55:36 +0200 Subject: [PATCH 5/8] Fix CheckSetupController tests --- settings/Controller/CheckSetupController.php | 21 ++++++----- .../Controller/CheckSetupControllerTest.php | 35 ++++++++----------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index 4d9ad47651..48c0783f17 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -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]; } /** diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index f48e9c04f3..b2c8498409 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -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') From 5e9c7d3ff38df8a7f562c1904f35cbe315b17247 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:37:55 +0200 Subject: [PATCH 6/8] Use generated URL --- tests/Core/Controller/LoginControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 86bf4d8fdf..0439b5b7de 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -327,7 +327,7 @@ class LoginControllerTest extends TestCase { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->getMock('\OCP\IUser'); $password = 'secret'; - $indexPageUrl = 'http://localhost/index.php/apps/files/'; + $indexPageUrl = \OC_Util::getDefaultPageUrl(); $this->request ->expects($this->exactly(2)) From b860fa71257a1cb5cf5c586d546497796e34c610 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 15 Aug 2016 20:07:07 +0200 Subject: [PATCH 7/8] Fix mock call in AvatarControllerTest --- .../Core/Controller/AvatarControllerTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 937d8aaf17..4a7b7f2178 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -32,7 +32,7 @@ use Punic\Exception; use Test\Traits\UserTrait; /** - * Overwrite is_uploaded_file in this namespace to allow proper unit testing of + * Overwrite is_uploaded_file in this namespace to allow proper unit testing of * the postAvatar call. */ function is_uploaded_file($filename) { @@ -68,19 +68,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 +91,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 +326,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') From a8ba573ba97e469ef6add19c1312de2e0a9200b7 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 15 Aug 2016 20:08:20 +0200 Subject: [PATCH 8/8] We have to mock the is_uploaded_file in the OC\Core\Controller namespace --- tests/Core/Controller/AvatarControllerTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 4a7b7f2178..d45d061823 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -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 *