diff options
author | kondou <kondou@ts.unde.re> | 2013-08-28 16:44:11 +0200 |
---|---|---|
committer | kondou <kondou@ts.unde.re> | 2013-08-28 16:44:11 +0200 |
commit | 67c5be9f199c08ac4c9307901e8e6cc678943f05 (patch) | |
tree | 061575d844745b3ad43b9aac518b386228966ad3 /tests | |
parent | 8d8a57de7fb41030ffb69f098419616f4003119a (diff) | |
parent | 0c02e1efef76430eea8986697cd9736814fb604a (diff) | |
download | nextcloud-server-67c5be9f199c08ac4c9307901e8e6cc678943f05.tar.gz nextcloud-server-67c5be9f199c08ac4c9307901e8e6cc678943f05.zip |
Merge branch 'master' into oc_avatars
Conflicts:
3rdparty
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/appconfig.php | 132 | ||||
-rw-r--r-- | tests/lib/connector/sabre/quotaplugin.php | 101 | ||||
-rw-r--r-- | tests/lib/group/group.php | 10 |
3 files changed, 238 insertions, 5 deletions
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php new file mode 100644 index 00000000000..4d82cd5ba7b --- /dev/null +++ b/tests/lib/appconfig.php @@ -0,0 +1,132 @@ +<?php +/** + * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_Appconfig extends PHPUnit_Framework_TestCase { + public static function setUpBeforeClass() { + $query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)'); + + $query->execute(array('testapp', 'enabled', 'true')); + $query->execute(array('testapp', 'installed_version', '1.2.3')); + $query->execute(array('testapp', 'depends_on', 'someapp')); + $query->execute(array('testapp', 'deletethis', 'deletethis')); + $query->execute(array('testapp', 'key', 'value')); + + $query->execute(array('someapp', 'key', 'value')); + $query->execute(array('someapp', 'otherkey', 'othervalue')); + + $query->execute(array('123456', 'key', 'value')); + $query->execute(array('123456', 'enabled', 'false')); + + $query->execute(array('anotherapp', 'key', 'value')); + $query->execute(array('anotherapp', 'enabled', 'false')); + } + + public static function tearDownAfterClass() { + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?'); + $query->execute(array('testapp')); + $query->execute(array('someapp')); + $query->execute(array('123456')); + $query->execute(array('anotherapp')); + } + + public function testGetApps() { + $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`'); + $result = $query->execute(); + $expected = array(); + while ($row = $result->fetchRow()) { + $expected[] = $row['appid']; + } + $apps = \OC_Appconfig::getApps(); + $this->assertEquals($expected, $apps); + } + + public function testGetKeys() { + $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'); + $result = $query->execute(array('testapp')); + $expected = array(); + while($row = $result->fetchRow()) { + $expected[] = $row["configkey"]; + } + $keys = \OC_Appconfig::getKeys('testapp'); + $this->assertEquals($expected, $keys); + } + + public function testGetValue() { + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('testapp', 'installed_version')); + $expected = $result->fetchRow(); + $value = \OC_Appconfig::getValue('testapp', 'installed_version'); + $this->assertEquals($expected['configvalue'], $value); + + $value = \OC_Appconfig::getValue('testapp', 'nonexistant'); + $this->assertNull($value); + + $value = \OC_Appconfig::getValue('testapp', 'nonexistant', 'default'); + $this->assertEquals('default', $value); + } + + public function testHasKey() { + $value = \OC_Appconfig::hasKey('testapp', 'installed_version'); + $this->assertTrue($value); + + $value = \OC_Appconfig::hasKey('nonexistant', 'nonexistant'); + $this->assertFalse($value); + } + + public function testSetValue() { + \OC_Appconfig::setValue('testapp', 'installed_version', '1.33.7'); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('testapp', 'installed_version')); + $value = $result->fetchRow(); + $this->assertEquals('1.33.7', $value['configvalue']); + + \OC_Appconfig::setValue('someapp', 'somekey', 'somevalue'); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('someapp', 'somekey')); + $value = $result->fetchRow(); + $this->assertEquals('somevalue', $value['configvalue']); + } + + public function testDeleteKey() { + \OC_Appconfig::deleteKey('testapp', 'deletethis'); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); + $query->execute(array('testapp', 'deletethis')); + $result = (bool)$query->fetchRow(); + $this->assertFalse($result); + } + + public function testDeleteApp() { + \OC_Appconfig::deleteApp('someapp'); + $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'); + $query->execute(array('someapp')); + $result = (bool)$query->fetchRow(); + $this->assertFalse($result); + } + + public function testGetValues() { + $this->assertFalse(\OC_Appconfig::getValues('testapp', 'enabled')); + + $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?'); + $query->execute(array('testapp')); + $expected = array(); + while ($row = $query->fetchRow()) { + $expected[$row['configkey']] = $row['configvalue']; + } + $values = \OC_Appconfig::getValues('testapp', false); + $this->assertEquals($expected, $values); + + $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?'); + $query->execute(array('enabled')); + $expected = array(); + while ($row = $query->fetchRow()) { + $expected[$row['appid']] = $row['configvalue']; + } + $values = \OC_Appconfig::getValues(false, 'enabled'); + $this->assertEquals($expected, $values); + } +} diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php new file mode 100644 index 00000000000..1186de28742 --- /dev/null +++ b/tests/lib/connector/sabre/quotaplugin.php @@ -0,0 +1,101 @@ +<?php +/** + * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { + + /** + * @var Sabre_DAV_Server + */ + private $server; + + /** + * @var OC_Connector_Sabre_QuotaPlugin + */ + private $plugin; + + public function setUp() { + $this->server = new Sabre_DAV_Server(); + $this->plugin = new OC_Connector_Sabre_QuotaPlugin(); + $this->plugin->initialize($this->server); + } + + /** + * @dataProvider lengthProvider + */ + public function testLength($expected, $headers) + { + $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $length = $this->plugin->getLength(); + $this->assertEquals($expected, $length); + } + + /** + * @dataProvider quotaOkayProvider + */ + public function testCheckQuota($quota, $headers) + { + $this->plugin->fileView = $this->buildFileViewMock($quota); + + $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $result = $this->plugin->checkQuota(''); + $this->assertTrue($result); + } + + /** + * @expectedException Sabre_DAV_Exception_InsufficientStorage + * @dataProvider quotaExceededProvider + */ + public function testCheckExceededQuota($quota, $headers) + { + $this->plugin->fileView = $this->buildFileViewMock($quota); + + $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->plugin->checkQuota(''); + } + + public function quotaOkayProvider() { + return array( + array(1024, array()), + array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array(1024, array('HTTP_CONTENT_LENGTH' => '512')), + array(1024, array('HTTP_OC_TOTAL_LENGTH' => '1024', 'HTTP_CONTENT_LENGTH' => '512')), + // OC\Files\FREE_SPACE_UNKNOWN = -2 + array(-2, array()), + array(-2, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array(-2, array('HTTP_CONTENT_LENGTH' => '512')), + array(-2, array('HTTP_OC_TOTAL_LENGTH' => '1024', 'HTTP_CONTENT_LENGTH' => '512')), + ); + } + + public function quotaExceededProvider() { + return array( + array(1023, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array(511, array('HTTP_CONTENT_LENGTH' => '512')), + array(2047, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')), + ); + } + + public function lengthProvider() { + return array( + array(null, array()), + array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array(512, array('HTTP_CONTENT_LENGTH' => '512')), + array(2048, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')), + array(4096, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '4096')), + ); + } + + private function buildFileViewMock($quota) { + // mock filesysten + $view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', FALSE); + $view->expects($this->any())->method('free_space')->withAnyParameters()->will($this->returnValue($quota)); + + return $view; + } + +} diff --git a/tests/lib/group/group.php b/tests/lib/group/group.php index 75e975d9e65..f1fda3b9288 100644 --- a/tests/lib/group/group.php +++ b/tests/lib/group/group.php @@ -43,8 +43,8 @@ class Group extends \PHPUnit_Framework_TestCase { $users = $group->getUsers(); $this->assertEquals(2, count($users)); - $user1 = $users[0]; - $user2 = $users[1]; + $user1 = $users['user1']; + $user2 = $users['user2']; $this->assertEquals('user1', $user1->getUID()); $this->assertEquals('user2', $user2->getUID()); } @@ -68,9 +68,9 @@ class Group extends \PHPUnit_Framework_TestCase { $users = $group->getUsers(); $this->assertEquals(3, count($users)); - $user1 = $users[0]; - $user2 = $users[1]; - $user3 = $users[2]; + $user1 = $users['user1']; + $user2 = $users['user2']; + $user3 = $users['user3']; $this->assertEquals('user1', $user1->getUID()); $this->assertEquals('user2', $user2->getUID()); $this->assertEquals('user3', $user3->getUID()); |