From 80a3f8d066b7deffe70a232ca956746db02db138 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 17 Mar 2013 16:00:39 +0100 Subject: Seperate memory based cache from OC_Cache --- tests/lib/cache/apc.php | 35 ----------------------------------- tests/lib/cache/xcache.php | 31 ------------------------------- tests/lib/memcache/apc.php | 31 +++++++++++++++++++++++++++++++ tests/lib/memcache/xcache.php | 31 +++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 66 deletions(-) delete mode 100644 tests/lib/cache/apc.php delete mode 100644 tests/lib/cache/xcache.php create mode 100644 tests/lib/memcache/apc.php create mode 100644 tests/lib/memcache/xcache.php (limited to 'tests') 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 @@ -. -* -*/ - -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 @@ -. -* -*/ - -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/memcache/apc.php b/tests/lib/memcache/apc.php new file mode 100644 index 00000000000..e3dccc09669 --- /dev/null +++ b/tests/lib/memcache/apc.php @@ -0,0 +1,31 @@ +. +* +*/ + +class Test_Memcache_APC extends Test_Cache { + public function setUp() { + if(!\OC\Memcache\APC::isAvailable()) { + $this->markTestSkipped('The apc extension is not available.'); + return; + } + $this->instance=new \OC\Memcache\APC(); + } +} diff --git a/tests/lib/memcache/xcache.php b/tests/lib/memcache/xcache.php new file mode 100644 index 00000000000..48773533c89 --- /dev/null +++ b/tests/lib/memcache/xcache.php @@ -0,0 +1,31 @@ +. + * + */ + +class Test_Memcache_XCache extends Test_Cache { + public function setUp() { + if (!\OC\Memcache\XCache::isAvailable()) { + $this->markTestSkipped('The xcache extension is not available.'); + return; + } + $this->instance = new \OC\Memcache\XCache(); + } +} -- cgit v1.2.3 From 5418c98a81caba2da00b2e81fb56fe373737a7c8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 17 Mar 2013 16:01:10 +0100 Subject: Add memcached backend --- lib/memcache/cache.php | 6 ++- lib/memcache/memcached.php | 81 ++++++++++++++++++++++++++++++++++++++++ tests/lib/memcache/memcached.php | 17 +++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 lib/memcache/memcached.php create mode 100644 tests/lib/memcache/memcached.php (limited to 'tests') diff --git a/lib/memcache/cache.php b/lib/memcache/cache.php index d77ea27933f..331c689f065 100644 --- a/lib/memcache/cache.php +++ b/lib/memcache/cache.php @@ -20,6 +20,8 @@ abstract class Cache { return new XCache($global); } elseif (APC::isAvailable()) { return new APC($global); + } elseif (Memcached::isAvailable()) { + return new Memcached($global); } else { return null; } @@ -65,5 +67,7 @@ abstract class Cache { /** * @return bool */ - //static public function isAvailable(); + static public function isAvailable() { + return XCache::isAvailable() || APC::isAvailable() || Memcached::isAvailable(); + } } diff --git a/lib/memcache/memcached.php b/lib/memcache/memcached.php new file mode 100644 index 00000000000..ab35bd8bbac --- /dev/null +++ b/lib/memcache/memcached.php @@ -0,0 +1,81 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Memcache; + +class Memcached extends Cache { + protected $prefix; + + /** + * @var \Memcached $cache + */ + private static $cache = null; + + public function __construct($global = false) { + $this->prefix = \OC_Util::getInstanceId() . '/'; + if (!$global) { + $this->prefix .= \OC_User::getUser() . '/'; + } + if (is_null(self::$cache)) { + self::$cache = new \Memcached(); + list($host, $port) = \OC_Config::getValue('memcached_server', array('localhost', 11211)); + self::$cache->addServer($host, $port); + } + } + + /** + * entries in XCache gets namespaced to prevent collisions between owncloud instances and users + */ + protected function getNameSpace() { + return $this->prefix; + } + + public function get($key) { + $result = self::$cache->get($this->getNamespace() . $key); + if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { + return null; + } else { + return $result; + } + } + + public function set($key, $value, $ttl = 0) { + if ($ttl > 0) { + return self::$cache->set($this->getNamespace() . $key, $value, $ttl); + } else { + return self::$cache->set($this->getNamespace() . $key, $value); + } + } + + public function hasKey($key) { + self::$cache->get($this->getNamespace() . $key); + return self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND; + } + + public function remove($key) { + return self::$cache->delete($this->getNamespace() . $key); + } + + public function clear($prefix = '') { + $prefix = $this->getNamespace() . $prefix; + $allKeys = self::$cache->getAllKeys(); + $keys = array(); + $prefixLength = strlen($prefix); + foreach ($allKeys as $key) { + if (substr($key, 0, $prefixLength) === $prefix) { + $keys[] = $key; + } + } + self::$cache->deleteMulti($keys); + return true; + } + + static public function isAvailable() { + return extension_loaded('memcached'); + } +} diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php new file mode 100644 index 00000000000..a0be047ed1f --- /dev/null +++ b/tests/lib/memcache/memcached.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_Memcache_Memcached extends Test_Cache { + public function setUp() { + if (!\OC\Memcache\Memcached::isAvailable()) { + $this->markTestSkipped('The memcached extension is not available.'); + return; + } + $this->instance = new \OC\Memcache\Memcached(); + } +} -- cgit v1.2.3 From 07df94def66a78bda40560a5bdd31058f61e2238 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 3 Mar 2013 12:06:00 +0100 Subject: Convert OC_Config to object interface --- lib/config.php | 111 ++++++++++++++++++++++--------------------------- lib/hintexception.php | 27 ++++++++++++ lib/legacy/config.php | 98 +++++++++++++++++++++++++++++++++++++++++++ lib/setup.php | 16 +------ tests/lib/config.php | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 288 insertions(+), 77 deletions(-) create mode 100644 lib/hintexception.php create mode 100644 lib/legacy/config.php create mode 100644 tests/lib/config.php (limited to 'tests') diff --git a/lib/config.php b/lib/config.php index 9b87d4ce4e5..dcc659395a7 100644 --- a/lib/config.php +++ b/lib/config.php @@ -34,17 +34,27 @@ * */ +namespace OC; + /** * This class is responsible for reading and writing config.php, the very basic * configuration file of owncloud. */ -class OC_Config{ +class Config { // associative array key => value - private static $cache = array(); + protected $cache = array(); + + protected $config_dir; + protected $config_filename; - // Is the cache filled? - private static $init = false; + protected $debug_mode; + public function __construct($config_dir, $debug_mode) { + $this->config_dir = $config_dir; + $this->debug_mode = $debug_mode; + $this->config_filename = $this->config_dir.'config.php'; + $this->readData(); + } /** * @brief Lists all available config keys * @return array with key names @@ -52,10 +62,8 @@ class OC_Config{ * This function returns all keys saved in config.php. Please note that it * does not return the values. */ - public static function getKeys() { - self::readData(); - - return array_keys( self::$cache ); + public function getKeys() { + return array_keys( $this->cache ); } /** @@ -67,11 +75,9 @@ class OC_Config{ * This function gets the value from config.php. If it does not exist, * $default will be returned. */ - public static function getValue( $key, $default = null ) { - self::readData(); - - if( array_key_exists( $key, self::$cache )) { - return self::$cache[$key]; + public function getValue( $key, $default = null ) { + if( array_key_exists( $key, $this->cache )) { + return $this->cache[$key]; } return $default; @@ -81,57 +87,43 @@ class OC_Config{ * @brief Sets a value * @param string $key key * @param string $value value - * @return bool * * This function sets the value and writes the config.php. If the file can * not be written, false will be returned. */ - public static function setValue( $key, $value ) { - self::readData(); - + public function setValue( $key, $value ) { // Add change - self::$cache[$key] = $value; + $this->cache[$key] = $value; // Write changes - self::writeData(); - return true; + $this->writeData(); } /** * @brief Removes a key from the config * @param string $key key - * @return bool * * This function removes a key from the config.php. If owncloud has no * write access to config.php, the function will return false. */ - public static function deleteKey( $key ) { - self::readData(); - - if( array_key_exists( $key, self::$cache )) { + public function deleteKey( $key ) { + if( array_key_exists( $key, $this->cache )) { // Delete key from cache - unset( self::$cache[$key] ); + unset( $this->cache[$key] ); // Write changes - self::writeData(); + $this->writeData(); } - - return true; } /** * @brief Loads the config file - * @return bool * * Reads the config file and saves it to the cache */ - private static function readData() { - if( self::$init ) { - return true; - } - + private function readData() { // read all file in config dir ending by config.php - $config_files = glob( OC::$SERVERROOT."/config/*.config.php"); + $config_files = glob( $this->config_dir.'*.config.php'); //Filter only regular files $config_files = array_filter($config_files, 'is_file'); @@ -140,54 +132,49 @@ class OC_Config{ natsort($config_files); // Add default config - array_unshift($config_files,OC::$SERVERROOT."/config/config.php"); + array_unshift($config_files, $this->config_filename); //Include file and merge config - foreach($config_files as $file){ + foreach($config_files as $file) { + if( !file_exists( $file) ) { + continue; + } + unset($CONFIG); include $file; if( isset( $CONFIG ) && is_array( $CONFIG )) { - self::$cache = array_merge(self::$cache, $CONFIG); + $this->cache = array_merge($this->cache, $CONFIG); } } - - // We cached everything - self::$init = true; - - return true; } /** * @brief Writes the config file - * @return bool * * Saves the config to the config file. * */ - public static function writeData() { + private function writeData() { // Create a php file ... - $content = "debug_mode) { $content .= "define('DEBUG',true);\n"; } - $content .= "\$CONFIG = "; - $content .= var_export(self::$cache, true); + $content .= '$CONFIG = '; + $content .= var_export($this->cache, true); $content .= ";\n"; + //var_dump($content, $this); - $filename = OC::$SERVERROOT."/config/config.php"; // Write the file - $result=@file_put_contents( $filename, $content ); + $result=@file_put_contents( $this->config_filename, $content ); if(!$result) { - $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors', array(1=>array( - 'error'=>"Can't write into config directory 'config'", - 'hint'=>'You can usually fix this by giving the webserver user write access' - .' to the config directory in owncloud'))); - $tmpl->printPage(); - exit; + throw new HintException( + "Can't write into config directory 'config'", + 'You can usually fix this by giving the webserver user write access' + .' to the config directory in owncloud'); } // Prevent others not to read the config - @chmod($filename, 0640); - - return true; + @chmod($this->config_filename, 0640); } } + +require_once __DIR__.'/legacy/'.basename(__FILE__); diff --git a/lib/hintexception.php b/lib/hintexception.php new file mode 100644 index 00000000000..8c64258435b --- /dev/null +++ b/lib/hintexception.php @@ -0,0 +1,27 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC; + +class HintException extends \Exception +{ + private $hint; + + public function __construct($message, $hint, $code = 0, Exception $previous = null) { + $this->hint = $hint; + parent::__construct($message, $code, $previous); + } + + public function __toString() { + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; + } + + public function getHint() { + return $this->hint; + } +} diff --git a/lib/legacy/config.php b/lib/legacy/config.php new file mode 100644 index 00000000000..d030bbe3676 --- /dev/null +++ b/lib/legacy/config.php @@ -0,0 +1,98 @@ +. + * + */ +/* + * + * An example of config.php + * + * "mysql", + * "firstrun" => false, + * "pi" => 3.14 + * ); + * ?> + * + */ + +/** + * This class is responsible for reading and writing config.php, the very basic + * configuration file of owncloud. + */ +OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG); +class OC_Config{ + public static $object; + /** + * @brief Lists all available config keys + * @return array with key names + * + * This function returns all keys saved in config.php. Please note that it + * does not return the values. + */ + public static function getKeys() { + return self::$object->getKeys(); + } + + /** + * @brief Gets a value from config.php + * @param string $key key + * @param string $default = null default value + * @return string the value or $default + * + * This function gets the value from config.php. If it does not exist, + * $default will be returned. + */ + public static function getValue( $key, $default = null ) { + return self::$object->getValue( $key, $default ); + } + + /** + * @brief Sets a value + * @param string $key key + * @param string $value value + * + * This function sets the value and writes the config.php. If the file can + * not be written, false will be returned. + */ + public static function setValue( $key, $value ) { + try { + self::$object->setValue( $key, $value ); + } catch (\OC\HintException $e) { + \OC_Template::printErrorPage( $e->getMessage(), $e->getHint() ); + } + } + + /** + * @brief Removes a key from the config + * @param string $key key + * + * This function removes a key from the config.php. If owncloud has no + * write access to config.php, the function will return false. + */ + public static function deleteKey( $key ) { + try { + self::$object->deleteKey( $key ); + } catch (\OC\HintException $e) { + \OC_Template::printErrorPage( $e->getMessage(), $e->getHint() ); + } + } +} diff --git a/lib/setup.php b/lib/setup.php index d1197b3ebf3..e05db554320 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -1,21 +1,7 @@ hint = $hint; - parent::__construct($message, $code, $previous); - } - - public function __toString() { - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; - } - - public function getHint() { - return $this->hint; - } } class OC_Setup { diff --git a/tests/lib/config.php b/tests/lib/config.php new file mode 100644 index 00000000000..e22bf3fd7de --- /dev/null +++ b/tests/lib/config.php @@ -0,0 +1,113 @@ + + * 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 = '"bar");'; + + public function testReadData() + { + $config = new OC\Config(self::CONFIG_DIR, false); + $this->assertAttributeEquals(array(), 'cache', $config); + + file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); + $config = new OC\Config(self::CONFIG_DIR, false); + $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config); + } + + public function testGetKeys() + { + file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); + $config = new OC\Config(self::CONFIG_DIR, false); + $this->assertEquals(array('foo'), $config->getKeys()); + } + + public function testGetValue() + { + file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); + $config = new OC\Config(self::CONFIG_DIR, false); + $this->assertEquals('bar', $config->getValue('foo')); + $this->assertEquals(null, $config->getValue('bar')); + $this->assertEquals('moo', $config->getValue('bar', 'moo')); + } + + public function testSetValue() + { + file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); + $config = new OC\Config(self::CONFIG_DIR, false); + $config->setValue('foo', 'moo'); + $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config); + $content = file_get_contents(self::CONFIG_FILE); + $this->assertEquals(<< 'moo', +); + +EOL +, $content); + $config->setValue('bar', 'red'); + $this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $config); + $content = file_get_contents(self::CONFIG_FILE); + $this->assertEquals(<< 'moo', + 'bar' => 'red', +); + +EOL +, $content); + } + + public function testDeleteKey() + { + file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); + $config = new OC\Config(self::CONFIG_DIR, false); + $config->deleteKey('foo'); + $this->assertAttributeEquals(array(), 'cache', $config); + $content = file_get_contents(self::CONFIG_FILE); + $this->assertEquals(<<deleteKey('foo'); // change something so we save to the config file + $this->assertAttributeEquals(array(), 'cache', $config); + $this->assertAttributeEquals(true, 'debug_mode', $config); + $content = file_get_contents(self::CONFIG_FILE); + $this->assertEquals(<<setValue('foo', 'bar'); + } catch (\OC\HintException $e) { + return; + } + $this->fail(); + } +} -- cgit v1.2.3 From 969e43c87b7afb6184846fe27849167c9c6f5eab Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 10 Jun 2013 12:07:25 -0400 Subject: Can't determine if debug mode is defined until we read the config --- lib/config.php | 9 +++------ lib/legacy/config.php | 2 +- tests/lib/config.php | 18 +++++++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/lib/config.php b/lib/config.php index 4003339ea5c..a3663949d16 100644 --- a/lib/config.php +++ b/lib/config.php @@ -47,11 +47,8 @@ class Config { protected $configDir; protected $configFilename; - protected $debugMode; - - public function __construct($configDir, $debugMode) { + public function __construct($configDir) { $this->configDir = $configDir; - $this->debugMode = $debugMode; $this->configFilename = $this->configDir.'config.php'; $this->readData(); } @@ -152,7 +149,7 @@ class Config { private function writeData() { // Create a php file ... $content = "debugMode) { + if (defined('DEBUG') && DEBUG) { $content .= "define('DEBUG',true);\n"; } $content .= '$CONFIG = '; @@ -167,7 +164,7 @@ class Config { 'You can usually fix this by giving the webserver user write access' .' to the config directory in ownCloud'); } - // Prevent others not to read the config + // Prevent others from reading the config @chmod($this->configFilename, 0640); } } diff --git a/lib/legacy/config.php b/lib/legacy/config.php index 635f0af66f8..f68d7c31b25 100644 --- a/lib/legacy/config.php +++ b/lib/legacy/config.php @@ -38,7 +38,7 @@ * This class is responsible for reading and writing config.php, the very basic * configuration file of ownCloud. */ -OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG); +OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/'); class OC_Config { public static $object; diff --git a/tests/lib/config.php b/tests/lib/config.php index e22bf3fd7de..acc2a536fd0 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -13,25 +13,25 @@ class Test_Config extends PHPUnit_Framework_TestCase { public function testReadData() { - $config = new OC\Config(self::CONFIG_DIR, false); + $config = new OC\Config(self::CONFIG_DIR); $this->assertAttributeEquals(array(), 'cache', $config); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); + $config = new OC\Config(self::CONFIG_DIR); $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config); } public function testGetKeys() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); + $config = new OC\Config(self::CONFIG_DIR); $this->assertEquals(array('foo'), $config->getKeys()); } public function testGetValue() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); + $config = new OC\Config(self::CONFIG_DIR); $this->assertEquals('bar', $config->getValue('foo')); $this->assertEquals(null, $config->getValue('bar')); $this->assertEquals('moo', $config->getValue('bar', 'moo')); @@ -40,7 +40,7 @@ class Test_Config extends PHPUnit_Framework_TestCase { public function testSetValue() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); + $config = new OC\Config(self::CONFIG_DIR); $config->setValue('foo', 'moo'); $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config); $content = file_get_contents(self::CONFIG_FILE); @@ -69,7 +69,7 @@ EOL public function testDeleteKey() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); + $config = new OC\Config(self::CONFIG_DIR); $config->deleteKey('foo'); $this->assertAttributeEquals(array(), 'cache', $config); $content = file_get_contents(self::CONFIG_FILE); @@ -84,11 +84,11 @@ EOL public function testSavingDebugMode() { + define('DEBUG',true); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, true); + $config = new OC\Config(self::CONFIG_DIR); $config->deleteKey('foo'); // change something so we save to the config file $this->assertAttributeEquals(array(), 'cache', $config); - $this->assertAttributeEquals(true, 'debug_mode', $config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<setValue('foo', 'bar'); } catch (\OC\HintException $e) { -- cgit v1.2.3 From 6887d7daf5f0dfcd2f1da0d9c8f796a4fcc29963 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 23da0c7d188b4c0a119e16c5be48ce322df29068 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 24 Jun 2013 17:46:51 +0200 Subject: Fix tableExists test function for Oracle --- tests/lib/dbschema.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 59f203993ef..813112f1fe5 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -102,9 +102,10 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { $exists = $result && $result->fetchOne(); break; case 'oci': - $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 + $sql = "SELECT table_name FROM user_tables WHERE table_name = '{$table}'"; + $query = OC_DB::prepare($sql); + $result = $query->execute(array()); + $exists = $result && $result->fetchOne(); break; case 'mssql': $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; -- cgit v1.2.3 From eb9078407437f275687e31c9bd7486f469ffa978 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 12 Jun 2013 18:51:59 +0200 Subject: Fix table change tests for OCI --- tests/data/db_structure2.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (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 -- cgit v1.2.3 From b980987e32270fc416eefc87f7e163763cab2776 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 21 Jun 2013 12:04:52 +0200 Subject: Doctrine only returns false --- tests/lib/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/db.php b/tests/lib/db.php index afbdb413c3d..60331a23295 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -37,7 +37,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); $row = $result->fetchRow(); - $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null + $this->assertFalse($row); $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(array('fullname test', 'uri_1')); $this->assertTrue((bool)$result); -- cgit v1.2.3 From 769212a9a025a58a5b2189eb2461a01e0ece6d36 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 24 Jun 2013 18:15:02 +0200 Subject: numRows doesn't work with Oracle --- tests/lib/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/db.php b/tests/lib/db.php index 60331a23295..18b7340ec9b 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -94,7 +94,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table3.'`'); $result = $query->execute(); $this->assertTrue((bool)$result); - $this->assertEquals('4', $result->numRows()); + $this->assertEquals('4', count($result->fetchAll())); } public function testinsertIfNotExistDontOverwrite() { -- cgit v1.2.3 From 0c680b46cdfe5106d87ad807657c9d2e558b4a73 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 26 Jun 2013 20:48:54 +0200 Subject: View test needs a dummy user --- tests/lib/files/view.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 830913a91ad..3bac9e770aa 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -20,10 +20,19 @@ class View extends \PHPUnit_Framework_TestCase { private $storages = array(); public function setUp() { + \OC_User::clearBackends(); + \OC_User::useBackend(new \OC_User_Dummy()); + + //login + \OC_User::createUser('test', 'test'); + $this->user=\OC_User::getUser(); + \OC_User::setUserId('test'); + \OC\Files\Filesystem::clearMounts(); } public function tearDown() { + \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); -- cgit v1.2.3 From 194b61b4c507e58eab0750ab40ed6eb6f085c06a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 27 Jun 2013 22:24:17 +0200 Subject: Revert "Can't determine if debug mode is defined until we read the config" This reverts commit 969e43c87b7afb6184846fe27849167c9c6f5eab. --- lib/config.php | 9 ++++++--- lib/legacy/config.php | 2 +- tests/lib/config.php | 18 +++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/lib/config.php b/lib/config.php index 7ccbc050508..adf70ac841a 100644 --- a/lib/config.php +++ b/lib/config.php @@ -47,8 +47,11 @@ class Config { protected $configDir; protected $configFilename; - public function __construct($configDir) { + protected $debugMode; + + public function __construct($configDir, $debugMode) { $this->configDir = $configDir; + $this->debugMode = $debugMode; $this->configFilename = $this->configDir.'config.php'; $this->readData(); } @@ -149,7 +152,7 @@ class Config { private function writeData() { // Create a php file ... $content = "debugMode) { $content .= "define('DEBUG',true);\n"; } $content .= '$CONFIG = '; @@ -164,7 +167,7 @@ class Config { 'You can usually fix this by giving the webserver user write access' .' to the config directory in ownCloud'); } - // Prevent others from reading the config + // Prevent others not to read the config @chmod($this->configFilename, 0640); \OC_Util::clearOpcodeCache(); } diff --git a/lib/legacy/config.php b/lib/legacy/config.php index f68d7c31b25..635f0af66f8 100644 --- a/lib/legacy/config.php +++ b/lib/legacy/config.php @@ -38,7 +38,7 @@ * This class is responsible for reading and writing config.php, the very basic * configuration file of ownCloud. */ -OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/'); +OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG); class OC_Config { public static $object; diff --git a/tests/lib/config.php b/tests/lib/config.php index acc2a536fd0..e22bf3fd7de 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -13,25 +13,25 @@ class Test_Config extends PHPUnit_Framework_TestCase { public function testReadData() { - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, false); $this->assertAttributeEquals(array(), 'cache', $config); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, false); $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config); } public function testGetKeys() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, false); $this->assertEquals(array('foo'), $config->getKeys()); } public function testGetValue() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, false); $this->assertEquals('bar', $config->getValue('foo')); $this->assertEquals(null, $config->getValue('bar')); $this->assertEquals('moo', $config->getValue('bar', 'moo')); @@ -40,7 +40,7 @@ class Test_Config extends PHPUnit_Framework_TestCase { public function testSetValue() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, false); $config->setValue('foo', 'moo'); $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config); $content = file_get_contents(self::CONFIG_FILE); @@ -69,7 +69,7 @@ EOL public function testDeleteKey() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, false); $config->deleteKey('foo'); $this->assertAttributeEquals(array(), 'cache', $config); $content = file_get_contents(self::CONFIG_FILE); @@ -84,11 +84,11 @@ EOL public function testSavingDebugMode() { - define('DEBUG',true); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR); + $config = new OC\Config(self::CONFIG_DIR, true); $config->deleteKey('foo'); // change something so we save to the config file $this->assertAttributeEquals(array(), 'cache', $config); + $this->assertAttributeEquals(true, 'debug_mode', $config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<setValue('foo', 'bar'); } catch (\OC\HintException $e) { -- cgit v1.2.3 From 12976fb2e1f6a4d6a054ba2b620f0e7707ce2c69 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 27 Jun 2013 22:50:28 +0200 Subject: Set debugMode after reading the config file --- lib/config.php | 9 +++++++-- lib/legacy/config.php | 2 +- tests/lib/config.php | 50 ++++++++++++++++++++++---------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/lib/config.php b/lib/config.php index adf70ac841a..afd74c56b40 100644 --- a/lib/config.php +++ b/lib/config.php @@ -49,12 +49,17 @@ class Config { protected $debugMode; - public function __construct($configDir, $debugMode) { + public function __construct($configDir) { $this->configDir = $configDir; - $this->debugMode = $debugMode; $this->configFilename = $this->configDir.'config.php'; $this->readData(); + $this->setDebugMode(defined('DEBUG') && DEBUG); } + + public function setDebugMode($enable) { + $this->debugMode = $enable; + } + /** * @brief Lists all available config keys * @return array with key names diff --git a/lib/legacy/config.php b/lib/legacy/config.php index 635f0af66f8..f68d7c31b25 100644 --- a/lib/legacy/config.php +++ b/lib/legacy/config.php @@ -38,7 +38,7 @@ * This class is responsible for reading and writing config.php, the very basic * configuration file of ownCloud. */ -OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG); +OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/'); class OC_Config { public static $object; diff --git a/tests/lib/config.php b/tests/lib/config.php index e22bf3fd7de..8f52cf4ae76 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -11,38 +11,35 @@ class Test_Config extends PHPUnit_Framework_TestCase { const CONFIG_DIR = 'static://'; const TESTCONTENT = '"bar");'; + 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(self::CONFIG_DIR, false); + $config = new OC\Config('/non-existing'); $this->assertAttributeEquals(array(), 'cache', $config); - file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); - $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config); + $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $this->config); } public function testGetKeys() { - file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); - $this->assertEquals(array('foo'), $config->getKeys()); + $this->assertEquals(array('foo'), $this->config->getKeys()); } public function testGetValue() { - file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); - $this->assertEquals('bar', $config->getValue('foo')); - $this->assertEquals(null, $config->getValue('bar')); - $this->assertEquals('moo', $config->getValue('bar', 'moo')); + $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() { - file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); - $config = new OC\Config(self::CONFIG_DIR, false); - $config->setValue('foo', 'moo'); - $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config); + $this->config->setValue('foo', 'moo'); + $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<setValue('bar', 'red'); - $this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $config); + $this->config->setValue('bar', 'red'); + $this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<deleteKey('foo'); - $this->assertAttributeEquals(array(), 'cache', $config); + $this->config->deleteKey('foo'); + $this->assertAttributeEquals(array(), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<deleteKey('foo'); // change something so we save to the config file - $this->assertAttributeEquals(array(), 'cache', $config); - $this->assertAttributeEquals(true, 'debug_mode', $config); + $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); $this->assertEquals(<<setValue('foo', 'bar'); } catch (\OC\HintException $e) { -- cgit v1.2.3 From e789e056759aedb93d9eba3a8598acea67c842c6 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 2 Jul 2013 00:15:42 +0200 Subject: on unit test use @expectedException some phpdoc added --- lib/legacy/config.php | 3 +++ tests/lib/config.php | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/lib/legacy/config.php b/lib/legacy/config.php index f68d7c31b25..5294a48ea44 100644 --- a/lib/legacy/config.php +++ b/lib/legacy/config.php @@ -41,6 +41,9 @@ OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/'); class OC_Config { + /** + * @var \OC\Config + */ public static $object; /** diff --git a/tests/lib/config.php b/tests/lib/config.php index 8f52cf4ae76..c17d2ae7eff 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -11,6 +11,11 @@ class Test_Config extends PHPUnit_Framework_TestCase { const CONFIG_DIR = 'static://'; const TESTCONTENT = '"bar");'; + /** + * @var \OC\Config + */ + private $config; + function setUp() { file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); $this->config = new OC\Config(self::CONFIG_DIR); @@ -94,14 +99,12 @@ EOL , $content); } + /** + * @expectedException \OC\HintException + */ public function testWriteData() { $config = new OC\Config('/non-writable'); - try { - $config->setValue('foo', 'bar'); - } catch (\OC\HintException $e) { - return; - } - $this->fail(); + $config->setValue('foo', 'bar'); } } -- cgit v1.2.3 From 21601fd78448ede37bc6f55c9880fc27a4df9ae3 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:08:19 +0200 Subject: increasing difference for modifcation time tests one second is sometimes not enough when using a slow storage connection, three seconds is working better (at least when testing against S3) --- tests/lib/files/storage/storage.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index fb3e05e66b3..155a99d8bab 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -168,10 +168,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->isReadable('/lorem.txt')); $ctimeEnd = time(); $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 1)); - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 1)); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 3)); + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 3)); - $this->assertTrue(($ctimeStart - 1) <= $mTime); + $this->assertTrue(($ctimeStart - 3) <= $mTime); $this->assertTrue($mTime <= ($ctimeEnd + 1)); $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); @@ -185,10 +185,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $mtimeEnd = time(); if ($supportsTouch !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 1) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 1)); + $this->assertTrue(($mtimeStart - 3) <= $mTime); + $this->assertTrue($mTime <= ($mtimeEnd + 3)); - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 1)); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 3)); if ($this->instance->touch('/lorem.txt', 100) !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); @@ -203,11 +203,11 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { clearstatcache(); $mtimeEnd = time(); $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 1) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 1)); + $this->assertTrue(($mtimeStart - 3) <= $mTime); + $this->assertTrue($mTime <= ($mtimeEnd + 3)); $this->instance->unlink('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 1)); + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 3)); } public function testSearch() { -- cgit v1.2.3 From 81acfc9498d1451d7266dbad024cd3d29d7d0b1a Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:11:54 +0200 Subject: test copying and moving files in subdirectories --- tests/lib/files/storage/storage.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 155a99d8bab..4a3a0c40e08 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -129,6 +129,16 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->file_exists('/target2.txt')); $this->assertFalse($this->instance->file_exists('/source.txt')); $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target.txt')); + + // check if it's working inside directories as well + $this->instance->mkdir('/folder'); + $this->instance->file_put_contents('/folder/lorem.txt', $sourceText); + $this->assertFalse($this->instance->is_dir('/folder/lorem.txt')); + $this->assertEquals($sourceText, $this->instance->file_get_contents('/folder/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); + $this->instance->file_put_contents('/folder/lorem.txt', ''); + $this->assertEquals('', $this->instance->file_get_contents('/folder/lorem.txt'), 'file not emptied'); + $this->instance->rmdir('/folder'); + $this->assertFalse($this->instance->file_exists('/folder/lorem.txt')); } public function testLocal() { -- cgit v1.2.3 From e556b7ab5504a039553f92696be6124db51a2a39 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:16:50 +0200 Subject: test working with subdirectories --- tests/lib/files/storage/storage.php | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 4a3a0c40e08..e5cc9483871 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -79,6 +79,54 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { } } $this->assertEquals(array(), $content); + + $this->assertTrue($this->instance->mkdir('/folder')); + $this->assertTrue($this->instance->mkdir('/folder/sub_a')); + $this->assertTrue($this->instance->mkdir('/folder/sub_b')); + $this->assertTrue($this->instance->mkdir('/folder/sub_b/sub_bb')); + $this->assertTrue($this->instance->touch('/folder/sub_b/sub_bb/file.txt')); + $this->assertTrue($this->instance->touch('/folder/sub_a/file.txt')); + $this->assertTrue($this->instance->is_dir('/folder/sub_b')); + $this->assertTrue($this->instance->is_dir('/folder/sub_b/sub_bb')); + $this->assertTrue($this->instance->file_exists('/folder/sub_a/file.txt')); + $this->assertTrue($this->instance->file_exists('/folder/sub_b/sub_bb/file.txt')); + + $dh = $this->instance->opendir('/folder'); + $content = array(); + while ($file = readdir($dh)) { + if ($file != '.' and $file != '..') { + $content[] = $file; + } + } + $this->assertEquals(array('sub_a', 'sub_b'), $content); + + $dh = $this->instance->opendir('/folder/sub_b/sub_bb'); + $content = array(); + while ($file = readdir($dh)) { + if ($file != '.' and $file != '..') { + $content[] = $file; + } + } + $this->assertEquals(array('file.txt'), $content); + + $this->assertTrue($this->instance->rmdir('/folder/sub_b')); + $this->assertFalse($this->instance->is_dir('/folder/sub_b')); + $this->assertFalse($this->instance->is_dir('/folder/sub_b/sub_bb')); + $this->assertFalse($this->instance->file_exists('/folder/sub_b/sub_bb/file.txt')); + + $dh = $this->instance->opendir('/folder'); + $content = array(); + while ($file = readdir($dh)) { + if ($file != '.' and $file != '..') { + $content[] = $file; + } + } + $this->assertEquals(array('sub_a'), $content); + + $this->assertTrue($this->instance->rmdir('/folder')); + $this->assertFalse($this->instance->is_dir('/folder')); + $this->assertFalse($this->instance->is_dir('/folder/sub_a')); + $this->assertFalse($this->instance->file_exists('/folder/sub_a/file.txt')); } /** -- cgit v1.2.3 From 0a5e18335ec4fef9fc0ea7b6778628b7471962bd Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:23:09 +0200 Subject: test working with files in subdirectories --- tests/lib/files/storage/storage.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index e5cc9483871..8f6a8771ba8 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -127,6 +127,16 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->instance->is_dir('/folder')); $this->assertFalse($this->instance->is_dir('/folder/sub_a')); $this->assertFalse($this->instance->file_exists('/folder/sub_a/file.txt')); + + // check if it's working inside directories as well + $this->instance->mkdir('/folder'); + $this->instance->file_put_contents('/folder/lorem.txt', $sourceText); + $this->assertFalse($this->instance->is_dir('/folder/lorem.txt')); + $this->assertEquals($sourceText, $this->instance->file_get_contents('/folder/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); + $this->instance->file_put_contents('/folder/lorem.txt', ''); + $this->assertEquals('', $this->instance->file_get_contents('/folder/lorem.txt'), 'file not emptied'); + $this->instance->rmdir('/folder'); + $this->assertFalse($this->instance->file_exists('/folder/lorem.txt')); } /** -- cgit v1.2.3 From 407753f59402c7377db1d1badbf198616a1ac563 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:34:33 +0200 Subject: move new tests into the correct test method --- tests/lib/files/storage/storage.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 8f6a8771ba8..771fad8c61b 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -154,6 +154,16 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { //empty the file $this->instance->file_put_contents('/lorem.txt', ''); $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied'); + + // check if it's working inside directories as well + $this->instance->mkdir('/folder'); + $this->instance->file_put_contents('/folder/lorem.txt', $sourceText); + $this->assertFalse($this->instance->is_dir('/folder/lorem.txt')); + $this->assertEquals($sourceText, $this->instance->file_get_contents('/folder/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); + $this->instance->file_put_contents('/folder/lorem.txt', ''); + $this->assertEquals('', $this->instance->file_get_contents('/folder/lorem.txt'), 'file not emptied'); + $this->instance->rmdir('/folder'); + $this->assertFalse($this->instance->file_exists('/folder/lorem.txt')); } /** @@ -187,16 +197,6 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->file_exists('/target2.txt')); $this->assertFalse($this->instance->file_exists('/source.txt')); $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target.txt')); - - // check if it's working inside directories as well - $this->instance->mkdir('/folder'); - $this->instance->file_put_contents('/folder/lorem.txt', $sourceText); - $this->assertFalse($this->instance->is_dir('/folder/lorem.txt')); - $this->assertEquals($sourceText, $this->instance->file_get_contents('/folder/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); - $this->instance->file_put_contents('/folder/lorem.txt', ''); - $this->assertEquals('', $this->instance->file_get_contents('/folder/lorem.txt'), 'file not emptied'); - $this->instance->rmdir('/folder'); - $this->assertFalse($this->instance->file_exists('/folder/lorem.txt')); } public function testLocal() { -- cgit v1.2.3 From 818e2a364a6ff3eae0e463fb117e6f17166b3dd1 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:38:34 +0200 Subject: test moving and copying of subdirectories --- tests/lib/files/storage/storage.php | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 771fad8c61b..b694a76ddfe 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -197,6 +197,47 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->file_exists('/target2.txt')); $this->assertFalse($this->instance->file_exists('/source.txt')); $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target.txt')); + + $this->assertTrue($this->instance->mkdir('/folder')); + $this->assertTrue($this->instance->mkdir('/folder/sub_a')); + $this->assertTrue($this->instance->mkdir('/folder/sub_b')); + $this->assertTrue($this->instance->mkdir('/folder/sub_b/sub_bb')); + + $this->assertTrue($this->instance->rename('/folder/sub_b', '/folder/sub_c')); + $this->assertTrue($this->instance->is_dir('/folder/sub_c')); + $this->assertTrue($this->instance->is_dir('/folder/sub_c/sub_bb')); + $this->assertFalse($this->instance->is_dir('/folder/sub_b')); + $this->assertFalse($this->instance->is_dir('/folder/sub_b/sub_bb')); + + $this->assertTrue($this->instance->rename('/folder', '/folder_b')); + $this->assertTrue($this->instance->is_dir('/folder_b')); + $this->assertTrue($this->instance->is_dir('/folder_b/sub_c')); + $this->assertTrue($this->instance->is_dir('/folder_b/sub_c/sub_bb')); + $this->assertFalse($this->instance->is_dir('/folder')); + $this->assertFalse($this->instance->is_dir('/folder/sub_c')); + $this->assertFalse($this->instance->is_dir('/folder/sub_c/sub_bb')); + + $this->assertTrue($this->instance->copy('/folder_b', '/folder')); + $this->assertTrue($this->instance->is_dir('/folder_b')); + $this->assertTrue($this->instance->is_dir('/folder_b/sub_c')); + $this->assertTrue($this->instance->is_dir('/folder_b/sub_c/sub_bb')); + $this->assertTrue($this->instance->is_dir('/folder')); + $this->assertTrue($this->instance->is_dir('/folder/sub_c')); + $this->assertTrue($this->instance->is_dir('/folder/sub_c/sub_bb')); + + $this->assertTrue($this->instance->copy('/folder/sub_c', '/folder/sub_b')); + $this->assertTrue($this->instance->is_dir('/folder/sub_b')); + $this->assertTrue($this->instance->is_dir('/folder/sub_b/sub_bb')); + $this->assertTrue($this->instance->is_dir('/folder/sub_c')); + $this->assertTrue($this->instance->is_dir('/folder/sub_c/sub_bb')); + + $this->assertTrue($this->instance->rmdir('/folder')); + $this->assertFalse($this->instance->is_dir('/folder')); + $this->assertFalse($this->instance->is_dir('/folder/sub_a')); + $this->assertFalse($this->instance->is_dir('/folder/sub_b')); + $this->assertFalse($this->instance->is_dir('/folder/sub_c')); + $this->assertFalse($this->instance->is_dir('/folder/sub_b/sub_bb')); + $this->assertFalse($this->instance->is_dir('/folder/sub_c/sub_bb')); } public function testLocal() { -- cgit v1.2.3 From 37254744b5b1d0f5761837dee1e33ad63dcff101 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 3 Jul 2013 18:41:14 +0200 Subject: remove tests from the wrong test method --- tests/lib/files/storage/storage.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index b694a76ddfe..8db3aed1fa5 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -127,16 +127,6 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->instance->is_dir('/folder')); $this->assertFalse($this->instance->is_dir('/folder/sub_a')); $this->assertFalse($this->instance->file_exists('/folder/sub_a/file.txt')); - - // check if it's working inside directories as well - $this->instance->mkdir('/folder'); - $this->instance->file_put_contents('/folder/lorem.txt', $sourceText); - $this->assertFalse($this->instance->is_dir('/folder/lorem.txt')); - $this->assertEquals($sourceText, $this->instance->file_get_contents('/folder/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); - $this->instance->file_put_contents('/folder/lorem.txt', ''); - $this->assertEquals('', $this->instance->file_get_contents('/folder/lorem.txt'), 'file not emptied'); - $this->instance->rmdir('/folder'); - $this->assertFalse($this->instance->file_exists('/folder/lorem.txt')); } /** -- cgit v1.2.3 From 92e73928529f00aa1638777995fdd5c91ee05275 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Thu, 4 Jul 2013 09:01:36 +0200 Subject: revoking additional tests --- tests/lib/files/storage/storage.php | 99 ------------------------------------- 1 file changed, 99 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 8db3aed1fa5..155a99d8bab 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -79,54 +79,6 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { } } $this->assertEquals(array(), $content); - - $this->assertTrue($this->instance->mkdir('/folder')); - $this->assertTrue($this->instance->mkdir('/folder/sub_a')); - $this->assertTrue($this->instance->mkdir('/folder/sub_b')); - $this->assertTrue($this->instance->mkdir('/folder/sub_b/sub_bb')); - $this->assertTrue($this->instance->touch('/folder/sub_b/sub_bb/file.txt')); - $this->assertTrue($this->instance->touch('/folder/sub_a/file.txt')); - $this->assertTrue($this->instance->is_dir('/folder/sub_b')); - $this->assertTrue($this->instance->is_dir('/folder/sub_b/sub_bb')); - $this->assertTrue($this->instance->file_exists('/folder/sub_a/file.txt')); - $this->assertTrue($this->instance->file_exists('/folder/sub_b/sub_bb/file.txt')); - - $dh = $this->instance->opendir('/folder'); - $content = array(); - while ($file = readdir($dh)) { - if ($file != '.' and $file != '..') { - $content[] = $file; - } - } - $this->assertEquals(array('sub_a', 'sub_b'), $content); - - $dh = $this->instance->opendir('/folder/sub_b/sub_bb'); - $content = array(); - while ($file = readdir($dh)) { - if ($file != '.' and $file != '..') { - $content[] = $file; - } - } - $this->assertEquals(array('file.txt'), $content); - - $this->assertTrue($this->instance->rmdir('/folder/sub_b')); - $this->assertFalse($this->instance->is_dir('/folder/sub_b')); - $this->assertFalse($this->instance->is_dir('/folder/sub_b/sub_bb')); - $this->assertFalse($this->instance->file_exists('/folder/sub_b/sub_bb/file.txt')); - - $dh = $this->instance->opendir('/folder'); - $content = array(); - while ($file = readdir($dh)) { - if ($file != '.' and $file != '..') { - $content[] = $file; - } - } - $this->assertEquals(array('sub_a'), $content); - - $this->assertTrue($this->instance->rmdir('/folder')); - $this->assertFalse($this->instance->is_dir('/folder')); - $this->assertFalse($this->instance->is_dir('/folder/sub_a')); - $this->assertFalse($this->instance->file_exists('/folder/sub_a/file.txt')); } /** @@ -144,16 +96,6 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { //empty the file $this->instance->file_put_contents('/lorem.txt', ''); $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied'); - - // check if it's working inside directories as well - $this->instance->mkdir('/folder'); - $this->instance->file_put_contents('/folder/lorem.txt', $sourceText); - $this->assertFalse($this->instance->is_dir('/folder/lorem.txt')); - $this->assertEquals($sourceText, $this->instance->file_get_contents('/folder/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); - $this->instance->file_put_contents('/folder/lorem.txt', ''); - $this->assertEquals('', $this->instance->file_get_contents('/folder/lorem.txt'), 'file not emptied'); - $this->instance->rmdir('/folder'); - $this->assertFalse($this->instance->file_exists('/folder/lorem.txt')); } /** @@ -187,47 +129,6 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->file_exists('/target2.txt')); $this->assertFalse($this->instance->file_exists('/source.txt')); $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target.txt')); - - $this->assertTrue($this->instance->mkdir('/folder')); - $this->assertTrue($this->instance->mkdir('/folder/sub_a')); - $this->assertTrue($this->instance->mkdir('/folder/sub_b')); - $this->assertTrue($this->instance->mkdir('/folder/sub_b/sub_bb')); - - $this->assertTrue($this->instance->rename('/folder/sub_b', '/folder/sub_c')); - $this->assertTrue($this->instance->is_dir('/folder/sub_c')); - $this->assertTrue($this->instance->is_dir('/folder/sub_c/sub_bb')); - $this->assertFalse($this->instance->is_dir('/folder/sub_b')); - $this->assertFalse($this->instance->is_dir('/folder/sub_b/sub_bb')); - - $this->assertTrue($this->instance->rename('/folder', '/folder_b')); - $this->assertTrue($this->instance->is_dir('/folder_b')); - $this->assertTrue($this->instance->is_dir('/folder_b/sub_c')); - $this->assertTrue($this->instance->is_dir('/folder_b/sub_c/sub_bb')); - $this->assertFalse($this->instance->is_dir('/folder')); - $this->assertFalse($this->instance->is_dir('/folder/sub_c')); - $this->assertFalse($this->instance->is_dir('/folder/sub_c/sub_bb')); - - $this->assertTrue($this->instance->copy('/folder_b', '/folder')); - $this->assertTrue($this->instance->is_dir('/folder_b')); - $this->assertTrue($this->instance->is_dir('/folder_b/sub_c')); - $this->assertTrue($this->instance->is_dir('/folder_b/sub_c/sub_bb')); - $this->assertTrue($this->instance->is_dir('/folder')); - $this->assertTrue($this->instance->is_dir('/folder/sub_c')); - $this->assertTrue($this->instance->is_dir('/folder/sub_c/sub_bb')); - - $this->assertTrue($this->instance->copy('/folder/sub_c', '/folder/sub_b')); - $this->assertTrue($this->instance->is_dir('/folder/sub_b')); - $this->assertTrue($this->instance->is_dir('/folder/sub_b/sub_bb')); - $this->assertTrue($this->instance->is_dir('/folder/sub_c')); - $this->assertTrue($this->instance->is_dir('/folder/sub_c/sub_bb')); - - $this->assertTrue($this->instance->rmdir('/folder')); - $this->assertFalse($this->instance->is_dir('/folder')); - $this->assertFalse($this->instance->is_dir('/folder/sub_a')); - $this->assertFalse($this->instance->is_dir('/folder/sub_b')); - $this->assertFalse($this->instance->is_dir('/folder/sub_c')); - $this->assertFalse($this->instance->is_dir('/folder/sub_b/sub_bb')); - $this->assertFalse($this->instance->is_dir('/folder/sub_c/sub_bb')); } public function testLocal() { -- cgit v1.2.3 From 424ec94680e69a3082a3d3f7c1ceefd7eeae15d2 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 8 Mar 2013 14:22:04 +0100 Subject: Make buildNotExistingFileName testable and write unittests --- lib/helper.php | 14 +++++++++++++- tests/lib/helper.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/lib/helper.php b/lib/helper.php index 1860a55fc8f..017221cef77 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -636,6 +636,18 @@ class OC_Helper { * @return string */ public static function buildNotExistingFileName($path, $filename) { + $view = \OC\Files\Filesystem::getView(); + return self::buildNotExistingFileNameForView($path, $filename, $view); + } + + /** + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ + public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) { if($path==='/') { $path=''; } @@ -649,7 +661,7 @@ class OC_Helper { $newpath = $path . '/' . $filename; $counter = 2; - while (\OC\Files\Filesystem::file_exists($newpath)) { + while ($view->file_exists($newpath)) { $newname = $name . ' (' . $counter . ')' . $ext; $newpath = $path . '/' . $newname; $counter++; diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 6acb0dfaa6b..410117a9e67 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -146,4 +146,46 @@ 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)); + $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)); + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); + $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)); + $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)); + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); + $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)); + $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)); + $this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock)); + } } -- cgit v1.2.3 From f29dd1c784b736e5d5398f936733409c0db0160d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 5 Jul 2013 15:25:53 +0200 Subject: fix test case whitespace --- tests/lib/config.php | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/lib/config.php b/tests/lib/config.php index c17d2ae7eff..12473eb6676 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -21,30 +21,26 @@ class Test_Config extends PHPUnit_Framework_TestCase { $this->config = new OC\Config(self::CONFIG_DIR); } - public function testReadData() - { + public function testReadData() { $config = new OC\Config('/non-existing'); $this->assertAttributeEquals(array(), 'cache', $config); - $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $this->config); + $this->assertAttributeEquals(array('foo' => 'bar'), 'cache', $this->config); } - public function testGetKeys() - { + public function testGetKeys() { $this->assertEquals(array('foo'), $this->config->getKeys()); } - public function testGetValue() - { + 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() - { + public function testSetValue() { $this->config->setValue('foo', 'moo'); - $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $this->config); + $this->assertAttributeEquals(array('foo' => 'moo'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<config->setValue('bar', 'red'); - $this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $this->config); + $this->assertAttributeEquals(array('foo' => 'moo', 'bar' => 'red'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); $this->assertEquals(<<config->deleteKey('foo'); $this->assertAttributeEquals(array(), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); @@ -79,11 +74,10 @@ EOL ); EOL -, $content); + , $content); } - public function testSavingDebugMode() - { + 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); @@ -96,14 +90,13 @@ define('DEBUG',true); ); EOL -, $content); + , $content); } /** * @expectedException \OC\HintException */ - public function testWriteData() - { + public function testWriteData() { $config = new OC\Config('/non-writable'); $config->setValue('foo', 'bar'); } -- cgit v1.2.3 From 492a35737c634fee27b0eb9d3ea6425bc6d98396 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 5 Jul 2013 15:26:39 +0200 Subject: fix \OC\Config test cases when debug mode is enabled --- tests/lib/config.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/lib/config.php b/tests/lib/config.php index 12473eb6676..87ee2807c2d 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -39,6 +39,7 @@ class Test_Config extends PHPUnit_Framework_TestCase { } 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); @@ -65,6 +66,7 @@ EOL } public function testDeleteKey() { + $this->config->setDebugMode(false); $this->config->deleteKey('foo'); $this->assertAttributeEquals(array(), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); -- cgit v1.2.3 From 22c29eb64b67ee18beacf126eecb78fd4a02608c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 5 Jul 2013 15:38:09 +0200 Subject: Fix renaming using parenthesis --- lib/helper.php | 26 +++++++++++++++++++++----- tests/lib/helper.php | 36 +++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/lib/helper.php b/lib/helper.php index 017221cef77..df0d120976d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -660,11 +660,27 @@ class OC_Helper { } $newpath = $path . '/' . $filename; - $counter = 2; - while ($view->file_exists($newpath)) { - $newname = $name . ' (' . $counter . ')' . $ext; - $newpath = $path . '/' . $newname; - $counter++; + if ($view->file_exists($newpath)) { + if(preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { + //Replace the last "(number)" with "(number+1)" + $last_match = count($matches[0])-1; + $counter = $matches[1][$last_match][0]+1; + $offset = $matches[0][$last_match][1]; + $match_length = strlen($matches[0][$last_match][0]); + } else { + $counter = 2; + $offset = false; + } + do { + if($offset) { + //Replace the last "(number)" with "(number+1)" + $newname = substr_replace($name, '('.$counter.')', $offset, $match_length); + } else { + $newname = $name . ' (' . $counter . ')'; + } + $newpath = $path . '/' . $newname . $ext; + $counter++; + } while ($view->file_exists($newpath)); } return $newpath; diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 410117a9e67..67b5a3d43ec 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -154,38 +154,56 @@ class Test_Helper extends PHPUnit_Framework_TestCase { $viewMock->expects($this->at(0)) ->method('file_exists') - ->will($this->returnValue(true)); + ->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)); + ->will($this->returnValue(true)); // filename.ext exists $viewMock->expects($this->at(1)) ->method('file_exists') - ->will($this->returnValue(true)); + ->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)); + ->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)); + ->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)); - $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock)); + ->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)); + ->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)); + ->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)); } } -- cgit v1.2.3 From 8c9e6db1b10c8dac559d3eaec0952e9b733dc7fe Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Mon, 8 Jul 2013 15:03:55 +0200 Subject: increasing allowed time difference --- tests/lib/files/storage/storage.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 155a99d8bab..fbf502fbc1c 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -168,10 +168,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->isReadable('/lorem.txt')); $ctimeEnd = time(); $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 3)); - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 3)); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); - $this->assertTrue(($ctimeStart - 3) <= $mTime); + $this->assertTrue(($ctimeStart - 5) <= $mTime); $this->assertTrue($mTime <= ($ctimeEnd + 1)); $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); @@ -185,10 +185,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $mtimeEnd = time(); if ($supportsTouch !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 3) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 3)); + $this->assertTrue(($mtimeStart - 5) <= $mTime); + $this->assertTrue($mTime <= ($mtimeEnd + 5)); - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 3)); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 5)); if ($this->instance->touch('/lorem.txt', 100) !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); @@ -203,11 +203,11 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { clearstatcache(); $mtimeEnd = time(); $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 3) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 3)); + $this->assertTrue(($mtimeStart - 5) <= $mTime); + $this->assertTrue($mTime <= ($mtimeEnd + 5)); $this->instance->unlink('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 3)); + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } public function testSearch() { -- cgit v1.2.3 From 925d09cb0e3aed2ab89a11d636111ba699cc403f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 8 Jul 2013 16:45:19 +0200 Subject: add forwarding emitter for agregating multiple emitters --- lib/hooks/forwardingemitter.php | 42 ++++++++++++++++++++++++ tests/lib/hooks/forwardingemitter.php | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 lib/hooks/forwardingemitter.php create mode 100644 tests/lib/hooks/forwardingemitter.php (limited to 'tests') diff --git a/lib/hooks/forwardingemitter.php b/lib/hooks/forwardingemitter.php new file mode 100644 index 00000000000..518641ac7cf --- /dev/null +++ b/lib/hooks/forwardingemitter.php @@ -0,0 +1,42 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Hooks; + +/** + * Class ForwardingEmitter + * + * allows forwarding all listen calls to other emitters + * + * @package OC\Hooks + */ +abstract class ForwardingEmitter extends BasicEmitter { + /** + * @var \OC\Hooks\Emitter[] array + */ + private $forwardEmitters = array(); + + /** + * @param string $scope + * @param string $method + * @param callable $callback + */ + public function listen($scope, $method, $callback) { + parent::listen($scope, $method, $callback); + foreach ($this->forwardEmitters as $emitter) { + $emitter->listen($scope, $method, $callback); + } + } + + /** + * @param \OC\Hooks\Emitter $emitter + */ + protected function forward($emitter) { + $this->forwardEmitters[] = $emitter; + } +} diff --git a/tests/lib/hooks/forwardingemitter.php b/tests/lib/hooks/forwardingemitter.php new file mode 100644 index 00000000000..0686ebece9f --- /dev/null +++ b/tests/lib/hooks/forwardingemitter.php @@ -0,0 +1,62 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Hooks; +use OC\Hooks\PublicEmitter; + +class DummyForwardingEmitter extends \OC\Hooks\ForwardingEmitter { + public function emitEvent($scope, $method, $arguments = array()) { + $this->emit($scope, $method, $arguments); + } + + /** + * @param \OC\Hooks\Emitter $emitter + */ + public function forward($emitter) { + parent::forward($emitter); + } +} + +/** + * Class ForwardingEmitter + * + * allows forwarding all listen calls to other emitters + * + * @package OC\Hooks + */ +class ForwardingEmitter extends BasicEmitter { + public function testSingleForward() { + $baseEmitter = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $forwardingEmitter->forward($baseEmitter); + $hookCalled = false; + $forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { + $hookCalled = true; + }); + $baseEmitter->emit('Test', 'test'); + $this->assertTrue($hookCalled); + } + + public function testMultipleForwards() { + $baseEmitter1 = new PublicEmitter(); + $baseEmitter2 = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $forwardingEmitter->forward($baseEmitter1); + $forwardingEmitter->forward($baseEmitter2); + $hookCalled = 0; + $forwardingEmitter->listen('Test', 'test1', function () use (&$hookCalled) { + $hookCalled++; + }); + $forwardingEmitter->listen('Test', 'test2', function () use (&$hookCalled) { + $hookCalled++; + }); + $baseEmitter1->emit('Test', 'test1'); + $baseEmitter1->emit('Test', 'test2'); + $this->assertEquals(2, $hookCalled); + } +} -- cgit v1.2.3 From 4a4e139c8391986ce54585f3292f3c2e40dd624d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 8 Jul 2013 16:54:26 +0200 Subject: forward previously registerd hooks --- lib/hooks/basicemitter.php | 2 +- lib/hooks/forwardingemitter.php | 8 ++++++++ tests/lib/hooks/forwardingemitter.php | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/lib/hooks/basicemitter.php b/lib/hooks/basicemitter.php index e615a58cfe8..9ffe1af2314 100644 --- a/lib/hooks/basicemitter.php +++ b/lib/hooks/basicemitter.php @@ -13,7 +13,7 @@ abstract class BasicEmitter implements Emitter { /** * @var (callable[])[] $listeners */ - private $listeners = array(); + protected $listeners = array(); /** * @param string $scope diff --git a/lib/hooks/forwardingemitter.php b/lib/hooks/forwardingemitter.php index 518641ac7cf..1aacc4012e0 100644 --- a/lib/hooks/forwardingemitter.php +++ b/lib/hooks/forwardingemitter.php @@ -38,5 +38,13 @@ abstract class ForwardingEmitter extends BasicEmitter { */ protected function forward($emitter) { $this->forwardEmitters[] = $emitter; + + //forward all previously connected hooks + foreach ($this->listeners as $key => $listeners) { + list($scope, $method) = explode('::', $key, 2); + foreach ($listeners as $listener) { + $emitter->listen($scope, $method, $listener); + } + } } } diff --git a/tests/lib/hooks/forwardingemitter.php b/tests/lib/hooks/forwardingemitter.php index 0686ebece9f..decf6bb354c 100644 --- a/tests/lib/hooks/forwardingemitter.php +++ b/tests/lib/hooks/forwardingemitter.php @@ -59,4 +59,16 @@ class ForwardingEmitter extends BasicEmitter { $baseEmitter1->emit('Test', 'test2'); $this->assertEquals(2, $hookCalled); } + + public function testForwardExistingHooks() { + $baseEmitter = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $hookCalled = false; + $forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { + $hookCalled = true; + }); + $forwardingEmitter->forward($baseEmitter); + $baseEmitter->emit('Test', 'test'); + $this->assertTrue($hookCalled); + } } -- cgit v1.2.3 From c0b210f0d5b4953fc9a437d82ac6af1a4b482909 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 5 Jul 2013 15:02:41 +0300 Subject: Add unit test --- tests/lib/util.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/lib/util.php b/tests/lib/util.php index 1f253825920..9742d57ac7a 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -37,6 +37,12 @@ class Test_Util extends PHPUnit_Framework_TestCase { $result = OC_Util::sanitizeHTML($goodString); $this->assertEquals("This is an harmless string.", $result); } + + function testEncodePath(){ + $component = '/§#@test%&^ä/-child'; + $result = OC_Util::encodePath($component); + $this->assertEquals("/%C2%A7%23%40test%25%26%5E%C3%A4/-child", $result); + } function testGenerate_random_bytes() { $result = strlen(OC_Util::generate_random_bytes(59)); -- cgit v1.2.3 From 7ba4269c263a6e102e5efeefdce94909f9a59aab Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 15 Jul 2013 10:28:14 +0200 Subject: <<config->setValue('foo', 'moo'); $this->assertAttributeEquals(array('foo' => 'moo'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<< 'moo', -); -EOL - , $content); + $expected = " '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); - $this->assertEquals(<< 'moo', - 'bar' => 'red', -); -EOL - , $content); + $expected = " 'moo',\n 'bar' => 'red',\n);\n"; + $this->assertEquals($expected, $content); } public function testDeleteKey() { @@ -70,13 +59,9 @@ EOL $this->config->deleteKey('foo'); $this->assertAttributeEquals(array(), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<<assertEquals($expected, $content); } public function testSavingDebugMode() { @@ -85,14 +70,9 @@ EOL $this->assertAttributeEquals(array(), 'cache', $this->config); $this->assertAttributeEquals(true, 'debugMode', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<<assertEquals($expected, $content); } /** -- cgit v1.2.3 From 8ad148feaf975481815b3f2413fc1fa34b3e8be7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Jul 2013 15:46:27 +0200 Subject: memcache: some additional unit tests --- tests/lib/memcache/apc.php | 31 ++++++++++--------------------- tests/lib/memcache/cache.php | 36 ++++++++++++++++++++++++++++++++++++ tests/lib/memcache/memcached.php | 7 +++++-- tests/lib/memcache/xcache.php | 29 +++++++++-------------------- 4 files changed, 60 insertions(+), 43 deletions(-) create mode 100644 tests/lib/memcache/cache.php (limited to 'tests') diff --git a/tests/lib/memcache/apc.php b/tests/lib/memcache/apc.php index e3dccc09669..6b2a49470ba 100644 --- a/tests/lib/memcache/apc.php +++ b/tests/lib/memcache/apc.php @@ -1,31 +1,20 @@ . -* -*/ + * Copyright (c) 2013 Robin Appelman + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Memcache; -class Test_Memcache_APC extends Test_Cache { +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(); + $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..2c1dbc9d2f7 --- /dev/null +++ b/tests/lib/memcache/cache.php @@ -0,0 +1,36 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Memcache; + +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 tearDown() { + if ($this->instance) { + $this->instance->clear(); + } + } +} diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php index a0be047ed1f..4b38ae8ef3c 100644 --- a/tests/lib/memcache/memcached.php +++ b/tests/lib/memcache/memcached.php @@ -1,4 +1,5 @@ * This file is licensed under the Affero General Public License version 3 or @@ -6,12 +7,14 @@ * See the COPYING-README file. */ -class Test_Memcache_Memcached extends Test_Cache { +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(); + $this->instance = new \OC\Memcache\Memcached(uniqid()); } } diff --git a/tests/lib/memcache/xcache.php b/tests/lib/memcache/xcache.php index 48773533c89..f59afda3966 100644 --- a/tests/lib/memcache/xcache.php +++ b/tests/lib/memcache/xcache.php @@ -1,31 +1,20 @@ . - * + * Copyright (c) 2013 Robin Appelman + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ -class Test_Memcache_XCache extends Test_Cache { +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(); + $this->instance = new \OC\Memcache\XCache(uniqid()); } } -- cgit v1.2.3 From 504089940de88220a425db21e8e133582fe15c30 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Jul 2013 16:06:00 +0200 Subject: mamcache: implement the ArrayAccess interface --- lib/memcache/cache.php | 20 +++++++++++++++++++- tests/lib/memcache/cache.php | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/lib/memcache/cache.php b/lib/memcache/cache.php index 9db69ae4104..0ad1cc7ec03 100644 --- a/lib/memcache/cache.php +++ b/lib/memcache/cache.php @@ -8,7 +8,7 @@ namespace OC\Memcache; -abstract class Cache { +abstract class Cache implements \ArrayAccess { /** * @var string $prefix */ @@ -56,4 +56,22 @@ abstract class Cache { * @return mixed */ abstract public function clear($prefix = ''); + + //implement the ArrayAccess interface + + public function offsetExists($offset) { + return $this->hasKey($offset); + } + + public function offsetSet($offset, $value) { + $this->set($offset, $value); + } + + public function offsetGet($offset) { + return $this->get($offset); + } + + public function offsetUnset($offset) { + $this->remove($offset); + } } diff --git a/tests/lib/memcache/cache.php b/tests/lib/memcache/cache.php index 2c1dbc9d2f7..e2643b9fcd9 100644 --- a/tests/lib/memcache/cache.php +++ b/tests/lib/memcache/cache.php @@ -28,6 +28,28 @@ class Cache extends \Test_Cache { $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(); -- cgit v1.2.3 From b2bcc9774bb3c7857a99dc81116e0d949962657e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Jul 2013 23:11:22 +0200 Subject: memcache: make base testcase abstract --- tests/lib/memcache/cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/memcache/cache.php b/tests/lib/memcache/cache.php index e2643b9fcd9..d07c492cef0 100644 --- a/tests/lib/memcache/cache.php +++ b/tests/lib/memcache/cache.php @@ -9,7 +9,7 @@ namespace Test\Memcache; -class Cache extends \Test_Cache { +abstract class Cache extends \Test_Cache { public function testExistsAfterSet() { $this->assertFalse($this->instance->hasKey('foo')); $this->instance->set('foo', 'bar'); -- cgit v1.2.3 From 8f93490ac45fbd74bd0e9697a685fd43bb34239b Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Sun, 21 Jul 2013 11:13:29 +0200 Subject: fix failing master branch - Test_Config::testWriteData --- lib/config.php | 6 +++++- tests/lib/config.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/lib/config.php b/lib/config.php index 00d9f5b4247..a38ce19c74f 100644 --- a/lib/config.php +++ b/lib/config.php @@ -144,7 +144,11 @@ class Config { continue; } unset($CONFIG); - include $file; + if((@include $file) === false) + { + throw new HintException("Can't read from config file '" . $file . "'. ". + 'This is usually caused by the wrong file permission.'); + } if (isset($CONFIG) && is_array($CONFIG)) { $this->cache = array_merge($this->cache, $CONFIG); } diff --git a/tests/lib/config.php b/tests/lib/config.php index c67a66c832e..1a1d062d688 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -80,6 +80,17 @@ class Test_Config extends PHPUnit_Framework_TestCase { */ public function testWriteData() { $config = new OC\Config('/non-writable'); + // TODO never get's called, because the previous call throws the exception + // maybe include some more logic to create a readable dir and then try to + // write to this dir + // + // console commands: + // $ sudo touch /non-writableconfig.php + // $ sudo chmod go-rwx /non-writableconfig.php + // ---- call the tests now -> above statemant throws the exception + // + // $ sudo chmod go+r /non-writableconfig.php + // ---- call the tests now -> bellow statemant throws the exception $config->setValue('foo', 'bar'); } } -- cgit v1.2.3