diff options
author | Georg Ehrke <developer@georgehrke.com> | 2013-08-05 14:27:38 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2013-08-05 14:27:38 +0200 |
commit | af983b843d1335917f4a702cea6d91d28bab68e9 (patch) | |
tree | 692e6e4090ef282b597b9b69d2abd53262cf47a0 /tests | |
parent | 554b1990e23c76aea182e9b8c2687f8f8b939fb9 (diff) | |
parent | 0fce89308e2fbcb44a2091ca67f373ba89ee068e (diff) | |
download | nextcloud-server-af983b843d1335917f4a702cea6d91d28bab68e9.tar.gz nextcloud-server-af983b843d1335917f4a702cea6d91d28bab68e9.zip |
fix merge conflicts
Diffstat (limited to 'tests')
-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 | 16 | ||||
-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/image.php | 221 | ||||
-rw-r--r-- | tests/lib/util.php | 33 |
9 files changed, 423 insertions, 9 deletions
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..79e05f30a1c 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -71,7 +71,21 @@ 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); + $this->assertInternalType('int', $id1); + + // 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->assertInternalType('int', $id2); + $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/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/util.php b/tests/lib/util.php index 9742d57ac7a..a038538d7ea 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -8,12 +8,9 @@ class Test_Util extends PHPUnit_Framework_TestCase { - // Constructor - function Test_Util() { + function testFormatDate() { date_default_timezone_set("UTC"); - } - function testFormatDate() { $result = OC_Util::formatDate(1350129205); $expected = 'October 13, 2012 11:53'; $this->assertEquals($expected, $result); @@ -61,8 +58,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/') + ); + } } |