diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-10-13 04:29:20 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-10-13 04:29:20 +0200 |
commit | 11e9ce25e622ea3a98c8085717541620fb878a69 (patch) | |
tree | 4cc0563d51768efa01a92a7333f370a4d0ccf3d3 /tests/lib | |
parent | 141ff806c6cfbd349ffa232502a89a620882c409 (diff) | |
parent | d386bc8737374200b4dc8ca0b62e432757ac2f04 (diff) | |
download | nextcloud-server-11e9ce25e622ea3a98c8085717541620fb878a69.tar.gz nextcloud-server-11e9ce25e622ea3a98c8085717541620fb878a69.zip |
merge master into filesystem
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/cache/apc.php | 6 | ||||
-rw-r--r-- | tests/lib/db.php | 70 | ||||
-rw-r--r-- | tests/lib/dbschema.php | 118 | ||||
-rw-r--r-- | tests/lib/share/share.php | 10 |
4 files changed, 199 insertions, 5 deletions
diff --git a/tests/lib/cache/apc.php b/tests/lib/cache/apc.php index 0e0edcf58f3..f68b97bcbd9 100644 --- a/tests/lib/cache/apc.php +++ b/tests/lib/cache/apc.php @@ -22,10 +22,14 @@ class Test_Cache_APC extends Test_Cache { public function setUp() { - if(!function_exists('apc_store')){ + if(!extension_loaded('apc')){ $this->markTestSkipped('The apc extension is not available.'); return; } + if(!ini_get('apc.enable_cli') && OC::$CLI){ + $this->markTestSkipped('apc not available in CLI.'); + return; + } $this->instance=new OC_Cache_APC(); } } diff --git a/tests/lib/db.php b/tests/lib/db.php new file mode 100644 index 00000000000..2344f7d8ec4 --- /dev/null +++ b/tests/lib/db.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_DB extends UnitTestCase { + protected $backupGlobals = FALSE; + + protected static $schema_file = 'static://test_db_scheme'; + protected $test_prefix; + + public function setUp() { + $dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml'; + + $r = '_'.OC_Util::generate_random_bytes('4').'_'; + $content = file_get_contents( $dbfile ); + $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); + file_put_contents( self::$schema_file, $content ); + OC_DB::createDbFromStructure(self::$schema_file); + + $this->test_prefix = $r; + $this->table1 = $this->test_prefix.'contacts_addressbooks'; + $this->table2 = $this->test_prefix.'contacts_cards'; + } + + public function tearDown() { + OC_DB::removeDBStructure(self::$schema_file); + unlink(self::$schema_file); + } + + public function testQuotes() { + $query = OC_DB::prepare('SELECT `fullname` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $result = $query->execute(array('uri_1')); + $this->assertTrue($result); + $row = $result->fetchRow(); + $this->assertFalse($row); + $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (?,?)'); + $result = $query->execute(array('fullname test', 'uri_1')); + $this->assertTrue($result); + $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $result = $query->execute(array('uri_1')); + $this->assertTrue($result); + $row = $result->fetchRow(); + $this->assertArrayHasKey('fullname', $row); + $this->assertEqual($row['fullname'], 'fullname test'); + $row = $result->fetchRow(); + $this->assertFalse($row); + } + + public function testNOW() { + $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (NOW(),?)'); + $result = $query->execute(array('uri_2')); + $this->assertTrue($result); + $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $result = $query->execute(array('uri_2')); + $this->assertTrue($result); + } + + public function testUNIX_TIMESTAMP() { + $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (UNIX_TIMESTAMP(),?)'); + $result = $query->execute(array('uri_3')); + $this->assertTrue($result); + $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $result = $query->execute(array('uri_3')); + $this->assertTrue($result); + } +} diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php new file mode 100644 index 00000000000..cd408160afb --- /dev/null +++ b/tests/lib/dbschema.php @@ -0,0 +1,118 @@ +<?php +/** + * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_DBSchema extends UnitTestCase { + protected static $schema_file = 'static://test_db_scheme'; + protected static $schema_file2 = 'static://test_db_scheme2'; + protected $test_prefix; + protected $table1; + protected $table2; + + public function setUp() { + $dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml'; + $dbfile2 = OC::$SERVERROOT.'/tests/data/db_structure2.xml'; + + $r = '_'.OC_Util::generate_random_bytes('4').'_'; + $content = file_get_contents( $dbfile ); + $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); + file_put_contents( self::$schema_file, $content ); + $content = file_get_contents( $dbfile2 ); + $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); + file_put_contents( self::$schema_file2, $content ); + + $this->test_prefix = $r; + $this->table1 = $this->test_prefix.'contacts_addressbooks'; + $this->table2 = $this->test_prefix.'contacts_cards'; + } + + public function tearDown() { + unlink(self::$schema_file); + unlink(self::$schema_file2); + } + + // everything in one test, they depend on each other + public function testSchema() { + $this->doTestSchemaCreating(); + $this->doTestSchemaChanging(); + $this->doTestSchemaDumping(); + $this->doTestSchemaRemoving(); + } + + public function doTestSchemaCreating() { + OC_DB::createDbFromStructure(self::$schema_file); + $this->assertTableExist($this->table1); + $this->assertTableExist($this->table2); + } + + public function doTestSchemaChanging() { + OC_DB::updateDbFromStructure(self::$schema_file2); + $this->assertTableExist($this->table2); + } + + public function doTestSchemaDumping() { + $outfile = 'static://db_out.xml'; + OC_DB::getDbStructure($outfile); + $content = file_get_contents($outfile); + $this->assertContains($this->table1, $content); + $this->assertContains($this->table2, $content); + } + + public function doTestSchemaRemoving() { + OC_DB::removeDBStructure(self::$schema_file); + $this->assertTableNotExist($this->table1); + $this->assertTableNotExist($this->table2); + } + + public function tableExist($table) { + $table = '*PREFIX*' . $table; + + switch (OC_Config::getValue( 'dbtype', 'sqlite' )) { + case 'sqlite': + case 'sqlite3': + $sql = "SELECT name FROM sqlite_master " + . "WHERE type = 'table' AND name != 'sqlite_sequence' " + . "AND name != 'geometry_columns' AND name != 'spatial_ref_sys' " + . "UNION ALL SELECT name FROM sqlite_temp_master " + . "WHERE type = 'table' AND name = '".$table."'"; + $query = OC_DB::prepare($sql); + $result = $query->execute(array()); + $exists = $result && $result->fetchOne(); + break; + case 'mysql': + $sql = 'SHOW TABLES LIKE "'.$table.'"'; + $query = OC_DB::prepare($sql); + $result = $query->execute(array()); + $exists = $result && $result->fetchOne(); + break; + case 'pgsql': + $sql = "SELECT tablename AS table_name, schemaname AS schema_name " + . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " + . "AND schemaname != 'information_schema' " + . "AND tablename = '".$table."'"; + $query = OC_DB::prepare($sql); + $result = $query->execute(array()); + $exists = $result && $result->fetchOne(); + break; + } + return $exists; + } + + public function assertTableExist($table) { + $this->assertTrue($this->tableExist($table)); + } + + public function assertTableNotExist($table) { + $type=OC_Config::getValue( "dbtype", "sqlite" ); + if( $type == 'sqlite' || $type == 'sqlite3' ) { + // sqlite removes the tables after closing the DB + } + else { + $this->assertFalse($this->tableExist($table)); + } + } +} diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 48d0270cc57..7f6784f8df7 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -61,11 +61,13 @@ class Test_Share extends UnitTestCase { $query->execute(array('test')); } - /** - * @expectedException Exception - */ public function testShareInvalidShareType() { - OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); + $message = 'Share type foobar is not valid for test.txt'; + try { + OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } } public function testInvalidItemType() { |