From ba9db1964053be769b42452fee65ac4720489f81 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 7 May 2013 19:42:46 +0200 Subject: Add wrapper storage backend --- tests/lib/files/storage/wrapper.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/lib/files/storage/wrapper.php (limited to 'tests') diff --git a/tests/lib/files/storage/wrapper.php b/tests/lib/files/storage/wrapper.php new file mode 100644 index 00000000000..8452949a723 --- /dev/null +++ b/tests/lib/files/storage/wrapper.php @@ -0,0 +1,26 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Storage; + +class Wrapper extends Storage { + /** + * @var string tmpDir + */ + private $tmpDir; + + public function setUp() { + $this->tmpDir = \OC_Helper::tmpFolder(); + $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); + $this->instance = new \OC\Files\Storage\Wrapper(array('storage' => $storage)); + } + + public function tearDown() { + \OC_Helper::rmdirr($this->tmpDir); + } +} -- cgit v1.2.3 From 31693d393749c94591dc0814cc502eac8d415e11 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 7 Jun 2013 17:40:38 +0200 Subject: add test cases for Mount --- tests/lib/files/mount/mount.php | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/lib/files/mount/mount.php (limited to 'tests') diff --git a/tests/lib/files/mount/mount.php b/tests/lib/files/mount/mount.php new file mode 100644 index 00000000000..aa98db856f4 --- /dev/null +++ b/tests/lib/files/mount/mount.php @@ -0,0 +1,46 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Mount; + + +use OC\Files\Storage\Loader; +use OC\Files\Storage\Wrapper; + +class Mount extends \PHPUnit_Framework_TestCase { + public function testFromStorageObject() { + $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') + ->disableOriginalConstructor() + ->getMock(); + $mount = new \OC\Files\Mount\Mount($storage, '/foo'); + $this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage()); + } + + public function testFromStorageClassname() { + $mount = new \OC\Files\Mount\Mount('\OC\Files\Storage\Temporary', '/foo'); + $this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage()); + } + + public function testWrapper() { + $test = $this; + $wrapper = function ($mountPoint, $storage) use (&$test) { + $test->assertEquals('/foo/', $mountPoint); + $test->assertInstanceOf('\OC\Files\Storage\Storage', $storage); + return new Wrapper(array('storage' => $storage)); + }; + + $loader = new Loader(); + $loader->addStorageWrapper($wrapper); + + $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') + ->disableOriginalConstructor() + ->getMock(); + $mount = new \OC\Files\Mount\Mount($storage, '/foo', array(), $loader); + $this->assertInstanceOf('\OC\Files\Storage\Wrapper', $mount->getStorage()); + } +} -- cgit v1.2.3 From 63c898c064233d08823e1b18ec7cb20185b1fe05 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 6 Jun 2013 20:47:20 +0200 Subject: Make rmdir recursive for local storage --- lib/files/storage/local.php | 22 +++++++++++++++++++++- tests/lib/files/storage/storage.php | 14 +++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/lib/files/storage/local.php b/lib/files/storage/local.php index d684905bf9a..b08fd73ce19 100644 --- a/lib/files/storage/local.php +++ b/lib/files/storage/local.php @@ -39,7 +39,27 @@ if (\OC_Util::runningOnWindows()) { } public function rmdir($path) { - return @rmdir($this->datadir . $path); + try { + $it = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($this->datadir . $path), + \RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($it as $file) { + /** + * @var \SplFileInfo $file + */ + if (in_array($file->getBasename(), array('.', '..'))) { + continue; + } elseif ($file->isDir()) { + rmdir($file->getPathname()); + } elseif ($file->isFile() || $file->isLink()) { + unlink($file->getPathname()); + } + } + return rmdir($this->datadir . $path); + } catch (\UnexpectedValueException $e) { + return false; + } } public function opendir($path) { diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 0e22f26ae83..fb3e05e66b3 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -258,9 +258,21 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals(file_get_contents($textFile), $content); } - public function testTouchCreateFile(){ + public function testTouchCreateFile() { $this->assertFalse($this->instance->file_exists('foo')); $this->instance->touch('foo'); $this->assertTrue($this->instance->file_exists('foo')); } + + public function testRecursiveRmdir() { + $this->instance->mkdir('folder'); + $this->instance->mkdir('folder/bar'); + $this->instance->file_put_contents('folder/asd.txt', 'foobar'); + $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); + $this->instance->rmdir('folder'); + $this->assertFalse($this->instance->file_exists('folder/asd.txt')); + $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); + $this->assertFalse($this->instance->file_exists('folder/bar')); + $this->assertFalse($this->instance->file_exists('folder')); + } } -- cgit v1.2.3 From 1b97c186b4f2946753123fb73314597b818aea70 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 20 Jun 2013 15:38:02 +0200 Subject: use assertEquals number of rows in db tests --- tests/lib/db.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/lib/db.php b/tests/lib/db.php index afbdb413c3d..0ba7d5d4b06 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -40,7 +40,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(array('fullname test', 'uri_1')); - $this->assertTrue((bool)$result); + $this->assertEquals('1', $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); @@ -57,7 +57,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { public function testNOW() { $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (NOW(),?)'); $result = $query->execute(array('uri_2')); - $this->assertTrue((bool)$result); + $this->assertEquals('1', $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_2')); $this->assertTrue((bool)$result); @@ -66,7 +66,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { 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((bool)$result); + $this->assertEquals('1', $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_3')); $this->assertTrue((bool)$result); @@ -105,7 +105,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { // Normal test to have same known data inserted. $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)'); $result = $query->execute(array($fullname, $uri, $carddata)); - $this->assertTrue((bool)$result); + $this->assertEquals('1', $result); $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array($uri)); $this->assertTrue((bool)$result); -- cgit v1.2.3 From 592bb01ccde6e4fbbf9e306aa0bafddabf3b8b67 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 25 Jun 2013 21:57:00 +0200 Subject: phpunit: Remove PHPUnit_Util_Log_JSON which spammed to stdout on console. --- tests/phpunit.xml | 3 --- 1 file changed, 3 deletions(-) (limited to 'tests') diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 510c38a3c8b..25dfc64cfeb 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -15,7 +15,4 @@ - - - -- cgit v1.2.3 From 121e4ca395f05b6dff8903650a71a95cd4a3a229 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 27 Jun 2013 16:31:31 +0200 Subject: PHPUnit: Allow developers to use their own custom phpunit.xml file. The order of precedence of configuration files for PHPUnit is: - phpunit.xml (allowing custom user defined configuration) - phpunit.xml.dist (configuration distributed with the software) --- tests/phpunit.xml | 18 ------------------ tests/phpunit.xml.dist | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 tests/phpunit.xml create mode 100644 tests/phpunit.xml.dist (limited to 'tests') diff --git a/tests/phpunit.xml b/tests/phpunit.xml deleted file mode 100644 index 25dfc64cfeb..00000000000 --- a/tests/phpunit.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - lib/ - apps.php - - - - - - .. - - ../3rdparty - ../lib/MDB2 - - - - diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist new file mode 100644 index 00000000000..25dfc64cfeb --- /dev/null +++ b/tests/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + + lib/ + apps.php + + + + + + .. + + ../3rdparty + ../lib/MDB2 + + + + -- cgit v1.2.3 From 7f3ddd43411c9b5b1b26d42751a6dbe416ab5499 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 24 Jun 2013 22:38:05 +0200 Subject: Skip Test_Archive_TAR in php 5.5 for now --- tests/lib/archive/tar.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/lib/archive/tar.php b/tests/lib/archive/tar.php index e66a8740879..d831487b16f 100644 --- a/tests/lib/archive/tar.php +++ b/tests/lib/archive/tar.php @@ -10,6 +10,12 @@ require_once 'archive.php'; if (!OC_Util::runningOnWindows()) { class Test_Archive_TAR extends Test_Archive { + public function setUp() { + if (floatval(phpversion())>=5.5) { + $this->markTestSkipped('php 5.5 changed unpack function.'); + return; + } + } protected function getExisting() { $dir = OC::$SERVERROOT . '/tests/data'; return new OC_Archive_TAR($dir . '/data.tar.gz'); -- cgit v1.2.3 From 42cb77b9821eb032afce7e1b7f233c9ffcd0be41 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 28 Jun 2013 13:24:24 +0200 Subject: TimedJob: make PhpUnit happy with asserts --- tests/lib/backgroundjob/timedjob.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/lib/backgroundjob/timedjob.php b/tests/lib/backgroundjob/timedjob.php index 0af933afef8..f3c3eb4d0dd 100644 --- a/tests/lib/backgroundjob/timedjob.php +++ b/tests/lib/backgroundjob/timedjob.php @@ -41,6 +41,7 @@ class TimedJob extends \PHPUnit_Framework_TestCase { $this->fail("job should have run"); } catch (JobRun $e) { } + $this->assertTrue(true); } public function testShouldNotRunWithinInterval() { @@ -50,6 +51,7 @@ class TimedJob extends \PHPUnit_Framework_TestCase { } catch (JobRun $e) { $this->fail("job should not have run"); } + $this->assertTrue(true); } public function testShouldNotTwice() { @@ -64,5 +66,6 @@ class TimedJob extends \PHPUnit_Framework_TestCase { $this->fail("job should not have run the second time"); } } + $this->assertTrue(true); } } -- cgit v1.2.3 From 3abeb252d8b8777bce5ae2ec33d1234a77558b98 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 28 Jun 2013 14:37:52 +0200 Subject: make PHPUnit happy and add asserts --- tests/lib/session/session.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/lib/session/session.php b/tests/lib/session/session.php index 72dee44e7cb..9ce11274c84 100644 --- a/tests/lib/session/session.php +++ b/tests/lib/session/session.php @@ -44,7 +44,9 @@ abstract class Session extends \PHPUnit_Framework_TestCase { } public function testRemoveNonExisting() { + $this->assertFalse($this->instance->exists('foo')); $this->instance->remove('foo'); + $this->assertFalse($this->instance->exists('foo')); } public function testNotExistsAfterClear() { -- cgit v1.2.3 From de66861ef1a440837cc6161eaea21fd3e401570f Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 28 Jun 2013 15:13:57 +0200 Subject: make phpunit happy - adding asserts --- tests/lib/hooks/basicemitter.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/lib/hooks/basicemitter.php b/tests/lib/hooks/basicemitter.php index f48dc53c563..0eae730d030 100644 --- a/tests/lib/hooks/basicemitter.php +++ b/tests/lib/hooks/basicemitter.php @@ -155,6 +155,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener); $this->emitter->removeListener('Test', 'test', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } public function testRemoveWildcardListener() { @@ -168,6 +170,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener2); $this->emitter->removeListener('Test', 'test'); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } public function testRemoveWildcardMethod() { @@ -179,6 +183,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->removeListener('Test', null, $listener); $this->emitter->emitEvent('Test', 'test'); $this->emitter->emitEvent('Test', 'foo'); + + $this->assertTrue(true); } public function testRemoveWildcardScope() { @@ -190,6 +196,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->removeListener(null, 'test', $listener); $this->emitter->emitEvent('Test', 'test'); $this->emitter->emitEvent('Bar', 'test'); + + $this->assertTrue(true); } public function testRemoveWildcardScopeAndMethod() { @@ -203,6 +211,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->emitEvent('Test', 'test'); $this->emitter->emitEvent('Test', 'foo'); $this->emitter->emitEvent('Bar', 'foo'); + + $this->assertTrue(true); } /** @@ -219,6 +229,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener2); $this->emitter->removeListener('Test', 'test', $listener1); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } /** @@ -232,6 +244,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'foo', $listener); $this->emitter->removeListener('Test', 'foo', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } /** @@ -245,6 +259,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Bar', 'test', $listener); $this->emitter->removeListener('Bar', 'test', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } /** @@ -257,5 +273,7 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener); $this->emitter->removeListener('Bar', 'test', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } } -- cgit v1.2.3 From a7c70915d592cd3cc06c6dc86ba3d2707d000871 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 28 Jun 2013 18:18:12 +0200 Subject: fix storage wrapper namespaces --- lib/files/storage/wrapper/wrapper.php | 2 +- tests/lib/files/mount/mount.php | 4 ++-- tests/lib/files/storage/wrapper.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/lib/files/storage/wrapper/wrapper.php b/lib/files/storage/wrapper/wrapper.php index 802c8ea0492..4feb0520f12 100644 --- a/lib/files/storage/wrapper/wrapper.php +++ b/lib/files/storage/wrapper/wrapper.php @@ -8,7 +8,7 @@ namespace OC\Files\Storage\Wrapper; -class Wrapper implements Storage { +class Wrapper implements \OC\Files\Storage\Storage { /** * @var \OC\Files\Storage\Storage $storage */ diff --git a/tests/lib/files/mount/mount.php b/tests/lib/files/mount/mount.php index aa98db856f4..b057204ad35 100644 --- a/tests/lib/files/mount/mount.php +++ b/tests/lib/files/mount/mount.php @@ -10,7 +10,7 @@ namespace Test\Files\Mount; use OC\Files\Storage\Loader; -use OC\Files\Storage\Wrapper; +use OC\Files\Storage\Wrapper\Wrapper; class Mount extends \PHPUnit_Framework_TestCase { public function testFromStorageObject() { @@ -41,6 +41,6 @@ class Mount extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $mount = new \OC\Files\Mount\Mount($storage, '/foo', array(), $loader); - $this->assertInstanceOf('\OC\Files\Storage\Wrapper', $mount->getStorage()); + $this->assertInstanceOf('\OC\Files\Storage\Wrapper\Wrapper', $mount->getStorage()); } } diff --git a/tests/lib/files/storage/wrapper.php b/tests/lib/files/storage/wrapper.php index 8452949a723..2794a0a6263 100644 --- a/tests/lib/files/storage/wrapper.php +++ b/tests/lib/files/storage/wrapper.php @@ -17,7 +17,7 @@ class Wrapper extends Storage { public function setUp() { $this->tmpDir = \OC_Helper::tmpFolder(); $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); - $this->instance = new \OC\Files\Storage\Wrapper(array('storage' => $storage)); + $this->instance = new \OC\Files\Storage\Wrapper\Wrapper(array('storage' => $storage)); } public function tearDown() { -- cgit v1.2.3 From a0d83771094df4d3a7d27ee72b9abb4a6854b604 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 28 Jun 2013 19:59:04 +0200 Subject: better unit tests for static stream wrapper --- tests/lib/files/stream/staticstream.php | 68 +++++++++++++++++++++++++++++++++ tests/lib/streamwrappers.php | 12 ------ 2 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 tests/lib/files/stream/staticstream.php (limited to 'tests') diff --git a/tests/lib/files/stream/staticstream.php b/tests/lib/files/stream/staticstream.php new file mode 100644 index 00000000000..d55086196a0 --- /dev/null +++ b/tests/lib/files/stream/staticstream.php @@ -0,0 +1,68 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Stream; + +class StaticStream extends \PHPUnit_Framework_TestCase { + + private $sourceFile; + private $sourceText; + + public function __construct() { + $this->sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; + $this->sourceText = file_get_contents($this->sourceFile); + } + + public function tearDown() { + \OC\Files\Stream\StaticStream::clear(); + } + + public function testContent() { + file_put_contents('static://foo', $this->sourceText); + $this->assertEquals($this->sourceText, file_get_contents('static://foo')); + } + + public function testMultipleFiles() { + file_put_contents('static://foo', $this->sourceText); + file_put_contents('static://bar', strrev($this->sourceText)); + $this->assertEquals($this->sourceText, file_get_contents('static://foo')); + $this->assertEquals(strrev($this->sourceText), file_get_contents('static://bar')); + } + + public function testOverwrite() { + file_put_contents('static://foo', $this->sourceText); + file_put_contents('static://foo', 'qwerty'); + $this->assertEquals('qwerty', file_get_contents('static://foo')); + } + + public function testIsFile() { + $this->assertFalse(is_file('static://foo')); + file_put_contents('static://foo', $this->sourceText); + $this->assertTrue(is_file('static://foo')); + } + + public function testIsDir() { + $this->assertFalse(is_dir('static://foo')); + file_put_contents('static://foo', $this->sourceText); + $this->assertFalse(is_dir('static://foo')); + } + + public function testFileType() { + file_put_contents('static://foo', $this->sourceText); + $this->assertEquals('file', filetype('static://foo')); + } + + public function testUnlink() { + $this->assertFalse(file_exists('static://foo')); + file_put_contents('static://foo', $this->sourceText); + $this->assertTrue(file_exists('static://foo')); + unlink('static://foo'); + clearstatcache(); + $this->assertFalse(file_exists('static://foo')); + } +} diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index c7e51ccfa48..d15b712139d 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -33,18 +33,6 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase { $this->assertEquals(count($items), count($result)); } - public function testStaticStream() { - $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt'; - $staticFile = 'static://test'; - $this->assertFalse(file_exists($staticFile)); - file_put_contents($staticFile, file_get_contents($sourceFile)); - $this->assertTrue(file_exists($staticFile)); - $this->assertEquals(file_get_contents($sourceFile), file_get_contents($staticFile)); - unlink($staticFile); - clearstatcache(); - $this->assertFalse(file_exists($staticFile)); - } - public function testCloseStream() { //ensure all basic stream stuff works $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt'; -- cgit v1.2.3 From 7b6fcddbc5314e7401e4f5579853aa6353d462f9 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 18 Jun 2013 18:24:48 +0200 Subject: use executeAudited, add table name to assert message, skip schema changing test on oracle --- tests/lib/dbschema.php | 87 +++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) (limited to 'tests') diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 59f203993ef..5d52db6a5ab 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -7,9 +7,8 @@ */ class Test_DBSchema extends PHPUnit_Framework_TestCase { - protected static $schema_file = 'static://test_db_scheme'; - protected static $schema_file2 = 'static://test_db_scheme2'; - protected $test_prefix; + protected $schema_file = 'static://test_db_scheme'; + protected $schema_file2 = 'static://test_db_scheme2'; protected $table1; protected $table2; @@ -20,19 +19,20 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { $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 ); + file_put_contents( $this->schema_file, $content ); $content = file_get_contents( $dbfile2 ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); - file_put_contents( self::$schema_file2, $content ); + file_put_contents( $this->schema_file2, $content ); - $this->test_prefix = $r; - $this->table1 = $this->test_prefix.'cntcts_addrsbks'; - $this->table2 = $this->test_prefix.'cntcts_cards'; + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + + $this->table1 = $prefix.$r.'cntcts_addrsbks'; + $this->table2 = $prefix.$r.'cntcts_cards'; } public function tearDown() { - unlink(self::$schema_file); - unlink(self::$schema_file2); + unlink($this->schema_file); + unlink($this->schema_file2); } // everything in one test, they depend on each other @@ -47,13 +47,19 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaCreating() { - OC_DB::createDbFromStructure(self::$schema_file); + OC_DB::createDbFromStructure($this->schema_file); $this->assertTableExist($this->table1); $this->assertTableExist($this->table2); } public function doTestSchemaChanging() { - OC_DB::updateDbFromStructure(self::$schema_file2); + if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') { + $this->markTestSkipped( + // see http://abhijitbashetti.blogspot.de/2011/10/converting-varchar2-to-clob-and-clob-to.html + 'Oracle does not simply ALTER a VARCHAR into a CLOB.' + ); + } + OC_DB::updateDbFromStructure($this->schema_file2); $this->assertTableExist($this->table2); } @@ -66,67 +72,62 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaRemoving() { - OC_DB::removeDBStructure(self::$schema_file); + OC_DB::removeDBStructure($this->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(); + . "WHERE type = 'table' AND name = ? " + . "UNION ALL SELECT name FROM sqlite_temp_master " + . "WHERE type = 'table' AND name = ?"; + $result = \OC_DB::executeAudited($sql, array($table, $table)); break; case 'mysql': - $sql = 'SHOW TABLES LIKE "'.$table.'"'; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SHOW TABLES LIKE ?'; + $result = \OC_DB::executeAudited($sql, array($table)); 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(); + $sql = 'SELECT tablename AS table_name, schemaname AS schema_name ' + . 'FROM pg_tables WHERE schemaname NOT LIKE \'pg_%\' ' + . 'AND schemaname != \'information_schema\' ' + . 'AND tablename = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; case 'oci': - $sql = 'SELECT table_name FROM user_tables WHERE table_name = ?'; + $sql = 'SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = ?'; $result = \OC_DB::executeAudited($sql, array($table)); - $exists = (bool)$result->fetchOne(); //oracle uses MDB2 and returns null break; case 'mssql': - $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; } - return $exists; + + $name = $result->fetchOne(); //FIXME checking with '$result->numRows() === 1' does not seem to work? + OC_DB::raiseExceptionOnError($name); + if ($name === $table) { + return true; + } else { + return false; + } } public function assertTableExist($table) { - $this->assertTrue($this->tableExist($table)); + $this->assertTrue($this->tableExist($table), 'Table ' . $table . ' does not exist'); } 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)); + } else { + $this->assertFalse($this->tableExist($table), 'Table ' . $table . ' exists.'); } } } -- cgit v1.2.3 From 4bbdd67a22fd5ac0efc6b8c9dc3e024a0af45c90 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 20 Jun 2013 16:58:49 +0200 Subject: remove wrong check here --- tests/lib/dbschema.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 5d52db6a5ab..103909e2e25 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -110,7 +110,6 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } $name = $result->fetchOne(); //FIXME checking with '$result->numRows() === 1' does not seem to work? - OC_DB::raiseExceptionOnError($name); if ($name === $table) { return true; } else { -- cgit v1.2.3 From c80e76720f4e65a5f7af31f67d70ec66019bcb68 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 28 Jun 2013 16:07:22 +0200 Subject: Going from text to clob is not something we do. Also Oracle DB has problems with this, see http://abhijitbashetti.blogspot.de/2011/10/converting-varchar2-to-clob-and-clob-to.html --- tests/data/db_structure2.xml | 3 ++- tests/lib/dbschema.php | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml index fc6fe0bba7d..6f12f81f477 100644 --- a/tests/data/db_structure2.xml +++ b/tests/data/db_structure2.xml @@ -49,8 +49,9 @@ description - clob + text false + 1024 diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 103909e2e25..c2e55eabf4b 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -53,12 +53,6 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaChanging() { - if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') { - $this->markTestSkipped( - // see http://abhijitbashetti.blogspot.de/2011/10/converting-varchar2-to-clob-and-clob-to.html - 'Oracle does not simply ALTER a VARCHAR into a CLOB.' - ); - } OC_DB::updateDbFromStructure($this->schema_file2); $this->assertTableExist($this->table2); } -- cgit v1.2.3