summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/cache/apc.php35
-rw-r--r--tests/lib/cache/xcache.php31
-rw-r--r--tests/lib/config.php85
-rw-r--r--tests/lib/helper.php60
-rw-r--r--tests/lib/memcache/apc.php20
-rw-r--r--tests/lib/memcache/cache.php58
-rw-r--r--tests/lib/memcache/memcached.php20
-rw-r--r--tests/lib/memcache/xcache.php20
8 files changed, 263 insertions, 66 deletions
diff --git a/tests/lib/cache/apc.php b/tests/lib/cache/apc.php
deleted file mode 100644
index bb5eb483dbf..00000000000
--- a/tests/lib/cache/apc.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
-* ownCloud
-*
-* @author Robin Appelman
-* @copyright 2012 Robin Appelman icewind@owncloud.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-class Test_Cache_APC extends Test_Cache {
- public function setUp() {
- if(!extension_loaded('apc')) {
- $this->markTestSkipped('The apc extension is not available.');
- return;
- }
- if(!ini_get('apc.enable_cli') && OC::$CLI) {
- $this->markTestSkipped('apc not available in CLI.');
- return;
- }
- $this->instance=new OC_Cache_APC();
- }
-}
diff --git a/tests/lib/cache/xcache.php b/tests/lib/cache/xcache.php
deleted file mode 100644
index 43bed2db037..00000000000
--- a/tests/lib/cache/xcache.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
-* ownCloud
-*
-* @author Robin Appelman
-* @copyright 2012 Robin Appelman icewind@owncloud.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-class Test_Cache_XCache extends Test_Cache {
- public function setUp() {
- if(!function_exists('xcache_get')) {
- $this->markTestSkipped('The xcache extension is not available.');
- return;
- }
- $this->instance=new OC_Cache_XCache();
- }
-}
diff --git a/tests/lib/config.php b/tests/lib/config.php
new file mode 100644
index 00000000000..c67a66c832e
--- /dev/null
+++ b/tests/lib/config.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Config extends PHPUnit_Framework_TestCase {
+ const CONFIG_FILE = 'static://config.php';
+ const CONFIG_DIR = 'static://';
+ const TESTCONTENT = '<?php $CONFIG=array("foo"=>"bar");';
+
+ /**
+ * @var \OC\Config
+ */
+ private $config;
+
+ function setUp() {
+ file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
+ $this->config = new OC\Config(self::CONFIG_DIR);
+ }
+
+ public function testReadData() {
+ $config = new OC\Config('/non-existing');
+ $this->assertAttributeEquals(array(), 'cache', $config);
+
+ $this->assertAttributeEquals(array('foo' => 'bar'), 'cache', $this->config);
+ }
+
+ public function testGetKeys() {
+ $this->assertEquals(array('foo'), $this->config->getKeys());
+ }
+
+ public function testGetValue() {
+ $this->assertEquals('bar', $this->config->getValue('foo'));
+ $this->assertEquals(null, $this->config->getValue('bar'));
+ $this->assertEquals('moo', $this->config->getValue('bar', 'moo'));
+ }
+
+ public function testSetValue() {
+ $this->config->setDebugMode(false);
+ $this->config->setValue('foo', 'moo');
+ $this->assertAttributeEquals(array('foo' => 'moo'), 'cache', $this->config);
+ $content = file_get_contents(self::CONFIG_FILE);
+
+ $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n);\n";
+ $this->assertEquals($expected, $content);
+ $this->config->setValue('bar', 'red');
+ $this->assertAttributeEquals(array('foo' => 'moo', 'bar' => 'red'), 'cache', $this->config);
+ $content = file_get_contents(self::CONFIG_FILE);
+
+ $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'bar' => 'red',\n);\n";
+ $this->assertEquals($expected, $content);
+ }
+
+ public function testDeleteKey() {
+ $this->config->setDebugMode(false);
+ $this->config->deleteKey('foo');
+ $this->assertAttributeEquals(array(), 'cache', $this->config);
+ $content = file_get_contents(self::CONFIG_FILE);
+
+ $expected = "<?php\n\$CONFIG = array (\n);\n";
+ $this->assertEquals($expected, $content);
+ }
+
+ public function testSavingDebugMode() {
+ $this->config->setDebugMode(true);
+ $this->config->deleteKey('foo'); // change something so we save to the config file
+ $this->assertAttributeEquals(array(), 'cache', $this->config);
+ $this->assertAttributeEquals(true, 'debugMode', $this->config);
+ $content = file_get_contents(self::CONFIG_FILE);
+
+ $expected = "<?php\ndefine('DEBUG',true);\n\$CONFIG = array (\n);\n";
+ $this->assertEquals($expected, $content);
+ }
+
+ /**
+ * @expectedException \OC\HintException
+ */
+ public function testWriteData() {
+ $config = new OC\Config('/non-writable');
+ $config->setValue('foo', 'bar');
+ }
+}
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 6acb0dfaa6b..67b5a3d43ec 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -146,4 +146,64 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
$result = OC_Helper::recursiveArraySearch($haystack, "NotFound");
$this->assertFalse($result);
}
+
+ function testBuildNotExistingFileNameForView() {
+ $viewMock = $this->getMock('\OC\Files\View', array(), array(), '', false);
+ $this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock));
+ $this->assertEquals('dir/filename.ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename.ext exists
+ $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename.ext exists
+ $viewMock->expects($this->at(1))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (2).ext exists
+ $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (1).ext exists
+ $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (2).ext exists
+ $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (2).ext exists
+ $viewMock->expects($this->at(1))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (3).ext exists
+ $this->assertEquals('dir/filename (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1).ext exists
+ $this->assertEquals('dir/filename(2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (1).ext exists
+ $this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (1).ext exists
+ $viewMock->expects($this->at(1))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (2).ext exists
+ $this->assertEquals('dir/filename(1) (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (2) (3).ext exists
+ $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
+ }
}
diff --git a/tests/lib/memcache/apc.php b/tests/lib/memcache/apc.php
new file mode 100644
index 00000000000..6b2a49470ba
--- /dev/null
+++ b/tests/lib/memcache/apc.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 APC extends Cache {
+ public function setUp() {
+ if(!\OC\Memcache\APC::isAvailable()) {
+ $this->markTestSkipped('The apc extension is not available.');
+ return;
+ }
+ $this->instance=new \OC\Memcache\APC(uniqid());
+ }
+}
diff --git a/tests/lib/memcache/cache.php b/tests/lib/memcache/cache.php
new file mode 100644
index 00000000000..d07c492cef0
--- /dev/null
+++ b/tests/lib/memcache/cache.php
@@ -0,0 +1,58 @@
+<?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;
+
+abstract class Cache extends \Test_Cache {
+ public function testExistsAfterSet() {
+ $this->assertFalse($this->instance->hasKey('foo'));
+ $this->instance->set('foo', 'bar');
+ $this->assertTrue($this->instance->hasKey('foo'));
+ }
+
+ public function testGetAfterSet() {
+ $this->assertNull($this->instance->get('foo'));
+ $this->instance->set('foo', 'bar');
+ $this->assertEquals('bar', $this->instance->get('foo'));
+ }
+
+ public function testDoesNotExistAfterRemove() {
+ $this->instance->set('foo', 'bar');
+ $this->instance->remove('foo');
+ $this->assertFalse($this->instance->hasKey('foo'));
+ }
+
+ public function testArrayAccessSet() {
+ $this->instance['foo'] = 'bar';
+ $this->assertEquals('bar', $this->instance->get('foo'));
+ }
+
+ public function testArrayAccessGet() {
+ $this->instance->set('foo', 'bar');
+ $this->assertEquals('bar', $this->instance['foo']);
+ }
+
+ public function testArrayAccessExists() {
+ $this->assertFalse(isset($this->instance['foo']));
+ $this->instance->set('foo', 'bar');
+ $this->assertTrue(isset($this->instance['foo']));
+ }
+
+ public function testArrayAccessUnset() {
+ $this->instance->set('foo', 'bar');
+ unset($this->instance['foo']);
+ $this->assertFalse($this->instance->hasKey('foo'));
+ }
+
+ public function tearDown() {
+ if ($this->instance) {
+ $this->instance->clear();
+ }
+ }
+}
diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php
new file mode 100644
index 00000000000..4b38ae8ef3c
--- /dev/null
+++ b/tests/lib/memcache/memcached.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 Memcached extends Cache {
+ public function setUp() {
+ if (!\OC\Memcache\Memcached::isAvailable()) {
+ $this->markTestSkipped('The memcached extension is not available.');
+ return;
+ }
+ $this->instance = new \OC\Memcache\Memcached(uniqid());
+ }
+}
diff --git a/tests/lib/memcache/xcache.php b/tests/lib/memcache/xcache.php
new file mode 100644
index 00000000000..f59afda3966
--- /dev/null
+++ b/tests/lib/memcache/xcache.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 XCache extends Cache {
+ public function setUp() {
+ if (!\OC\Memcache\XCache::isAvailable()) {
+ $this->markTestSkipped('The xcache extension is not available.');
+ return;
+ }
+ $this->instance = new \OC\Memcache\XCache(uniqid());
+ }
+}