From 7f3f16d1554bd2adbe3287fbf09a1124664f54af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 May 2016 09:17:54 +0200 Subject: Fix namespace in user/ --- tests/lib/updater/VersionCheckTest.php | 261 +++++++++++++++++++++++++++++++++ tests/lib/updater/versioncheck.php | 261 --------------------------------- tests/lib/user/avataruserdummy.php | 6 +- tests/lib/user/backend.php | 4 +- tests/lib/user/database.php | 4 +- tests/lib/user/dummy.php | 4 +- 6 files changed, 274 insertions(+), 266 deletions(-) create mode 100644 tests/lib/updater/VersionCheckTest.php delete mode 100644 tests/lib/updater/versioncheck.php diff --git a/tests/lib/updater/VersionCheckTest.php b/tests/lib/updater/VersionCheckTest.php new file mode 100644 index 00000000000..13851338eef --- /dev/null +++ b/tests/lib/updater/VersionCheckTest.php @@ -0,0 +1,261 @@ + + * @author Victor Dubiniuk + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace Test\Update; + +use OC\Updater\VersionCheck; +use OCP\IConfig; +use OCP\Util; + +class VersionCheckTest extends \Test\TestCase { + /** @var IConfig| \PHPUnit_Framework_MockObject_MockObject */ + private $config; + /** @var VersionCheck | \PHPUnit_Framework_MockObject_MockObject*/ + private $updater; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService') + ->disableOriginalConstructor() + ->getMock(); + + $this->updater = $this->getMock('\OC\Updater\VersionCheck', + ['getUrlContent'], [$clientService, $this->config]); + } + + /** + * @param string $baseUrl + * @return string + */ + private function buildUpdateUrl($baseUrl) { + return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatxlastupdatedatx'.\OC_Util::getChannel().'x'.\OC_Util::getEditionString().'x'; + } + + public function testCheckInCache() { + $expectedResult = [ + 'version' => '8.0.4.2', + 'versionstring' => 'ownCloud 8.0.4', + 'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip', + 'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html', + ]; + + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue(time())); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('core', 'lastupdateResult') + ->will($this->returnValue(json_encode($expectedResult))); + + $this->assertSame($expectedResult, $this->updater->check()); + } + + public function testCheckWithoutUpdateUrl() { + $expectedResult = [ + 'version' => '8.0.4.2', + 'versionstring' => 'ownCloud 8.0.4', + 'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip', + 'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html', + ]; + + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue(0)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('core', 'lastupdatedat', $this->isType('integer')); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'installedat') + ->will($this->returnValue('installedat')); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue('lastupdatedat')); + $this->config + ->expects($this->at(6)) + ->method('setAppValue') + ->with('core', 'lastupdateResult', json_encode($expectedResult)); + + $updateXml = ' + + 8.0.4.2 + ownCloud 8.0.4 + https://download.owncloud.org/community/owncloud-8.0.4.zip + http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html +'; + $this->updater + ->expects($this->once()) + ->method('getUrlContent') + ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) + ->will($this->returnValue($updateXml)); + + $this->assertSame($expectedResult, $this->updater->check()); + } + + public function testCheckWithInvalidXml() { + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue(0)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('core', 'lastupdatedat', $this->isType('integer')); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'installedat') + ->will($this->returnValue('installedat')); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue('lastupdatedat')); + $this->config + ->expects($this->at(6)) + ->method('setAppValue') + ->with('core', 'lastupdateResult', 'false'); + + $updateXml = 'Invalid XML Response!'; + $this->updater + ->expects($this->once()) + ->method('getUrlContent') + ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) + ->will($this->returnValue($updateXml)); + + $this->assertSame([], $this->updater->check()); + } + + public function testCheckWithEmptyValidXmlResponse() { + $expectedResult = [ + 'version' => '', + 'versionstring' => '', + 'url' => '', + 'web' => '', + ]; + + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue(0)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('core', 'lastupdatedat', $this->isType('integer')); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'installedat') + ->will($this->returnValue('installedat')); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue('lastupdatedat')); + + $updateXml = ' + + + + + +'; + $this->updater + ->expects($this->once()) + ->method('getUrlContent') + ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) + ->will($this->returnValue($updateXml)); + + $this->assertSame($expectedResult, $this->updater->check()); + } + + public function testCheckWithEmptyInvalidXmlResponse() { + $expectedResult = []; + + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue(0)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.owncloud.com/server/') + ->willReturn('https://updates.owncloud.com/server/'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('core', 'lastupdatedat', $this->isType('integer')); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'installedat') + ->will($this->returnValue('installedat')); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue('lastupdatedat')); + $this->config + ->expects($this->at(6)) + ->method('setAppValue') + ->with('core', 'lastupdateResult', json_encode($expectedResult)); + + $updateXml = ''; + $this->updater + ->expects($this->once()) + ->method('getUrlContent') + ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) + ->will($this->returnValue($updateXml)); + + $this->assertSame($expectedResult, $this->updater->check()); + } +} diff --git a/tests/lib/updater/versioncheck.php b/tests/lib/updater/versioncheck.php deleted file mode 100644 index 2122ca28800..00000000000 --- a/tests/lib/updater/versioncheck.php +++ /dev/null @@ -1,261 +0,0 @@ - - * @author Victor Dubiniuk - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OC; - -use OC\Updater\VersionCheck; -use OCP\IConfig; -use OCP\Util; - -class VersionCheckTest extends \Test\TestCase { - /** @var IConfig| \PHPUnit_Framework_MockObject_MockObject */ - private $config; - /** @var VersionCheck | \PHPUnit_Framework_MockObject_MockObject*/ - private $updater; - - public function setUp() { - parent::setUp(); - $this->config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService') - ->disableOriginalConstructor() - ->getMock(); - - $this->updater = $this->getMock('\OC\Updater\VersionCheck', - ['getUrlContent'], [$clientService, $this->config]); - } - - /** - * @param string $baseUrl - * @return string - */ - private function buildUpdateUrl($baseUrl) { - return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatxlastupdatedatx'.\OC_Util::getChannel().'x'.\OC_Util::getEditionString().'x'; - } - - public function testCheckInCache() { - $expectedResult = [ - 'version' => '8.0.4.2', - 'versionstring' => 'ownCloud 8.0.4', - 'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip', - 'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html', - ]; - - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue(time())); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('core', 'lastupdateResult') - ->will($this->returnValue(json_encode($expectedResult))); - - $this->assertSame($expectedResult, $this->updater->check()); - } - - public function testCheckWithoutUpdateUrl() { - $expectedResult = [ - 'version' => '8.0.4.2', - 'versionstring' => 'ownCloud 8.0.4', - 'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip', - 'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html', - ]; - - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue(0)); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.owncloud.com/server/') - ->willReturn('https://updates.owncloud.com/server/'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('core', 'lastupdatedat', $this->isType('integer')); - $this->config - ->expects($this->at(4)) - ->method('getAppValue') - ->with('core', 'installedat') - ->will($this->returnValue('installedat')); - $this->config - ->expects($this->at(5)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue('lastupdatedat')); - $this->config - ->expects($this->at(6)) - ->method('setAppValue') - ->with('core', 'lastupdateResult', json_encode($expectedResult)); - - $updateXml = ' - - 8.0.4.2 - ownCloud 8.0.4 - https://download.owncloud.org/community/owncloud-8.0.4.zip - http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html -'; - $this->updater - ->expects($this->once()) - ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) - ->will($this->returnValue($updateXml)); - - $this->assertSame($expectedResult, $this->updater->check()); - } - - public function testCheckWithInvalidXml() { - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue(0)); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.owncloud.com/server/') - ->willReturn('https://updates.owncloud.com/server/'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('core', 'lastupdatedat', $this->isType('integer')); - $this->config - ->expects($this->at(4)) - ->method('getAppValue') - ->with('core', 'installedat') - ->will($this->returnValue('installedat')); - $this->config - ->expects($this->at(5)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue('lastupdatedat')); - $this->config - ->expects($this->at(6)) - ->method('setAppValue') - ->with('core', 'lastupdateResult', 'false'); - - $updateXml = 'Invalid XML Response!'; - $this->updater - ->expects($this->once()) - ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) - ->will($this->returnValue($updateXml)); - - $this->assertSame([], $this->updater->check()); - } - - public function testCheckWithEmptyValidXmlResponse() { - $expectedResult = [ - 'version' => '', - 'versionstring' => '', - 'url' => '', - 'web' => '', - ]; - - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue(0)); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.owncloud.com/server/') - ->willReturn('https://updates.owncloud.com/server/'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('core', 'lastupdatedat', $this->isType('integer')); - $this->config - ->expects($this->at(4)) - ->method('getAppValue') - ->with('core', 'installedat') - ->will($this->returnValue('installedat')); - $this->config - ->expects($this->at(5)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue('lastupdatedat')); - - $updateXml = ' - - - - - -'; - $this->updater - ->expects($this->once()) - ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) - ->will($this->returnValue($updateXml)); - - $this->assertSame($expectedResult, $this->updater->check()); - } - - public function testCheckWithEmptyInvalidXmlResponse() { - $expectedResult = []; - - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue(0)); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.owncloud.com/server/') - ->willReturn('https://updates.owncloud.com/server/'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('core', 'lastupdatedat', $this->isType('integer')); - $this->config - ->expects($this->at(4)) - ->method('getAppValue') - ->with('core', 'installedat') - ->will($this->returnValue('installedat')); - $this->config - ->expects($this->at(5)) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->will($this->returnValue('lastupdatedat')); - $this->config - ->expects($this->at(6)) - ->method('setAppValue') - ->with('core', 'lastupdateResult', json_encode($expectedResult)); - - $updateXml = ''; - $this->updater - ->expects($this->once()) - ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) - ->will($this->returnValue($updateXml)); - - $this->assertSame($expectedResult, $this->updater->check()); - } -} diff --git a/tests/lib/user/avataruserdummy.php b/tests/lib/user/avataruserdummy.php index 086adb6043f..123825de50f 100644 --- a/tests/lib/user/avataruserdummy.php +++ b/tests/lib/user/avataruserdummy.php @@ -20,8 +20,10 @@ * */ -class Avatar_User_Dummy extends \Test\Util\User\Dummy { +namespace Test\User; + +class AvatarUserDummy extends \Test\Util\User\Dummy { public function canChangeAvatar($uid) { return true; } -} \ No newline at end of file +} diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php index d5bbbe9f406..85ccbac913c 100644 --- a/tests/lib/user/backend.php +++ b/tests/lib/user/backend.php @@ -20,6 +20,8 @@ * */ +namespace Test\User; + /** * Abstract class to provide the basis of backend-specific unit test classes. * @@ -30,7 +32,7 @@ * For an example see /tests/lib/user/dummy.php */ -abstract class Test_User_Backend extends \Test\TestCase { +abstract class Backend extends \Test\TestCase { /** * @var \OC\User\Backend $backend */ diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php index 0dea037ad78..76d6226a7fd 100644 --- a/tests/lib/user/database.php +++ b/tests/lib/user/database.php @@ -20,12 +20,14 @@ * */ +namespace Test\User; + /** * Class Test_User_Database * * @group DB */ -class Test_User_Database extends Test_User_Backend { +class Database extends Backend { /** @var array */ private $users; diff --git a/tests/lib/user/dummy.php b/tests/lib/user/dummy.php index c6c79d7a860..50382aa8fe6 100644 --- a/tests/lib/user/dummy.php +++ b/tests/lib/user/dummy.php @@ -20,7 +20,9 @@ * */ -class Test_User_Dummy extends Test_User_Backend { +namespace Test\User; + +class Dummy extends Backend { protected function setUp() { parent::setUp(); $this->backend=new \Test\Util\User\Dummy(); -- cgit v1.2.3