summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorkondou <kondou@ts.unde.re>2013-09-02 07:58:06 +0200
committerkondou <kondou@ts.unde.re>2013-09-02 07:58:06 +0200
commite5fc7b9dbeb01ac116bb132903c562c8f7d3c5b3 (patch)
treeb7d8d913cdf7f4d1ce42f3027918ad0f5fbe5c3b /tests
parent8dd93c8c0288a11f04816bea2a58aee661ef9e97 (diff)
parentf038cb9aea7c9a1513ab14d0df002773b17d5333 (diff)
downloadnextcloud-server-e5fc7b9dbeb01ac116bb132903c562c8f7d3c5b3.tar.gz
nextcloud-server-e5fc7b9dbeb01ac116bb132903c562c8f7d3c5b3.zip
Merge branch 'master' into clean_up_util
Conflicts: lib/base.php
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appconfig.php132
-rw-r--r--tests/lib/connector/sabre/quotaplugin.php101
-rw-r--r--tests/lib/group/group.php10
-rw-r--r--tests/lib/image.php36
-rw-r--r--tests/lib/preview.php108
5 files changed, 373 insertions, 14 deletions
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
new file mode 100644
index 00000000000..4d82cd5ba7b
--- /dev/null
+++ b/tests/lib/appconfig.php
@@ -0,0 +1,132 @@
+<?php
+/**
+ * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Appconfig extends PHPUnit_Framework_TestCase {
+ public static function setUpBeforeClass() {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
+
+ $query->execute(array('testapp', 'enabled', 'true'));
+ $query->execute(array('testapp', 'installed_version', '1.2.3'));
+ $query->execute(array('testapp', 'depends_on', 'someapp'));
+ $query->execute(array('testapp', 'deletethis', 'deletethis'));
+ $query->execute(array('testapp', 'key', 'value'));
+
+ $query->execute(array('someapp', 'key', 'value'));
+ $query->execute(array('someapp', 'otherkey', 'othervalue'));
+
+ $query->execute(array('123456', 'key', 'value'));
+ $query->execute(array('123456', 'enabled', 'false'));
+
+ $query->execute(array('anotherapp', 'key', 'value'));
+ $query->execute(array('anotherapp', 'enabled', 'false'));
+ }
+
+ public static function tearDownAfterClass() {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('testapp'));
+ $query->execute(array('someapp'));
+ $query->execute(array('123456'));
+ $query->execute(array('anotherapp'));
+ }
+
+ public function testGetApps() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`');
+ $result = $query->execute();
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['appid'];
+ }
+ $apps = \OC_Appconfig::getApps();
+ $this->assertEquals($expected, $apps);
+ }
+
+ public function testGetKeys() {
+ $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $result = $query->execute(array('testapp'));
+ $expected = array();
+ while($row = $result->fetchRow()) {
+ $expected[] = $row["configkey"];
+ }
+ $keys = \OC_Appconfig::getKeys('testapp');
+ $this->assertEquals($expected, $keys);
+ }
+
+ public function testGetValue() {
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('testapp', 'installed_version'));
+ $expected = $result->fetchRow();
+ $value = \OC_Appconfig::getValue('testapp', 'installed_version');
+ $this->assertEquals($expected['configvalue'], $value);
+
+ $value = \OC_Appconfig::getValue('testapp', 'nonexistant');
+ $this->assertNull($value);
+
+ $value = \OC_Appconfig::getValue('testapp', 'nonexistant', 'default');
+ $this->assertEquals('default', $value);
+ }
+
+ public function testHasKey() {
+ $value = \OC_Appconfig::hasKey('testapp', 'installed_version');
+ $this->assertTrue($value);
+
+ $value = \OC_Appconfig::hasKey('nonexistant', 'nonexistant');
+ $this->assertFalse($value);
+ }
+
+ public function testSetValue() {
+ \OC_Appconfig::setValue('testapp', 'installed_version', '1.33.7');
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('testapp', 'installed_version'));
+ $value = $result->fetchRow();
+ $this->assertEquals('1.33.7', $value['configvalue']);
+
+ \OC_Appconfig::setValue('someapp', 'somekey', 'somevalue');
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('someapp', 'somekey'));
+ $value = $result->fetchRow();
+ $this->assertEquals('somevalue', $value['configvalue']);
+ }
+
+ public function testDeleteKey() {
+ \OC_Appconfig::deleteKey('testapp', 'deletethis');
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $query->execute(array('testapp', 'deletethis'));
+ $result = (bool)$query->fetchRow();
+ $this->assertFalse($result);
+ }
+
+ public function testDeleteApp() {
+ \OC_Appconfig::deleteApp('someapp');
+ $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('someapp'));
+ $result = (bool)$query->fetchRow();
+ $this->assertFalse($result);
+ }
+
+ public function testGetValues() {
+ $this->assertFalse(\OC_Appconfig::getValues('testapp', 'enabled'));
+
+ $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('testapp'));
+ $expected = array();
+ while ($row = $query->fetchRow()) {
+ $expected[$row['configkey']] = $row['configvalue'];
+ }
+ $values = \OC_Appconfig::getValues('testapp', false);
+ $this->assertEquals($expected, $values);
+
+ $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?');
+ $query->execute(array('enabled'));
+ $expected = array();
+ while ($row = $query->fetchRow()) {
+ $expected[$row['appid']] = $row['configvalue'];
+ }
+ $values = \OC_Appconfig::getValues(false, 'enabled');
+ $this->assertEquals($expected, $values);
+ }
+}
diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php
new file mode 100644
index 00000000000..1186de28742
--- /dev/null
+++ b/tests/lib/connector/sabre/quotaplugin.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Sabre_DAV_Server
+ */
+ private $server;
+
+ /**
+ * @var OC_Connector_Sabre_QuotaPlugin
+ */
+ private $plugin;
+
+ public function setUp() {
+ $this->server = new Sabre_DAV_Server();
+ $this->plugin = new OC_Connector_Sabre_QuotaPlugin();
+ $this->plugin->initialize($this->server);
+ }
+
+ /**
+ * @dataProvider lengthProvider
+ */
+ public function testLength($expected, $headers)
+ {
+ $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $length = $this->plugin->getLength();
+ $this->assertEquals($expected, $length);
+ }
+
+ /**
+ * @dataProvider quotaOkayProvider
+ */
+ public function testCheckQuota($quota, $headers)
+ {
+ $this->plugin->fileView = $this->buildFileViewMock($quota);
+
+ $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $result = $this->plugin->checkQuota('');
+ $this->assertTrue($result);
+ }
+
+ /**
+ * @expectedException Sabre_DAV_Exception_InsufficientStorage
+ * @dataProvider quotaExceededProvider
+ */
+ public function testCheckExceededQuota($quota, $headers)
+ {
+ $this->plugin->fileView = $this->buildFileViewMock($quota);
+
+ $this->server->httpRequest = new Sabre_HTTP_Request($headers);
+ $this->plugin->checkQuota('');
+ }
+
+ public function quotaOkayProvider() {
+ return array(
+ array(1024, array()),
+ array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
+ array(1024, array('HTTP_CONTENT_LENGTH' => '512')),
+ array(1024, array('HTTP_OC_TOTAL_LENGTH' => '1024', 'HTTP_CONTENT_LENGTH' => '512')),
+ // OC\Files\FREE_SPACE_UNKNOWN = -2
+ array(-2, array()),
+ array(-2, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
+ array(-2, array('HTTP_CONTENT_LENGTH' => '512')),
+ array(-2, array('HTTP_OC_TOTAL_LENGTH' => '1024', 'HTTP_CONTENT_LENGTH' => '512')),
+ );
+ }
+
+ public function quotaExceededProvider() {
+ return array(
+ array(1023, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
+ array(511, array('HTTP_CONTENT_LENGTH' => '512')),
+ array(2047, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')),
+ );
+ }
+
+ public function lengthProvider() {
+ return array(
+ array(null, array()),
+ array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
+ array(512, array('HTTP_CONTENT_LENGTH' => '512')),
+ array(2048, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')),
+ array(4096, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '4096')),
+ );
+ }
+
+ private function buildFileViewMock($quota) {
+ // mock filesysten
+ $view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', FALSE);
+ $view->expects($this->any())->method('free_space')->withAnyParameters()->will($this->returnValue($quota));
+
+ return $view;
+ }
+
+}
diff --git a/tests/lib/group/group.php b/tests/lib/group/group.php
index 75e975d9e65..f1fda3b9288 100644
--- a/tests/lib/group/group.php
+++ b/tests/lib/group/group.php
@@ -43,8 +43,8 @@ class Group extends \PHPUnit_Framework_TestCase {
$users = $group->getUsers();
$this->assertEquals(2, count($users));
- $user1 = $users[0];
- $user2 = $users[1];
+ $user1 = $users['user1'];
+ $user2 = $users['user2'];
$this->assertEquals('user1', $user1->getUID());
$this->assertEquals('user2', $user2->getUID());
}
@@ -68,9 +68,9 @@ class Group extends \PHPUnit_Framework_TestCase {
$users = $group->getUsers();
$this->assertEquals(3, count($users));
- $user1 = $users[0];
- $user2 = $users[1];
- $user3 = $users[2];
+ $user1 = $users['user1'];
+ $user2 = $users['user2'];
+ $user3 = $users['user3'];
$this->assertEquals('user1', $user1->getUID());
$this->assertEquals('user2', $user2->getUID());
$this->assertEquals('user3', $user3->getUID());
diff --git a/tests/lib/image.php b/tests/lib/image.php
index 0583c300075..4aba1b0bc61 100644
--- a/tests/lib/image.php
+++ b/tests/lib/image.php
@@ -7,6 +7,10 @@
*/
class Test_Image extends PHPUnit_Framework_TestCase {
+ public static function tearDownAfterClass() {
+ unlink(OC::$SERVERROOT.'/tests/data/testimage2.png');
+ unlink(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
+ }
public function testGetMimeTypeForFile() {
$mimetype = \OC_Image::getMimeTypeForFile(OC::$SERVERROOT.'/tests/data/testimage.png');
@@ -55,7 +59,6 @@ class Test_Image extends PHPUnit_Framework_TestCase {
}
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());
@@ -102,35 +105,50 @@ class Test_Image extends PHPUnit_Framework_TestCase {
$img->resize(16);
$img->save(OC::$SERVERROOT.'/tests/data/testimage2.png');
$this->assertEquals(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage2.png'), $img->data());
+
+ $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
+ $img->resize(128);
+ $img->save(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
+ $this->assertEquals(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage2.jpg'), $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');
+ $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png'));
+ ob_start();
+ imagepng($raw);
+ $expected = ob_get_clean();
$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');
+ $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ ob_start();
+ imagejpeg($raw);
+ $expected = ob_get_clean();
$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');
+ $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'));
+ ob_start();
+ imagegif($raw);
+ $expected = ob_get_clean();
$this->assertEquals($expected, $img->data());
}
+ /**
+ * @depends testData
+ */
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'));
+ $expected = base64_encode($img->data());
$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'));
+ $expected = base64_encode($img->data());
$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'));
+ $expected = base64_encode($img->data());
$this->assertEquals($expected, (string)$img);
}
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
new file mode 100644
index 00000000000..bebdc12b500
--- /dev/null
+++ b/tests/lib/preview.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke <georg@ownCloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test;
+
+class Preview extends \PHPUnit_Framework_TestCase {
+
+ public function testIsPreviewDeleted() {
+ $user = $this->initFS();
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $samplefile = '/'.$user.'/files/test.txt';
+
+ $rootView->file_put_contents($samplefile, 'dummy file data');
+
+ $x = 50;
+ $y = 50;
+
+ $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y);
+ $preview->getPreview();
+
+ $fileinfo = $rootView->getFileInfo($samplefile);
+ $fileid = $fileinfo['fileid'];
+
+ $thumbcachefile = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $x . '-' . $y . '.png';
+
+ $this->assertEquals($rootView->file_exists($thumbcachefile), true);
+
+ $preview->deletePreview();
+
+ $this->assertEquals($rootView->file_exists($thumbcachefile), false);
+ }
+
+ public function testAreAllPreviewsDeleted() {
+ $user = $this->initFS();
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $samplefile = '/'.$user.'/files/test.txt';
+
+ $rootView->file_put_contents($samplefile, 'dummy file data');
+
+ $x = 50;
+ $y = 50;
+
+ $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y);
+ $preview->getPreview();
+
+ $fileinfo = $rootView->getFileInfo($samplefile);
+ $fileid = $fileinfo['fileid'];
+
+ $thumbcachefolder = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/';
+
+ $this->assertEquals($rootView->is_dir($thumbcachefolder), true);
+
+ $preview->deleteAllPreviews();
+
+ $this->assertEquals($rootView->is_dir($thumbcachefolder), false);
+ }
+
+ public function testIsMaxSizeWorking() {
+ $user = $this->initFS();
+
+ $maxX = 250;
+ $maxY = 250;
+
+ \OC_Config::setValue('preview_max_x', $maxX);
+ \OC_Config::setValue('preview_max_y', $maxY);
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $samplefile = '/'.$user.'/files/test.txt';
+
+ $rootView->file_put_contents($samplefile, 'dummy file data');
+
+ $preview = new \OC\Preview($user, 'files/', 'test.txt', 1000, 1000);
+ $image = $preview->getPreview();
+
+ $this->assertEquals($image->width(), $maxX);
+ $this->assertEquals($image->height(), $maxY);
+ }
+
+ private function initFS() {
+ if(\OC\Files\Filesystem::getView()){
+ $user = \OC_User::getUser();
+ }else{
+ $user=uniqid();
+ \OC_User::setUserId($user);
+ \OC\Files\Filesystem::init($user, '/'.$user.'/files');
+ }
+
+ \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
+
+ return $user;
+ }
+} \ No newline at end of file