From 859d2bc0ffb0c0c8a473679c1e785366e83b267b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 May 2016 08:53:06 +0200 Subject: Fix namespace of memcache/ and ocs/ --- tests/lib/memcache/FactoryTest.php | 132 ++++++++++++++++++++++++++++ tests/lib/memcache/factory.php | 132 ---------------------------- tests/lib/ocs/PrivatedataTest.php | 172 +++++++++++++++++++++++++++++++++++++ tests/lib/ocs/privatedata.php | 168 ------------------------------------ 4 files changed, 304 insertions(+), 300 deletions(-) create mode 100644 tests/lib/memcache/FactoryTest.php delete mode 100644 tests/lib/memcache/factory.php create mode 100644 tests/lib/ocs/PrivatedataTest.php delete mode 100644 tests/lib/ocs/privatedata.php (limited to 'tests/lib') diff --git a/tests/lib/memcache/FactoryTest.php b/tests/lib/memcache/FactoryTest.php new file mode 100644 index 00000000000..8607ea7de9b --- /dev/null +++ b/tests/lib/memcache/FactoryTest.php @@ -0,0 +1,132 @@ + + * + * @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\Memcache; + +class Test_Factory_Available_Cache1 { + public function __construct($prefix = '') { + } + + public static function isAvailable() { + return true; + } +} + +class Test_Factory_Available_Cache2 { + public function __construct($prefix = '') { + } + + public static function isAvailable() { + return true; + } +} + +class Test_Factory_Unavailable_Cache1 { + public function __construct($prefix = '') { + } + + public static function isAvailable() { + return false; + } +} + +class Test_Factory_Unavailable_Cache2 { + public function __construct($prefix = '') { + } + + public static function isAvailable() { + return false; + } +} + +class FactoryTest extends \Test\TestCase { + const AVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Available_Cache1'; + const AVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Available_Cache2'; + const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1'; + const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2'; + + public function cacheAvailabilityProvider() { + return [ + [ + // local and distributed available + self::AVAILABLE1, self::AVAILABLE2, null, + self::AVAILABLE1, self::AVAILABLE2, \OC\Memcache\Factory::NULL_CACHE + ], + [ + // local and distributed null + null, null, null, + \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE + ], + [ + // local available, distributed null (most common scenario) + self::AVAILABLE1, null, null, + self::AVAILABLE1, self::AVAILABLE1, \OC\Memcache\Factory::NULL_CACHE + ], + [ + // locking cache available + null, null, self::AVAILABLE1, + \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1 + ], + [ + // locking cache unavailable: no exception here in the factory + null, null, self::UNAVAILABLE1, + \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE + ] + ]; + } + + public function cacheUnavailableProvider() { + return [ + [ + // local available, distributed unavailable + self::AVAILABLE1, self::UNAVAILABLE1 + ], + [ + // local unavailable, distributed available + self::UNAVAILABLE1, self::AVAILABLE1 + ], + [ + // local and distributed unavailable + self::UNAVAILABLE1, self::UNAVAILABLE2 + ], + ]; + } + + /** + * @dataProvider cacheAvailabilityProvider + */ + public function testCacheAvailability($localCache, $distributedCache, $lockingCache, + $expectedLocalCache, $expectedDistributedCache, $expectedLockingCache) { + $logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); + $factory = new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache, $lockingCache); + $this->assertTrue(is_a($factory->createLocal(), $expectedLocalCache)); + $this->assertTrue(is_a($factory->createDistributed(), $expectedDistributedCache)); + $this->assertTrue(is_a($factory->createLocking(), $expectedLockingCache)); + } + + /** + * @dataProvider cacheUnavailableProvider + * @expectedException \OC\HintException + */ + public function testCacheNotAvailableException($localCache, $distributedCache) { + $logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); + new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache); + } +} diff --git a/tests/lib/memcache/factory.php b/tests/lib/memcache/factory.php deleted file mode 100644 index 33a27a42113..00000000000 --- a/tests/lib/memcache/factory.php +++ /dev/null @@ -1,132 +0,0 @@ - - * - * @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\Memcache; - -class Test_Factory_Available_Cache1 { - public function __construct($prefix = '') { - } - - public static function isAvailable() { - return true; - } -} - -class Test_Factory_Available_Cache2 { - public function __construct($prefix = '') { - } - - public static function isAvailable() { - return true; - } -} - -class Test_Factory_Unavailable_Cache1 { - public function __construct($prefix = '') { - } - - public static function isAvailable() { - return false; - } -} - -class Test_Factory_Unavailable_Cache2 { - public function __construct($prefix = '') { - } - - public static function isAvailable() { - return false; - } -} - -class Test_Factory extends \Test\TestCase { - const AVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Available_Cache1'; - const AVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Available_Cache2'; - const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1'; - const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2'; - - public function cacheAvailabilityProvider() { - return [ - [ - // local and distributed available - self::AVAILABLE1, self::AVAILABLE2, null, - self::AVAILABLE1, self::AVAILABLE2, \OC\Memcache\Factory::NULL_CACHE - ], - [ - // local and distributed null - null, null, null, - \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE - ], - [ - // local available, distributed null (most common scenario) - self::AVAILABLE1, null, null, - self::AVAILABLE1, self::AVAILABLE1, \OC\Memcache\Factory::NULL_CACHE - ], - [ - // locking cache available - null, null, self::AVAILABLE1, - \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1 - ], - [ - // locking cache unavailable: no exception here in the factory - null, null, self::UNAVAILABLE1, - \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE - ] - ]; - } - - public function cacheUnavailableProvider() { - return [ - [ - // local available, distributed unavailable - self::AVAILABLE1, self::UNAVAILABLE1 - ], - [ - // local unavailable, distributed available - self::UNAVAILABLE1, self::AVAILABLE1 - ], - [ - // local and distributed unavailable - self::UNAVAILABLE1, self::UNAVAILABLE2 - ], - ]; - } - - /** - * @dataProvider cacheAvailabilityProvider - */ - public function testCacheAvailability($localCache, $distributedCache, $lockingCache, - $expectedLocalCache, $expectedDistributedCache, $expectedLockingCache) { - $logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); - $factory = new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache, $lockingCache); - $this->assertTrue(is_a($factory->createLocal(), $expectedLocalCache)); - $this->assertTrue(is_a($factory->createDistributed(), $expectedDistributedCache)); - $this->assertTrue(is_a($factory->createLocking(), $expectedLockingCache)); - } - - /** - * @dataProvider cacheUnavailableProvider - * @expectedException \OC\HintException - */ - public function testCacheNotAvailableException($localCache, $distributedCache) { - $logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); - new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache); - } -} diff --git a/tests/lib/ocs/PrivatedataTest.php b/tests/lib/ocs/PrivatedataTest.php new file mode 100644 index 00000000000..0b3b23b8804 --- /dev/null +++ b/tests/lib/ocs/PrivatedataTest.php @@ -0,0 +1,172 @@ +. + * + */ + +namespace Test\OCS; + +use OC_OCS_Privatedata; + +/** + * Class PrivatedataTest + * + * @group DB + */ +class PrivatedataTest extends \Test\TestCase { + private $appKey; + + protected function setUp() { + parent::setUp(); + \OC::$server->getSession()->set('user_id', 'user1'); + $this->appKey = $this->getUniqueID('app'); + } + + public function testGetEmptyOne() { + $params = array('app' => $this->appKey, 'key' => '123'); + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(0, $result); + } + + public function testGetEmptyAll() { + $params = array('app' => $this->appKey); + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(0, $result); + } + + public function testSetOne() { + $_POST = array('value' => 123456789); + $params = array('app' => $this->appKey, 'key' => 'k-1'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(1, $result); + } + + public function testSetExisting() { + $_POST = array('value' => 123456789); + $params = array('app' => $this->appKey, 'key' => 'k-10'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(1, $result); + $data = $result->getData(); + $data = $data[0]; + $this->assertEquals('123456789', $data['value']); + + $_POST = array('value' => 'updated'); + $params = array('app' => $this->appKey, 'key' => 'k-10'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(1, $result); + $data = $result->getData(); + $data = $data[0]; + $this->assertEquals('updated', $data['value']); + } + + public function testSetSameValue() { + $_POST = array('value' => 123456789); + $params = array('app' => $this->appKey, 'key' => 'k-10'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(1, $result); + $data = $result->getData(); + $data = $data[0]; + $this->assertEquals('123456789', $data['value']); + + // set the same value again + $_POST = array('value' => 123456789); + $params = array('app' => $this->appKey, 'key' => 'k-10'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(1, $result); + $data = $result->getData(); + $data = $data[0]; + $this->assertEquals('123456789', $data['value']); + } + + public function testSetMany() { + $_POST = array('value' => 123456789); + + // set key 'k-1' + $params = array('app' => $this->appKey, 'key' => 'k-1'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + // set key 'k-2' + $params = array('app' => $this->appKey, 'key' => 'k-2'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + // query for all + $params = array('app' => $this->appKey); + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(2, $result); + } + + public function testDelete() { + $_POST = array('value' => 123456789); + + // set key 'k-1' + $params = array('app' => $this->appKey, 'key' => 'k-3'); + $result = OC_OCS_Privatedata::set($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::delete($params); + $this->assertEquals(100, $result->getStatusCode()); + + $result = OC_OCS_Privatedata::get($params); + $this->assertOcsResult(0, $result); + } + + /** + * @dataProvider deleteWithEmptyKeysProvider + */ + public function testDeleteWithEmptyKeys($params) { + $result = OC_OCS_Privatedata::delete($params); + $this->assertEquals(101, $result->getStatusCode()); + } + + public function deleteWithEmptyKeysProvider() { + return array( + array(array()), + array(array('app' => '123')), + array(array('key' => '123')), + ); + } + + /** + * @param \OC_OCS_Result $result + * @param integer $expectedArraySize + */ + public function assertOcsResult($expectedArraySize, $result) { + $this->assertEquals(100, $result->getStatusCode()); + $data = $result->getData(); + $this->assertTrue(is_array($data)); + $this->assertEquals($expectedArraySize, sizeof($data)); + } +} diff --git a/tests/lib/ocs/privatedata.php b/tests/lib/ocs/privatedata.php deleted file mode 100644 index ce153bf07d6..00000000000 --- a/tests/lib/ocs/privatedata.php +++ /dev/null @@ -1,168 +0,0 @@ -. - * - */ - -/** - * Class Test_OC_OCS_Privatedata - * - * @group DB - */ -class Test_OC_OCS_Privatedata extends \Test\TestCase { - private $appKey; - - protected function setUp() { - parent::setUp(); - \OC::$server->getSession()->set('user_id', 'user1'); - $this->appKey = $this->getUniqueID('app'); - } - - public function testGetEmptyOne() { - $params = array('app' => $this->appKey, 'key' => '123'); - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(0, $result); - } - - public function testGetEmptyAll() { - $params = array('app' => $this->appKey); - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(0, $result); - } - - public function testSetOne() { - $_POST = array('value' => 123456789); - $params = array('app' => $this->appKey, 'key' => 'k-1'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(1, $result); - } - - public function testSetExisting() { - $_POST = array('value' => 123456789); - $params = array('app' => $this->appKey, 'key' => 'k-10'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(1, $result); - $data = $result->getData(); - $data = $data[0]; - $this->assertEquals('123456789', $data['value']); - - $_POST = array('value' => 'updated'); - $params = array('app' => $this->appKey, 'key' => 'k-10'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(1, $result); - $data = $result->getData(); - $data = $data[0]; - $this->assertEquals('updated', $data['value']); - } - - public function testSetSameValue() { - $_POST = array('value' => 123456789); - $params = array('app' => $this->appKey, 'key' => 'k-10'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(1, $result); - $data = $result->getData(); - $data = $data[0]; - $this->assertEquals('123456789', $data['value']); - - // set the same value again - $_POST = array('value' => 123456789); - $params = array('app' => $this->appKey, 'key' => 'k-10'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(1, $result); - $data = $result->getData(); - $data = $data[0]; - $this->assertEquals('123456789', $data['value']); - } - - public function testSetMany() { - $_POST = array('value' => 123456789); - - // set key 'k-1' - $params = array('app' => $this->appKey, 'key' => 'k-1'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - // set key 'k-2' - $params = array('app' => $this->appKey, 'key' => 'k-2'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - // query for all - $params = array('app' => $this->appKey); - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(2, $result); - } - - public function testDelete() { - $_POST = array('value' => 123456789); - - // set key 'k-1' - $params = array('app' => $this->appKey, 'key' => 'k-3'); - $result = OC_OCS_Privatedata::set($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::delete($params); - $this->assertEquals(100, $result->getStatusCode()); - - $result = OC_OCS_Privatedata::get($params); - $this->assertOcsResult(0, $result); - } - - /** - * @dataProvider deleteWithEmptyKeysProvider - */ - public function testDeleteWithEmptyKeys($params) { - $result = OC_OCS_Privatedata::delete($params); - $this->assertEquals(101, $result->getStatusCode()); - } - - public function deleteWithEmptyKeysProvider() { - return array( - array(array()), - array(array('app' => '123')), - array(array('key' => '123')), - ); - } - - /** - * @param \OC_OCS_Result $result - * @param integer $expectedArraySize - */ - public function assertOcsResult($expectedArraySize, $result) { - $this->assertEquals(100, $result->getStatusCode()); - $data = $result->getData(); - $this->assertTrue(is_array($data)); - $this->assertEquals($expectedArraySize, sizeof($data)); - } -} -- cgit v1.2.3