From 5de2a292fcfe9174542e7708b033c8026a2c46a6 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 13 Jul 2012 13:41:13 +0200 Subject: restructuring test suite invocation - now we load all test cases into one suite and execute this single suite. this is necessary to be able to generate one xml report and is also a precondition for code coverage analysis(which will follow soon) --- tests/index.php | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/index.php b/tests/index.php index 691bf2a5d45..e91b3f0da56 100644 --- a/tests/index.php +++ b/tests/index.php @@ -26,39 +26,59 @@ require_once 'simpletest/mock_objects.php'; require_once 'simpletest/collector.php'; require_once 'simpletest/default_reporter.php'; +// test suite instance +$testSuite=new TestSuite("ownCloud Unit Test Suite"); + +// prepare the reporter +if(OC::$CLI){ + $reporter=new TextReporter; + $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; + if($test=='xml') + { + $reporter= new XmlReporter; + $test=false; + } +}else{ + $reporter='HtmlReporter'; + $test=isset($_GET['test'])?$_GET['test']:false; +} + //load core test cases -loadTests(dirname(__FILE__)); +loadTests(dirname(__FILE__), $testSuite, $test); //load app test cases + +// +// TODO: define a list of apps to be enabled + enable them +// + $apps=OC_App::getEnabledApps(); foreach($apps as $app){ if(is_dir(OC::$SERVERROOT.'/apps/'.$app.'/tests')){ - loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests'); + loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests', $testSuite, $test); } } -function loadTests($dir=''){ - if(OC::$CLI){ - $reporter='TextReporter'; - $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; - }else{ - $reporter='HtmlReporter'; - $test=isset($_GET['test'])?$_GET['test']:false; - } +// run the suite +if($testSuite->getSize()>0){ + $testSuite->run($reporter); +} + +// helper below +function loadTests($dir,$testSuite, $test){ if($dh=opendir($dir)){ while($name=readdir($dh)){ if($name[0]!='.'){//no hidden files, '.' or '..' $file=$dir.'/'.$name; if(is_dir($file)){ - loadTests($file); + loadTests($file, $testSuite, $test); }elseif(substr($file,-4)=='.php' and $file!=__FILE__){ $name=getTestName($file); if($test===false or $test==$name or substr($name,0,strlen($test))==$test){ - $testCase=new TestSuite($name); - $testCase->addFile($file); - if($testCase->getSize()>0){ - $testCase->run(new $reporter()); - } + $extractor = new SimpleFileLoader(); + $loadedSuite=$extractor->load($file); + if ($loadedSuite->getSize() > 0) + $testSuite->add($loadedSuite); } } } -- cgit v1.2.3 From 3ffc96c3e96de8bb26729f510e6a35be5477c6c1 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 16 Jul 2012 00:07:40 +0200 Subject: add database type to xml report --- autotest.sh | 2 +- tests/index.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/autotest.sh b/autotest.sh index fe55c1066da..bf98932a4af 100755 --- a/autotest.sh +++ b/autotest.sh @@ -69,7 +69,7 @@ function execute_tests { #test execution echo "Testing with $1 ..." cd tests - php -f index.php -- xml > autotest-results-$1.xml + php -f index.php -- xml $1 > autotest-results-$1.xml } # diff --git a/tests/index.php b/tests/index.php index e91b3f0da56..935ce39531a 100644 --- a/tests/index.php +++ b/tests/index.php @@ -26,8 +26,7 @@ require_once 'simpletest/mock_objects.php'; require_once 'simpletest/collector.php'; require_once 'simpletest/default_reporter.php'; -// test suite instance -$testSuite=new TestSuite("ownCloud Unit Test Suite"); +$testSuiteName="ownCloud Unit Test Suite"; // prepare the reporter if(OC::$CLI){ @@ -37,12 +36,19 @@ if(OC::$CLI){ { $reporter= new XmlReporter; $test=false; + + if(isset($_SERVER['argv'][2])){ + $testSuiteName=$testSuiteName." (".$_SERVER['argv'][2].")"; + } } }else{ $reporter='HtmlReporter'; $test=isset($_GET['test'])?$_GET['test']:false; } +// test suite instance +$testSuite=new TestSuite($testSuiteName); + //load core test cases loadTests(dirname(__FILE__), $testSuite, $test); -- cgit v1.2.3 From e031b9b88009ed7b1d1986d9a58e7cb39b5dd825 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 19 Jul 2012 16:19:23 +0200 Subject: fix running test cases from browser --- tests/index.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/index.php b/tests/index.php index 935ce39531a..0be27ee3fd7 100644 --- a/tests/index.php +++ b/tests/index.php @@ -32,8 +32,7 @@ $testSuiteName="ownCloud Unit Test Suite"; if(OC::$CLI){ $reporter=new TextReporter; $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; - if($test=='xml') - { + if($test=='xml'){ $reporter= new XmlReporter; $test=false; @@ -42,7 +41,7 @@ if(OC::$CLI){ } } }else{ - $reporter='HtmlReporter'; + $reporter=new HtmlReporter; $test=isset($_GET['test'])?$_GET['test']:false; } @@ -81,10 +80,10 @@ function loadTests($dir,$testSuite, $test){ }elseif(substr($file,-4)=='.php' and $file!=__FILE__){ $name=getTestName($file); if($test===false or $test==$name or substr($name,0,strlen($test))==$test){ - $extractor = new SimpleFileLoader(); + $extractor = new SimpleFileLoader(); $loadedSuite=$extractor->load($file); if ($loadedSuite->getSize() > 0) - $testSuite->add($loadedSuite); + $testSuite->add($loadedSuite); } } } -- cgit v1.2.3 From 0e6238c66fc5f37b11800e632dbcccd72833628f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 17:57:18 +0200 Subject: fix OC_Cache_File tests if encryption is not enabled --- tests/lib/cache/file.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index 54e60e6569d..c33c513fcff 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -30,8 +30,10 @@ class Test_Cache_File extends Test_Cache { OC_FileProxy::clearProxies(); OC_Hook::clear('OC_Filesystem'); - //enable only the encryption hook - OC_FileProxy::register(new OC_FileProxy_Encryption()); + //enable only the encryption hook if needed + if(OC_App::isEnabled('files_encryption')){ + OC_FileProxy::register(new OC_FileProxy_Encryption()); + } //set up temporary storage OC_Filesystem::clearMounts(); -- cgit v1.2.3 From c9be9ab251681d96cfb620ca26778ba0005023d3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 18:56:18 +0200 Subject: remove unused variables --- apps/files_encryption/lib/cryptstream.php | 3 --- apps/files_external/lib/smb.php | 2 -- apps/files_external/tests/ftp.php | 1 - apps/files_external/tests/google.php | 1 - apps/files_external/tests/smb.php | 1 - apps/files_external/tests/swift.php | 1 - apps/files_external/tests/webdav.php | 1 - apps/gallery/lib/album.php | 2 +- apps/gallery/lib/managers.php | 1 - apps/gallery/lib/tiles.php | 2 +- apps/media/lib_ampache.php | 1 - apps/media/lib_collection.php | 3 +-- apps/media/lib_media.php | 6 +++--- apps/remoteStorage/lib_remoteStorage.php | 13 ++++++------- lib/archive/zip.php | 1 - lib/filecache/update.php | 1 - lib/filestorage/common.php | 2 +- lib/group/database.php | 5 ++--- lib/group/dummy.php | 3 ++- lib/group/example.php | 18 +++++++++--------- lib/public/app.php | 22 ---------------------- lib/search/provider.php | 10 +++++++--- lib/user/database.php | 8 +++----- lib/user/example.php | 12 +++--------- tests/lib/user/database.php | 1 - 25 files changed, 39 insertions(+), 82 deletions(-) (limited to 'tests') diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index e0020537563..46471911d94 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -31,9 +31,7 @@ class OC_CryptStream{ public static $sourceStreams=array(); private $source; private $path; - private $readBuffer;//for streams that dont support seeking private $meta=array();//header/meta for source stream - private $count; private $writeCache; private $size; private static $rootView; @@ -100,7 +98,6 @@ class OC_CryptStream{ public function stream_write($data){ $length=strlen($data); - $written=0; $currentPos=ftell($this->source); if($this->writeCache){ $data=$this->writeCache.$data; diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 5e34deb2337..8a5e993b1d0 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -15,8 +15,6 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ private $root; private $share; - private static $tempFiles=array(); - public function __construct($params){ $this->host=$params['host']; $this->user=$params['user']; diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/ftp.php index 68481b4e66b..97796bca128 100644 --- a/apps/files_external/tests/ftp.php +++ b/apps/files_external/tests/ftp.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['ftp']) or !$config['ftp']['run']){ }else{ class Test_Filestorage_FTP extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/google.php index 08116f0e748..806db5a6aaa 100644 --- a/apps/files_external/tests/google.php +++ b/apps/files_external/tests/google.php @@ -28,7 +28,6 @@ if(!is_array($config) or !isset($config['google']) or !$config['google']['run']) class Test_Filestorage_Google extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php index e1495b7480d..001ef842276 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/smb.php @@ -14,7 +14,6 @@ if(!is_array($config) or !isset($config['smb']) or !$config['smb']['run']){ }else{ class Test_Filestorage_SMB extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/swift.php b/apps/files_external/tests/swift.php index f0bde6ed605..1520c9473d3 100644 --- a/apps/files_external/tests/swift.php +++ b/apps/files_external/tests/swift.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['swift']) or !$config['swift']['run']){ }else{ class Test_Filestorage_SWIFT extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/webdav.php index 144659819b6..14abbef2cbf 100644 --- a/apps/files_external/tests/webdav.php +++ b/apps/files_external/tests/webdav.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['webdav']) or !$config['webdav']['run']) }else{ class Test_Filestorage_DAV extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php index 39d6d3aded1..701949d4d80 100644 --- a/apps/gallery/lib/album.php +++ b/apps/gallery/lib/album.php @@ -58,7 +58,7 @@ class OC_Gallery_Album { return $stmt->execute($args); } - public static function removeByName($owner, $name) { self::remove($ownmer, $name); } + public static function removeByName($owner, $name) { self::remove($owner, $name); } public static function removeByPath($owner, $path) { self::remove($owner, null, $path); } public static function removeByParentPath($owner, $parent) { self::remove($owner, null, null, $parent); } diff --git a/apps/gallery/lib/managers.php b/apps/gallery/lib/managers.php index b6ade3d1b1e..575d962dbe3 100644 --- a/apps/gallery/lib/managers.php +++ b/apps/gallery/lib/managers.php @@ -29,7 +29,6 @@ class DatabaseManager { $stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)'); $stmt->execute(array(\OCP\USER::getUser(), $path, $width, $height)); $ret = array('path' => $path, 'width' => $width, 'height' => $height); - unset($image); $dir = dirname($path); $this->cache[$dir][$path] = $ret; return $ret; diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index 754734e609e..e36d26d3191 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -33,7 +33,7 @@ class TilesLine { } public function setAvailableSpace($space) { - $available_space = $space; + $this->available_space = $space; } public function getTilesCount() { diff --git a/apps/media/lib_ampache.php b/apps/media/lib_ampache.php index d35cca150b2..d5a093338cc 100644 --- a/apps/media/lib_ampache.php +++ b/apps/media/lib_ampache.php @@ -271,7 +271,6 @@ class OC_MEDIA_AMPACHE{ "); return; } - global $SITEROOT; $filter=$params['filter']; $albums=OC_MEDIA_COLLECTION::getAlbums($filter); $artist=OC_MEDIA_COLLECTION::getArtistName($filter); diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php index e65930f551d..cacab8e959f 100644 --- a/apps/media/lib_collection.php +++ b/apps/media/lib_collection.php @@ -27,7 +27,6 @@ class OC_MEDIA_COLLECTION{ public static $uid; private static $artistIdCache=array(); private static $albumIdCache=array(); - private static $songIdCache=array(); private static $queries=array(); /** @@ -152,7 +151,7 @@ class OC_MEDIA_COLLECTION{ return $artistId; }else{ $query=OCP\DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_name`) VALUES (?)"); - $result=$query->execute(array($name)); + $query->execute(array($name)); return self::getArtistId($name);; } } diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php index 9e687a4af2c..54502f42575 100644 --- a/apps/media/lib_media.php +++ b/apps/media/lib_media.php @@ -27,12 +27,12 @@ class OC_MEDIA{ * @param array $params, parameters passed from OC_Hook */ public static function loginListener($params){ - if(isset($_POST['user']) and $_POST['password']){ - $name=$_POST['user']; + if(isset($params['uid']) and $params['password']){ + $name=$params['uid']; $query=OCP\DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?"); $uid=$query->execute(array($name))->fetchAll(); if(count($uid)==0){ - $password=hash('sha256',$_POST['password']); + $password=hash('sha256',$params['password']); $query=OCP\DB::prepare("INSERT INTO *PREFIX*media_users (user_id, user_password_sha256) VALUES (?, ?);"); $query->execute(array($name,$password)); } diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php index 42cd9c90f64..c1765640c5d 100644 --- a/apps/remoteStorage/lib_remoteStorage.php +++ b/apps/remoteStorage/lib_remoteStorage.php @@ -17,12 +17,11 @@ class OC_remoteStorage { $user=OCP\USER::getUser(); $query=OCP\DB::prepare("SELECT token FROM *PREFIX*authtoken WHERE user=? AND appUrl=? AND category=? LIMIT 1"); $result=$query->execute(array($user, $appUrl, $categories)); - $ret = array(); if($row=$result->fetchRow()) { - return base64_encode('remoteStorage:'.$row['token']); - } else { - return false; - } + return base64_encode('remoteStorage:'.$row['token']); + } else { + return false; + } } public static function getAllTokens() { @@ -42,13 +41,13 @@ class OC_remoteStorage { public static function deleteToken($token) { $user=OCP\USER::getUser(); $query=OCP\DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?"); - $result=$query->execute(array($token,$user)); + $query->execute(array($token,$user)); return 'unknown';//how can we see if any rows were affected? } private static function addToken($token, $appUrl, $categories){ $user=OCP\USER::getUser(); $query=OCP\DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)"); - $result=$query->execute(array($token,$appUrl,$user,$categories)); + $query->execute(array($token,$appUrl,$user,$categories)); } public static function createCategories($appUrl, $categories) { $token=uniqid(); diff --git a/lib/archive/zip.php b/lib/archive/zip.php index ff405ce098b..b2d6674d639 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -11,7 +11,6 @@ class OC_Archive_ZIP extends OC_Archive{ * @var ZipArchive zip */ private $zip=null; - private $success=false; private $path; function __construct($source){ diff --git a/lib/filecache/update.php b/lib/filecache/update.php index dd77f491ca0..93b632acb4e 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -207,7 +207,6 @@ class OC_FileCache_Update{ $cached=OC_FileCache_Cached::get($oldPath,$root); $oldSize=$cached['size']; - $size=$view->filesize($newPath); OC_FileCache::increaseSize(dirname($oldPath),-$oldSize,$root); OC_FileCache::increaseSize(dirname($newPath),$oldSize,$root); OC_FileCache::move($oldPath,$newPath); diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index ba78fca80e5..fd389d3e2d7 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -220,7 +220,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { } $tmpFile=OC_Helper::tmpFile($extension); $target=fopen($tmpFile,'w'); - $count=OC_Helper::streamCopy($source,$target); + OC_Helper::streamCopy($source,$target); return $tmpFile; } // abstract public function touch($path, $mtime=null); diff --git a/lib/group/database.php b/lib/group/database.php index fb173665eb8..2770ec185c4 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -41,7 +41,6 @@ * Class for group management in a SQL Database (e.g. MySQL, SQLite) */ class OC_Group_Database extends OC_Group_Backend { - private $userGroupCache=array(); /** * @brief Try to create a new group @@ -116,7 +115,7 @@ class OC_Group_Database extends OC_Group_Backend { // No duplicate entries! if( !$this->inGroup( $uid, $gid )){ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )" ); - $result = $query->execute( array( $uid, $gid )); + $query->execute( array( $uid, $gid )); return true; }else{ return false; @@ -133,7 +132,7 @@ class OC_Group_Database extends OC_Group_Backend { */ public function removeFromGroup( $uid, $gid ){ $query = OC_DB::prepare( "DELETE FROM *PREFIX*group_user WHERE uid = ? AND gid = ?" ); - $result = $query->execute( array( $uid, $gid )); + $query->execute( array( $uid, $gid )); return true; } diff --git a/lib/group/dummy.php b/lib/group/dummy.php index 0825b10708a..1243891023f 100644 --- a/lib/group/dummy.php +++ b/lib/group/dummy.php @@ -126,7 +126,8 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function getUserGroups($uid){ $groups=array(); - foreach($this->groups as $group=>$user){ + $allGroups=array_keys($this->groups); + foreach($allGroups as $group){ if($this->inGroup($uid,$group)){ $groups[]=$group; } diff --git a/lib/group/example.php b/lib/group/example.php index c18562db7a4..f9c62fb9789 100644 --- a/lib/group/example.php +++ b/lib/group/example.php @@ -34,7 +34,7 @@ abstract class OC_Group_Example { * Trys to create a new group. If the group name already exists, false will * be returned. */ - public static function createGroup($gid){} + abstract public static function createGroup($gid); /** * @brief delete a group @@ -43,7 +43,7 @@ abstract class OC_Group_Example { * * Deletes a group and removes it from the group_user-table */ - public static function deleteGroup($gid){} + abstract public static function deleteGroup($gid); /** * @brief is user in group? @@ -53,7 +53,7 @@ abstract class OC_Group_Example { * * Checks whether the user is member of a group or not. */ - public static function inGroup($uid, $gid){} + abstract public static function inGroup($uid, $gid); /** * @brief Add a user to a group @@ -63,7 +63,7 @@ abstract class OC_Group_Example { * * Adds a user to a group. */ - public static function addToGroup($uid, $gid){} + abstract public static function addToGroup($uid, $gid); /** * @brief Removes a user from a group @@ -73,7 +73,7 @@ abstract class OC_Group_Example { * * removes the user from a group. */ - public static function removeFromGroup($uid,$gid){} + abstract public static function removeFromGroup($uid,$gid); /** * @brief Get all groups a user belongs to @@ -83,7 +83,7 @@ abstract class OC_Group_Example { * This function fetches all groups a user belongs to. It does not check * if the user exists at all. */ - public static function getUserGroups($uid){} + abstract public static function getUserGroups($uid); /** * @brief get a list of all groups @@ -91,19 +91,19 @@ abstract class OC_Group_Example { * * Returns a list with all groups */ - public static function getGroups(){} + abstract public static function getGroups(); /** * check if a group exists * @param string $gid * @return bool */ - public function groupExists($gid){} + public function groupExists($gid); /** * @brief get a list of all users in a group * @returns array with user ids */ - public static function usersInGroup($gid){} + abstract public static function usersInGroup($gid); } diff --git a/lib/public/app.php b/lib/public/app.php index 38c51af9cdb..28411933beb 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -34,28 +34,6 @@ namespace OCP; * This class provides functions to manage apps in ownCloud */ class App { - - /** - * @brief Makes owncloud aware of this app - * @brief This call is deprecated and not necessary to use. - * @param $data array with all information - * @returns true/false - * - * This function registers the application. $data is an associative array. - * The following keys are required: - * - id: id of the application, has to be unique ('addressbook') - * - name: Human readable name ('Addressbook') - * - version: array with Version (major, minor, bugfix) ( array(1, 0, 2)) - * - * The following keys are optional: - * - order: integer, that influences the position of your application in - * a list of applications. Lower values come first. - * - */ - public static function register( $data ){ - } - - /** * @brief adds an entry to the navigation * @param $data array containing the data diff --git a/lib/search/provider.php b/lib/search/provider.php index 838ab696d04..b3ee79b4770 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -2,13 +2,17 @@ /** * provides search functionalty */ -class OC_Search_Provider { - public function __construct($options){} +abstract class OC_Search_Provider { + private $options; + + public function __construct($options){ + $this->options=$options; + } /** * search for $query * @param string $query * @return array An array of OC_Search_Result's */ - public function search($query){} + abstract public function search($query); } diff --git a/lib/user/database.php b/lib/user/database.php index a48b8357d64..cc27b3ddbfd 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -39,7 +39,6 @@ require_once 'phpass/PasswordHash.php'; * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ class OC_User_Database extends OC_User_Backend { - static private $userGroupCache=array(); /** * @var PasswordHash */ @@ -87,7 +86,7 @@ class OC_User_Database extends OC_User_Backend { public function deleteUser( $uid ){ // Delete user-group-relation $query = OC_DB::prepare( "DELETE FROM `*PREFIX*users` WHERE uid = ?" ); - $result = $query->execute( array( $uid )); + $query->execute( array( $uid )); return true; } @@ -104,11 +103,10 @@ class OC_User_Database extends OC_User_Backend { $hasher=$this->getHasher(); $hash = $hasher->HashPassword($password.OC_Config::getValue('passwordsalt', '')); $query = OC_DB::prepare( "UPDATE *PREFIX*users SET password = ? WHERE uid = ?" ); - $result = $query->execute( array( $hash, $uid )); + $query->execute( array( $hash, $uid )); return true; - } - else{ + }else{ return false; } } diff --git a/lib/user/example.php b/lib/user/example.php index 7f3fd1b8578..77246d8136c 100644 --- a/lib/user/example.php +++ b/lib/user/example.php @@ -35,9 +35,7 @@ abstract class OC_User_Example extends OC_User_Backend { * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. */ - public function createUser($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function createUser($uid, $password); /** * @brief Set password @@ -47,9 +45,7 @@ abstract class OC_User_Example extends OC_User_Backend { * * Change the password of a user */ - public function setPassword($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function setPassword($uid, $password); /** * @brief Check if the password is correct @@ -60,7 +56,5 @@ abstract class OC_User_Example extends OC_User_Backend { * Check if the password is correct without logging in the user * returns the user id or false */ - public function checkPassword($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function checkPassword($uid, $password); } diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php index b2fcce93c5b..f484ffa78f7 100644 --- a/tests/lib/user/database.php +++ b/tests/lib/user/database.php @@ -21,7 +21,6 @@ */ class Test_User_Database extends Test_User_Backend { - private $user=array(); /** * get a new unique user name * test cases can override this in order to clean up created user -- cgit v1.2.3 From 51566e87c7343385ae3b6854386c20974c94a53d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 02:31:43 +0200 Subject: add prefix option to OC_Cache::clear --- lib/cache.php | 7 ++++--- lib/cache/apc.php | 5 +++-- lib/cache/broker.php | 6 +++--- lib/cache/file.php | 5 +++-- lib/cache/xcache.php | 5 +++-- tests/lib/cache.php | 21 +++++++++++++++++++++ 6 files changed, 37 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/lib/cache.php b/lib/cache.php index 6f4b3e6e3f6..36f409ab71a 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -99,12 +99,13 @@ class OC_Cache { } /** - * clear the user cache + * clear the user cache of all entries starting with a prefix + * @param string prefix (optional) * @return bool */ - static public function clear() { + static public function clear($prefix='') { $user_cache = self::getUserCache(); - return $user_cache->clear(); + return $user_cache->clear($prefix); } /** diff --git a/lib/cache/apc.php b/lib/cache/apc.php index 6cf47d0c158..c192fe2f196 100644 --- a/lib/cache/apc.php +++ b/lib/cache/apc.php @@ -43,14 +43,15 @@ class OC_Cache_APC { return apc_delete($this->getNamespace().$key); } - public function clear(){ - $ns = $this->getNamespace(); + public function clear($prefix=''){ + $ns = $this->getNamespace().$prefix; $cache = apc_cache_info('user'); foreach($cache['cache_list'] as $entry) { if (strpos($entry['info'], $ns) === 0) { apc_delete($entry['info']); } } + return true; } } if(!function_exists('apc_exists')) { diff --git a/lib/cache/broker.php b/lib/cache/broker.php index 931d0dd407e..c2aceabaf53 100644 --- a/lib/cache/broker.php +++ b/lib/cache/broker.php @@ -46,8 +46,8 @@ class OC_Cache_Broker { return $this->slow_cache->remove($key); } - public function clear(){ - $this->fast_cache->clear(); - $this->slow_cache->clear(); + public function clear($prefix=''){ + $this->fast_cache->clear($prefix); + $this->slow_cache->clear($prefix); } } diff --git a/lib/cache/file.php b/lib/cache/file.php index 0b7d3e30508..562c3d17167 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -62,15 +62,16 @@ class OC_Cache_File{ return $storage->unlink($key); } - public function clear(){ + public function clear($prefix=''){ $storage = $this->getStorage(); if($storage and $storage->is_dir('/')){ $dh=$storage->opendir('/'); while($file=readdir($dh)){ - if($file!='.' and $file!='..'){ + if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)){ $storage->unlink('/'.$file); } } } + return true; } } diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index bd55cee8f6b..951f9b47545 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -43,7 +43,8 @@ class OC_Cache_XCache { return xcache_unset($this->getNamespace().$key); } - public function clear(){ - return xcache_unset_by_prefix($this->getNamespace()); + public function clear($prefix=''){ + xcache_unset_by_prefix($this->getNamespace().$prefix); + return true; } } diff --git a/tests/lib/cache.php b/tests/lib/cache.php index bb5cfc6ee19..511999be956 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -42,6 +42,27 @@ abstract class Test_Cache extends UnitTestCase { $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); $this->assertTrue($this->instance->remove('value1')); + $this->assertFalse($this->instance->hasKey('value1')); + } + + function testClear(){ + $value='ipsum lorum'; + $this->instance->set('1_value1',$value); + $this->instance->set('1_value2',$value); + $this->instance->set('2_value1',$value); + $this->instance->set('3_value1',$value); + + $this->assertTrue($this->instance->clear('1_')); + $this->assertFalse($this->instance->hasKey('1_value1')); + $this->assertFalse($this->instance->hasKey('1_value2')); + $this->assertTrue($this->instance->hasKey('2_value1')); + $this->assertTrue($this->instance->hasKey('3_value1')); + + $this->assertTrue($this->instance->clear()); + $this->assertFalse($this->instance->hasKey('1_value1')); + $this->assertFalse($this->instance->hasKey('1_value2')); + $this->assertFalse($this->instance->hasKey('2_value1')); + $this->assertFalse($this->instance->hasKey('3_value1')); } function testTTL(){ -- cgit v1.2.3 From ab7a2d43e810da66087f3abf4a87afff219a33c0 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 23 Jul 2012 22:07:42 +0200 Subject: create a user for Test_Cache_File to allow unit tesing within ci --- tests/lib/cache/file.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index c33c513fcff..be2a2a72778 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -22,7 +22,7 @@ class Test_Cache_File extends Test_Cache { function skip() { - $this->skipUnless(OC_User::isLoggedIn()); + //$this->skipUnless(OC_User::isLoggedIn()); } public function setUp(){ @@ -39,6 +39,13 @@ class Test_Cache_File extends Test_Cache { OC_Filesystem::clearMounts(); OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); + //login + if (OC_User::userExists('test')) + OC_User::deleteUser('test'); + OC_User::createUser('test', 'testtesttest'); + + OC_User::login('test', 'testtesttest'); + //set up the users dir $rootView=new OC_FilesystemView(''); $rootView->mkdir('/'.OC_User::getUser()); -- cgit v1.2.3 From 59364366d8c69ca217fb817535d1b5d1df316841 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 23 Jul 2012 22:32:07 +0200 Subject: use dummy user backend for oc_cache_file tests --- tests/lib/cache/file.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index be2a2a72778..28778efb68c 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -21,6 +21,8 @@ */ class Test_Cache_File extends Test_Cache { + private $user; + function skip() { //$this->skipUnless(OC_User::isLoggedIn()); } @@ -39,17 +41,23 @@ class Test_Cache_File extends Test_Cache { OC_Filesystem::clearMounts(); OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); + OC_User::clearBackends(); + OC_User::useBackend(new OC_User_Dummy()); + //login - if (OC_User::userExists('test')) - OC_User::deleteUser('test'); - OC_User::createUser('test', 'testtesttest'); - - OC_User::login('test', 'testtesttest'); + OC_User::createUser('test', 'test'); + + $this->user=OC_User::getUser(); + OC_User::setUserId('test'); //set up the users dir $rootView=new OC_FilesystemView(''); - $rootView->mkdir('/'.OC_User::getUser()); + $rootView->mkdir('/test'); $this->instance=new OC_Cache_File(); } + + public function tearDown(){ + OC_User::setUserId($this->user); + } } -- cgit v1.2.3