diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-08-18 11:34:56 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-08-18 11:34:56 +0200 |
commit | d8c71ba734d95e954d4ff3af50a44b94f9f016ff (patch) | |
tree | c89cd494a618e621f9c8941bac52bfed15dbad4c /tests | |
parent | 5c9aedac1b9e858e450ac0b1f009d8042206060b (diff) | |
parent | 12f4494de02457d51004ca6a82c1b2160189819f (diff) | |
download | nextcloud-server-d8c71ba734d95e954d4ff3af50a44b94f9f016ff.tar.gz nextcloud-server-d8c71ba734d95e954d4ff3af50a44b94f9f016ff.zip |
merge master in storage-wrapper-quota
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/l10n/cs.php | 5 | ||||
-rw-r--r-- | tests/data/l10n/de.php | 5 | ||||
-rw-r--r-- | tests/data/l10n/ru.php | 5 | ||||
-rw-r--r-- | tests/data/testimage.gif | bin | 0 -> 362 bytes | |||
-rw-r--r-- | tests/data/testimage.jpg | bin | 0 -> 25392 bytes | |||
-rw-r--r-- | tests/data/testimage.png | bin | 0 -> 3670 bytes | |||
-rw-r--r-- | tests/lib/db.php | 14 | ||||
-rw-r--r-- | tests/lib/db/mdb2schemareader.php | 80 | ||||
-rw-r--r-- | tests/lib/db/testschema.xml | 77 | ||||
-rw-r--r-- | tests/lib/files/cache/cache.php | 5 | ||||
-rw-r--r-- | tests/lib/files/cache/scanner.php | 18 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 53 | ||||
-rw-r--r-- | tests/lib/files/utils/scanner.php | 74 | ||||
-rw-r--r-- | tests/lib/image.php | 221 | ||||
-rw-r--r-- | tests/lib/l10n.php | 67 | ||||
-rw-r--r-- | tests/lib/memcache/apc.php | 4 | ||||
-rw-r--r-- | tests/lib/memcache/apcu.php | 20 | ||||
-rw-r--r-- | tests/lib/preferences.php | 126 | ||||
-rw-r--r-- | tests/lib/util.php | 61 | ||||
-rw-r--r-- | tests/phpunit-autotest.xml | 1 |
20 files changed, 778 insertions, 58 deletions
diff --git a/tests/data/l10n/cs.php b/tests/data/l10n/cs.php new file mode 100644 index 00000000000..1c5907bc148 --- /dev/null +++ b/tests/data/l10n/cs.php @@ -0,0 +1,5 @@ +<?php +$TRANSLATIONS = array( + "_%n window__%n windows_" => array("%n okno", "%n okna", "%n oken") +); +$PLURAL_FORMS = "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;"; diff --git a/tests/data/l10n/de.php b/tests/data/l10n/de.php new file mode 100644 index 00000000000..858ec8af49c --- /dev/null +++ b/tests/data/l10n/de.php @@ -0,0 +1,5 @@ +<?php +$TRANSLATIONS = array( + "_%n file__%n files_" => array("%n Datei", "%n Dateien") +); +$PLURAL_FORMS = "nplurals=2; plural=(n != 1);"; diff --git a/tests/data/l10n/ru.php b/tests/data/l10n/ru.php new file mode 100644 index 00000000000..dd46293db6c --- /dev/null +++ b/tests/data/l10n/ru.php @@ -0,0 +1,5 @@ +<?php +$TRANSLATIONS = array( + "_%n file__%n files_" => array("%n файл", "%n файла", "%n файлов") +); +$PLURAL_FORMS = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);"; diff --git a/tests/data/testimage.gif b/tests/data/testimage.gif Binary files differnew file mode 100644 index 00000000000..3026395c5e6 --- /dev/null +++ b/tests/data/testimage.gif diff --git a/tests/data/testimage.jpg b/tests/data/testimage.jpg Binary files differnew file mode 100644 index 00000000000..2f51a2a6cdd --- /dev/null +++ b/tests/data/testimage.jpg diff --git a/tests/data/testimage.png b/tests/data/testimage.png Binary files differnew file mode 100644 index 00000000000..257598f04f5 --- /dev/null +++ b/tests/data/testimage.png diff --git a/tests/lib/db.php b/tests/lib/db.php index e817a2db5ed..51edbf7b309 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -71,7 +71,19 @@ class Test_DB extends PHPUnit_Framework_TestCase { $result = $query->execute(array('uri_3')); $this->assertTrue((bool)$result); } - + + public function testLastInsertId() { + $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); + $result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1')); + $id1 = OC_DB::insertid('*PREFIX*'.$this->table2); + + // we don't know the id we should expect, so insert another row + $result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2')); + $id2 = OC_DB::insertid('*PREFIX*'.$this->table2); + // now we can check if the two ids are in correct order + $this->assertGreaterThan($id1, $id2); + } + public function testinsertIfNotExist() { $categoryentries = array( array('user' => 'test', 'type' => 'contact', 'category' => 'Family', 'expectedResult' => 1), diff --git a/tests/lib/db/mdb2schemareader.php b/tests/lib/db/mdb2schemareader.php new file mode 100644 index 00000000000..b9b241194fd --- /dev/null +++ b/tests/lib/db/mdb2schemareader.php @@ -0,0 +1,80 @@ +<?php + +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\DB; + +use Doctrine\DBAL\Platforms\MySqlPlatform; + +class MDB2SchemaReader extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\DB\MDB2SchemaReader $reader + */ + protected $reader; + + /** + * @return \OC\Config + */ + protected function getConfig() { + $config = $this->getMockBuilder('\OC\Config') + ->disableOriginalConstructor() + ->getMock(); + $config->expects($this->any()) + ->method('getValue') + ->will($this->returnValueMap(array( + array('dbname', 'owncloud', 'testDB'), + array('dbtableprefix', 'oc_', 'test_') + ))); + return $config; + } + + public function testRead() { + $reader = new \OC\DB\MDB2SchemaReader($this->getConfig(), new MySqlPlatform()); + $schema = $reader->loadSchemaFromFile(__DIR__ . '/testschema.xml'); + $this->assertCount(1, $schema->getTables()); + + $table = $schema->getTable('test_table'); + $this->assertCount(7, $table->getColumns()); + + $this->assertEquals(4, $table->getColumn('integerfield')->getLength()); + $this->assertTrue($table->getColumn('integerfield')->getAutoincrement()); + $this->assertNull($table->getColumn('integerfield')->getDefault()); + $this->assertTrue($table->getColumn('integerfield')->getNotnull()); + $this->assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $table->getColumn('integerfield')->getType()); + + $this->assertSame(10, $table->getColumn('integerfield_default')->getDefault()); + + $this->assertEquals(32, $table->getColumn('textfield')->getLength()); + $this->assertFalse($table->getColumn('textfield')->getAutoincrement()); + $this->assertSame('foo', $table->getColumn('textfield')->getDefault()); + $this->assertTrue($table->getColumn('textfield')->getNotnull()); + $this->assertInstanceOf('Doctrine\DBAL\Types\StringType', $table->getColumn('textfield')->getType()); + + $this->assertNull($table->getColumn('clobfield')->getLength()); + $this->assertFalse($table->getColumn('clobfield')->getAutoincrement()); + $this->assertSame('', $table->getColumn('clobfield')->getDefault()); + $this->assertTrue($table->getColumn('clobfield')->getNotnull()); + $this->assertInstanceOf('Doctrine\DBAL\Types\TextType', $table->getColumn('clobfield')->getType()); + + $this->assertNull($table->getColumn('booleanfield')->getLength()); + $this->assertFalse($table->getColumn('booleanfield')->getAutoincrement()); + $this->assertFalse($table->getColumn('booleanfield')->getDefault()); + $this->assertInstanceOf('Doctrine\DBAL\Types\BooleanType', $table->getColumn('booleanfield')->getType()); + + $this->assertTrue($table->getColumn('booleanfield_true')->getDefault()); + $this->assertFalse($table->getColumn('booleanfield_false')->getDefault()); + + $this->assertCount(2, $table->getIndexes()); + $this->assertEquals(array('integerfield'), $table->getIndex('primary')->getUnquotedColumns()); + $this->assertTrue($table->getIndex('primary')->isPrimary()); + $this->assertTrue($table->getIndex('primary')->isUnique()); + $this->assertEquals(array('booleanfield'), $table->getIndex('index_boolean')->getUnquotedColumns()); + $this->assertFalse($table->getIndex('index_boolean')->isPrimary()); + $this->assertFalse($table->getIndex('index_boolean')->isUnique()); + } +} diff --git a/tests/lib/db/testschema.xml b/tests/lib/db/testschema.xml new file mode 100644 index 00000000000..509b55ee81f --- /dev/null +++ b/tests/lib/db/testschema.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="utf-8" ?> +<database> + + <name>*dbname*</name> + <create>true</create> + <overwrite>false</overwrite> + + <charset>utf8</charset> + + <table> + + <name>*dbprefix*table</name> + + <declaration> + <field> + <name>integerfield</name> + <type>integer</type> + <default>0</default> + <notnull>true</notnull> + <autoincrement>1</autoincrement> + <length>4</length> + </field> + <field> + <name>integerfield_default</name> + <type>integer</type> + <default>10</default> + <notnull>true</notnull> + <length>4</length> + </field> + <field> + <name>textfield</name> + <type>text</type> + <default>foo</default> + <notnull>true</notnull> + <length>32</length> + </field> + <field> + <name>clobfield</name> + <type>clob</type> + <notnull>true</notnull> + </field> + <field> + <name>booleanfield</name> + <type>boolean</type> + </field> + <field> + <name>booleanfield_true</name> + <type>boolean</type> + <default>true</default> + </field> + <field> + <name>booleanfield_false</name> + <type>boolean</type> + <default>false</default> + </field> + + <index> + <name>index_primary</name> + <primary>true</primary> + <unique>true</unique> + <field> + <name>integerfield</name> + <sorting>ascending</sorting> + </field> + </index> + + <index> + <name>index_boolean</name> + <unique>false</unique> + <field> + <name>booleanfield</name> + <sorting>ascending</sorting> + </field> + </index> + </declaration> + </table> +</database> diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 527c1d1b2a1..247373a5cb9 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -127,6 +127,11 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertEquals(1025, $this->cache->calculateFolderSize($file1)); + $this->cache->remove($file2); + $this->cache->remove($file3); + $this->cache->remove($file4); + $this->assertEquals(0, $this->cache->calculateFolderSize($file1)); + $this->cache->remove('folder'); $this->assertFalse($this->cache->inCache('folder/foo')); $this->assertFalse($this->cache->inCache('folder/bar')); diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index 263ceadccc7..f6deb93a49e 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -143,6 +143,24 @@ class Scanner extends \PHPUnit_Framework_TestCase { $newData = $this->cache->get(''); $this->assertEquals($oldData['etag'], $newData['etag']); $this->assertEquals(-1, $newData['size']); + + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); + $oldData = $this->cache->get(''); + $this->assertNotEquals(-1, $oldData['size']); + $this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); + + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); + + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); } public function testRemovedFile() { diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index fbf502fbc1c..3f339a10016 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -176,68 +176,21 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); $stat = $this->instance->stat('/lorem.txt'); - //only size and mtime are requered in the result + //only size and mtime are required in the result $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); $this->assertEquals($stat['mtime'], $mTime); - $mtimeStart = time(); - $supportsTouch = $this->instance->touch('/lorem.txt'); - $mtimeEnd = time(); - if ($supportsTouch !== false) { + if ($this->instance->touch('/lorem.txt', 100) !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 5) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 5)); - - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 5)); - - if ($this->instance->touch('/lorem.txt', 100) !== false) { - $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertEquals($mTime, 100); - } + $this->assertEquals($mTime, 100); } $mtimeStart = time(); - $fh = $this->instance->fopen('/lorem.txt', 'a'); - fwrite($fh, ' '); - fclose($fh); - clearstatcache(); - $mtimeEnd = time(); - $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 5) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 5)); $this->instance->unlink('/lorem.txt'); $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } - public function testSearch() { - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); - $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; - $this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r')); - $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; - $this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r')); - $result = $this->instance->search('logo'); - $this->assertEquals(2, count($result)); - $this->assertContains('/logo-wide.svg', $result); - $this->assertContains('/logo-wide.png', $result); - } - - public function testSearchInSubFolder() { - $this->instance->mkdir('sub'); - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; - $this->instance->file_put_contents('/sub/lorem.txt', file_get_contents($textFile, 'r')); - $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; - $this->instance->file_put_contents('/sub/logo-wide.png', file_get_contents($pngFile, 'r')); - $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; - $this->instance->file_put_contents('/sub/logo-wide.svg', file_get_contents($svgFile, 'r')); - - $result = $this->instance->search('logo'); - $this->assertEquals(2, count($result)); - $this->assertContains('/sub/logo-wide.svg', $result); - $this->assertContains('/sub/logo-wide.png', $result); - } - public function testFOpen() { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php new file mode 100644 index 00000000000..a021d215ae5 --- /dev/null +++ b/tests/lib/files/utils/scanner.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Utils; + +use OC\Files\Mount\Mount; +use OC\Files\Storage\Temporary; + +class TestScanner extends \OC\Files\Utils\Scanner { + /** + * @var \OC\Files\Mount\Mount[] $mounts + */ + private $mounts = array(); + + /** + * @param \OC\Files\Mount\Mount $mount + */ + public function addMount($mount) { + $this->mounts[] = $mount; + } + + protected function getMounts($dir) { + return $this->mounts; + } +} + +class Scanner extends \PHPUnit_Framework_TestCase { + public function testReuseExistingRoot() { + $storage = new Temporary(array()); + $mount = new Mount($storage, ''); + $cache = $storage->getCache(); + + $storage->mkdir('folder'); + $storage->file_put_contents('foo.txt', 'qwerty'); + $storage->file_put_contents('folder/bar.txt', 'qwerty'); + + $scanner = new TestScanner(''); + $scanner->addMount($mount); + + $scanner->scan(''); + $this->assertTrue($cache->inCache('folder/bar.txt')); + $oldRoot = $cache->get(''); + + $scanner->scan(''); + $newRoot = $cache->get(''); + $this->assertEquals($oldRoot, $newRoot); + } + + public function testReuseExistingFile() { + $storage = new Temporary(array()); + $mount = new Mount($storage, ''); + $cache = $storage->getCache(); + + $storage->mkdir('folder'); + $storage->file_put_contents('foo.txt', 'qwerty'); + $storage->file_put_contents('folder/bar.txt', 'qwerty'); + + $scanner = new TestScanner(''); + $scanner->addMount($mount); + + $scanner->scan(''); + $this->assertTrue($cache->inCache('folder/bar.txt')); + $old = $cache->get('folder/bar.txt'); + + $scanner->scan(''); + $new = $cache->get('folder/bar.txt'); + $this->assertEquals($old, $new); + } +} diff --git a/tests/lib/image.php b/tests/lib/image.php new file mode 100644 index 00000000000..0583c300075 --- /dev/null +++ b/tests/lib/image.php @@ -0,0 +1,221 @@ +<?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_Image extends PHPUnit_Framework_TestCase { + + public function testGetMimeTypeForFile() { + $mimetype = \OC_Image::getMimeTypeForFile(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertEquals('image/png', $mimetype); + + $mimetype = \OC_Image::getMimeTypeForFile(OC::$SERVERROOT.'/tests/data/testimage.jpg'); + $this->assertEquals('image/jpeg', $mimetype); + + $mimetype = \OC_Image::getMimeTypeForFile(OC::$SERVERROOT.'/tests/data/testimage.gif'); + $this->assertEquals('image/gif', $mimetype); + + $mimetype = \OC_Image::getMimeTypeForFile(null); + $this->assertEquals('', $mimetype); + } + + public function testConstructDestruct() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertInstanceOf('\OC_Image', $img); + unset($img); + + $imgcreate = imagecreatefromjpeg(OC::$SERVERROOT.'/tests/data/testimage.jpg'); + $img = new \OC_Image($imgcreate); + $this->assertInstanceOf('\OC_Image', $img); + unset($img); + + $base64 = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif')); + $img = new \OC_Image($base64); + $this->assertInstanceOf('\OC_Image', $img); + unset($img); + + $img = new \OC_Image(null); + $this->assertInstanceOf('\OC_Image', $img); + unset($img); + } + + public function testValid() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertTrue($img->valid()); + + $text = base64_encode("Lorem ipsum dolor sir amet …"); + $img = new \OC_Image($text); + $this->assertFalse($img->valid()); + + $img = new \OC_Image(null); + $this->assertFalse($img->valid()); + } + + public function testMimeType() { + $this->markTestSkipped("When loading from data or base64, imagetype is always image/png, see #4258."); + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertEquals('image/png', $img->mimeType()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertEquals('image/jpeg', $img->mimeType()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertEquals('image/gif', $img->mimeType()); + + $img = new \OC_Image(null); + $this->assertEquals('', $img->mimeType()); + } + + public function testWidth() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertEquals(128, $img->width()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertEquals(1680, $img->width()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertEquals(64, $img->width()); + + $img = new \OC_Image(null); + $this->assertEquals(-1, $img->width()); + } + + public function testHeight() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertEquals(128, $img->height()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertEquals(1050, $img->height()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertEquals(64, $img->height()); + + $img = new \OC_Image(null); + $this->assertEquals(-1, $img->height()); + } + + public function testSave() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $img->resize(16); + $img->save(OC::$SERVERROOT.'/tests/data/testimage2.png'); + $this->assertEquals(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage2.png'), $img->data()); + } + + public function testData() { + $this->markTestSkipped("\OC_Image->data() converts to png before outputting data, see #4258."); + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $expected = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertEquals($expected, $img->data()); + + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.jpg'); + $expected = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'); + $this->assertEquals($expected, $img->data()); + + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.gif'); + $expected = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'); + $this->assertEquals($expected, $img->data()); + } + + public function testToString() { + $this->markTestSkipped("\OC_Image->data() converts to png before outputting data, see #4258."); + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $expected = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png')); + $this->assertEquals($expected, (string)$img); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $expected = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertEquals($expected, (string)$img); + + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.gif'); + $expected = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif')); + $this->assertEquals($expected, (string)$img); + } + + public function testResize() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertTrue($img->resize(32)); + $this->assertEquals(32, $img->width()); + $this->assertEquals(32, $img->height()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertTrue($img->resize(840)); + $this->assertEquals(840, $img->width()); + $this->assertEquals(525, $img->height()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertTrue($img->resize(100)); + $this->assertEquals(100, $img->width()); + $this->assertEquals(100, $img->height()); + } + + public function testPreciseResize() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertTrue($img->preciseResize(128, 512)); + $this->assertEquals(128, $img->width()); + $this->assertEquals(512, $img->height()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertTrue($img->preciseResize(64, 840)); + $this->assertEquals(64, $img->width()); + $this->assertEquals(840, $img->height()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertTrue($img->preciseResize(1000, 1337)); + $this->assertEquals(1000, $img->width()); + $this->assertEquals(1337, $img->height()); + } + + public function testCenterCrop() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $img->centerCrop(); + $this->assertEquals(128, $img->width()); + $this->assertEquals(128, $img->height()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $img->centerCrop(); + $this->assertEquals(1050, $img->width()); + $this->assertEquals(1050, $img->height()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $img->centerCrop(512); + $this->assertEquals(512, $img->width()); + $this->assertEquals(512, $img->height()); + } + + public function testCrop() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertTrue($img->crop(0, 0, 50, 20)); + $this->assertEquals(50, $img->width()); + $this->assertEquals(20, $img->height()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertTrue($img->crop(500, 700, 550, 300)); + $this->assertEquals(550, $img->width()); + $this->assertEquals(300, $img->height()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertTrue($img->crop(10, 10, 15, 15)); + $this->assertEquals(15, $img->width()); + $this->assertEquals(15, $img->height()); + } + + public function testFitIn() { + $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); + $this->assertTrue($img->fitIn(200, 100)); + $this->assertEquals(100, $img->width()); + $this->assertEquals(100, $img->height()); + + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $this->assertTrue($img->fitIn(840, 840)); + $this->assertEquals(840, $img->width()); + $this->assertEquals(525, $img->height()); + + $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); + $this->assertTrue($img->fitIn(200, 250)); + $this->assertEquals(200, $img->width()); + $this->assertEquals(200, $img->height()); + } +} diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php new file mode 100644 index 00000000000..12eac818f84 --- /dev/null +++ b/tests/lib/l10n.php @@ -0,0 +1,67 @@ +<?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_L10n extends PHPUnit_Framework_TestCase { + + public function testGermanPluralTranslations() { + $l = new OC_L10N('test'); + $transFile = OC::$SERVERROOT.'/tests/data/l10n/de.php'; + + $l->load($transFile); + $this->assertEquals('1 Datei', (string)$l->n('%n file', '%n files', 1)); + $this->assertEquals('2 Dateien', (string)$l->n('%n file', '%n files', 2)); + } + + public function testRussianPluralTranslations() { + $l = new OC_L10N('test'); + $transFile = OC::$SERVERROOT.'/tests/data/l10n/ru.php'; + + $l->load($transFile); + $this->assertEquals('1 файл', (string)$l->n('%n file', '%n files', 1)); + $this->assertEquals('2 файла', (string)$l->n('%n file', '%n files', 2)); + $this->assertEquals('6 файлов', (string)$l->n('%n file', '%n files', 6)); + $this->assertEquals('21 файл', (string)$l->n('%n file', '%n files', 21)); + $this->assertEquals('22 файла', (string)$l->n('%n file', '%n files', 22)); + $this->assertEquals('26 файлов', (string)$l->n('%n file', '%n files', 26)); + + /* + 1 file 1 файл 1 папка + 2-4 files 2-4 файла 2-4 папки + 5-20 files 5-20 файлов 5-20 папок + 21 files 21 файл 21 папка + 22-24 files 22-24 файла 22-24 папки + 25-30 files 25-30 файлов 25-30 папок + etc + 100 files 100 файлов, 100 папок + 1000 files 1000 файлов 1000 папок + */ + } + + public function testCzechPluralTranslations() { + $l = new OC_L10N('test'); + $transFile = OC::$SERVERROOT.'/tests/data/l10n/cs.php'; + + $l->load($transFile); + $this->assertEquals('1 okno', (string)$l->n('%n window', '%n windows', 1)); + $this->assertEquals('2 okna', (string)$l->n('%n window', '%n windows', 2)); + $this->assertEquals('5 oken', (string)$l->n('%n window', '%n windows', 5)); + } + + /** + * Issue #4360: Do not call strtotime() on numeric strings. + */ + public function testNumericStringToDateTime() { + $l = new OC_L10N('test'); + $this->assertSame('February 13, 2009 23:31', $l->l('datetime', '1234567890')); + } + + public function testNumericToDateTime() { + $l = new OC_L10N('test'); + $this->assertSame('February 13, 2009 23:31', $l->l('datetime', 1234567890)); + } +} diff --git a/tests/lib/memcache/apc.php b/tests/lib/memcache/apc.php index 6b2a49470ba..e5d753a4fa5 100644 --- a/tests/lib/memcache/apc.php +++ b/tests/lib/memcache/apc.php @@ -15,6 +15,10 @@ class APC extends Cache { $this->markTestSkipped('The apc extension is not available.'); return; } + if(\OC\Memcache\APCu::isAvailable()) { + $this->markTestSkipped('The apc extension is emulated by ACPu.'); + return; + } $this->instance=new \OC\Memcache\APC(uniqid()); } } diff --git a/tests/lib/memcache/apcu.php b/tests/lib/memcache/apcu.php new file mode 100644 index 00000000000..7b99e7cd5e0 --- /dev/null +++ b/tests/lib/memcache/apcu.php @@ -0,0 +1,20 @@ +<?php + +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Memcache; + +class APCu extends Cache { + public function setUp() { + if(!\OC\Memcache\APCu::isAvailable()) { + $this->markTestSkipped('The APCu extension is not available.'); + return; + } + $this->instance=new \OC\Memcache\APCu(uniqid()); + } +} diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php new file mode 100644 index 00000000000..612cc81926b --- /dev/null +++ b/tests/lib/preferences.php @@ -0,0 +1,126 @@ +<?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_Preferences extends PHPUnit_Framework_TestCase { + public static function setUpBeforeClass() { + $query = \OC_DB::prepare('INSERT INTO `*PREFIX*preferences` VALUES(?, ?, ?, ?)'); + $query->execute(array("Someuser", "someapp", "somekey", "somevalue")); + + $query->execute(array("Someuser", "getusersapp", "somekey", "somevalue")); + $query->execute(array("Anotheruser", "getusersapp", "somekey", "someothervalue")); + $query->execute(array("Anuser", "getusersapp", "somekey", "somevalue")); + + $query->execute(array("Someuser", "getappsapp", "somekey", "somevalue")); + + $query->execute(array("Someuser", "getkeysapp", "firstkey", "somevalue")); + $query->execute(array("Someuser", "getkeysapp", "anotherkey", "somevalue")); + $query->execute(array("Someuser", "getkeysapp", "key-tastic", "somevalue")); + + $query->execute(array("Someuser", "getvalueapp", "key", "a value for a key")); + + $query->execute(array("Deleteuser", "deleteapp", "deletekey", "somevalue")); + $query->execute(array("Deleteuser", "deleteapp", "somekey", "somevalue")); + $query->execute(array("Deleteuser", "someapp", "somekey", "somevalue")); + } + + public static function tearDownAfterClass() { + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?'); + $query->execute(array('Someuser')); + $query->execute(array('Anotheruser')); + $query->execute(array('Anuser')); + } + + public function testGetUsers() { + $query = \OC_DB::prepare('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`'); + $result = $query->execute(); + $expected = array(); + while ($row = $result->fetchRow()) { + $expected[] = $row['userid']; + } + + $this->assertEquals($expected, \OC_Preferences::getUsers()); + } + + public function testGetApps() { + $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?'); + $result = $query->execute(array('Someuser')); + $expected = array(); + while ($row = $result->fetchRow()) { + $expected[] = $row['appid']; + } + + $this->assertEquals($expected, \OC_Preferences::getApps('Someuser')); + } + + public function testGetKeys() { + $query = \OC_DB::prepare('SELECT DISTINCT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?'); + $result = $query->execute(array('Someuser', 'getkeysapp')); + $expected = array(); + while ($row = $result->fetchRow()) { + $expected[] = $row['configkey']; + } + + $this->assertEquals($expected, \OC_Preferences::getKeys('Someuser', 'getkeysapp')); + } + + public function testGetValue() { + $this->assertNull(\OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant')); + + $this->assertEquals('default', \OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant', 'default')); + + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'getvalueapp', 'key')); + $row = $result->fetchRow(); + $expected = $row['configvalue']; + $this->assertEquals($expected, \OC_Preferences::getValue('Someuser', 'getvalueapp', 'key')); + } + + public function testSetValue() { + $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey')); + $row = $result->fetchRow(); + $value = $row['configvalue']; + $this->assertEquals('newvalue', $value); + + $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey')); + $row = $result->fetchRow(); + $value = $row['configvalue']; + $this->assertEquals('othervalue', $value); + } + + public function testDeleteKey() { + $this->assertTrue(\OC_Preferences::deleteKey('Deleteuser', 'deleteapp', 'deletekey')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'); + $result = $query->execute(array('Deleteuser', 'deleteapp', 'deletekey')); + $this->assertEquals(0, $result->numRows()); + } + + public function testDeleteApp() { + $this->assertTrue(\OC_Preferences::deleteApp('Deleteuser', 'deleteapp')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?'); + $result = $query->execute(array('Deleteuser', 'deleteapp')); + $this->assertEquals(0, $result->numRows()); + } + + public function testDeleteUser() { + $this->assertTrue(\OC_Preferences::deleteUser('Deleteuser')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'); + $result = $query->execute(array('Deleteuser')); + $this->assertEquals(0, $result->numRows()); + } + + public function testDeleteAppFromAllUsers() { + $this->assertTrue(\OC_Preferences::deleteAppFromAllUsers('someapp')); + $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `appid` = ?'); + $result = $query->execute(array('someapp')); + $this->assertEquals(0, $result->numRows()); + } +} diff --git a/tests/lib/util.php b/tests/lib/util.php index 9742d57ac7a..13aa49c8c6f 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -7,13 +7,27 @@ */ class Test_Util extends PHPUnit_Framework_TestCase { + public function testGetVersion() { + $version = \OC_Util::getVersion(); + $this->assertTrue(is_array($version)); + foreach ($version as $num) { + $this->assertTrue(is_int($num)); + } + } - // Constructor - function Test_Util() { - date_default_timezone_set("UTC"); + public function testGetVersionString() { + $version = \OC_Util::getVersionString(); + $this->assertTrue(is_string($version)); + } + + public function testGetEditionString() { + $edition = \OC_Util::getEditionString(); + $this->assertTrue(is_string($edition)); } function testFormatDate() { + date_default_timezone_set("UTC"); + $result = OC_Util::formatDate(1350129205); $expected = 'October 13, 2012 11:53'; $this->assertEquals($expected, $result); @@ -44,6 +58,19 @@ class Test_Util extends PHPUnit_Framework_TestCase { $this->assertEquals("/%C2%A7%23%40test%25%26%5E%C3%A4/-child", $result); } + public function testFileInfoLoaded() { + $expected = function_exists('finfo_open'); + $this->assertEquals($expected, \OC_Util::fileInfoLoaded()); + } + + public function testIsInternetConnectionEnabled() { + \OC_Config::setValue("has_internet_connection", false); + $this->assertFalse(\OC_Util::isInternetConnectionEnabled()); + + \OC_Config::setValue("has_internet_connection", true); + $this->assertTrue(\OC_Util::isInternetConnectionEnabled()); + } + function testGenerate_random_bytes() { $result = strlen(OC_Util::generate_random_bytes(59)); $this->assertEquals(59, $result); @@ -61,8 +88,28 @@ class Test_Util extends PHPUnit_Framework_TestCase { OC_Config::deleteKey('mail_domain'); } - function testGetInstanceIdGeneratesValidId() { - OC_Config::deleteKey('instanceid'); - $this->assertStringStartsWith('oc', OC_Util::getInstanceId()); - } + function testGetInstanceIdGeneratesValidId() { + OC_Config::deleteKey('instanceid'); + $this->assertStringStartsWith('oc', OC_Util::getInstanceId()); + } + + /** + * @dataProvider baseNameProvider + */ + public function testBaseName($expected, $file) + { + $base = \OC_Util::basename($file); + $this->assertEquals($expected, $base); + } + + public function baseNameProvider() + { + return array( + array('public_html', '/home/user/public_html/'), + array('public_html', '/home/user/public_html'), + array('', '/'), + array('public_html', 'public_html'), + array('442aa682de2a64db1e010f50e60fd9c9', 'local::C:\Users\ADMINI~1\AppData\Local\Temp\2/442aa682de2a64db1e010f50e60fd9c9/') + ); + } } diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml index 23b2d6c0060..a893e96ad97 100644 --- a/tests/phpunit-autotest.xml +++ b/tests/phpunit-autotest.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <phpunit bootstrap="bootstrap.php" strict="true" + verbose="true" timeoutForSmallTests="900" timeoutForMediumTests="900" timeoutForLargeTests="900" |