summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-07-25 17:08:18 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-07-25 17:08:18 -0400
commit30b58f56771aa54304069d40a62070c06f5308fc (patch)
treee0bb2bba21c561f96d27bb9cfc09d714aa21d332 /tests
parent4d17ed2f71c8cbb0d34c039aa7953b2427ce5c78 (diff)
parentf25ccaff59c135d7f1f22196bf266916ef131b35 (diff)
downloadnextcloud-server-30b58f56771aa54304069d40a62070c06f5308fc.tar.gz
nextcloud-server-30b58f56771aa54304069d40a62070c06f5308fc.zip
Merge branch 'master' into share_api
Conflicts: apps/calendar/js/loader.js apps/contacts/index.php apps/contacts/js/loader.js apps/files/js/files.js apps/files_sharing/sharedstorage.php lib/filesystemview.php
Diffstat (limited to 'tests')
-rw-r--r--tests/index.php57
-rw-r--r--tests/lib/cache.php21
-rw-r--r--tests/lib/cache/file.php25
-rw-r--r--tests/lib/share/backend.php66
-rw-r--r--tests/lib/share/share.php161
-rw-r--r--tests/lib/user/database.php1
6 files changed, 310 insertions, 21 deletions
diff --git a/tests/index.php b/tests/index.php
index 691bf2a5d45..0be27ee3fd7 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -26,39 +26,64 @@ require_once 'simpletest/mock_objects.php';
require_once 'simpletest/collector.php';
require_once 'simpletest/default_reporter.php';
+$testSuiteName="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;
+
+ if(isset($_SERVER['argv'][2])){
+ $testSuiteName=$testSuiteName." (".$_SERVER['argv'][2].")";
+ }
+ }
+}else{
+ $reporter=new HtmlReporter;
+ $test=isset($_GET['test'])?$_GET['test']:false;
+}
+
+// test suite instance
+$testSuite=new TestSuite($testSuiteName);
+
//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);
}
}
}
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(){
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index 54e60e6569d..28778efb68c 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -21,8 +21,10 @@
*/
class Test_Cache_File extends Test_Cache {
+ private $user;
+
function skip() {
- $this->skipUnless(OC_User::isLoggedIn());
+ //$this->skipUnless(OC_User::isLoggedIn());
}
public function setUp(){
@@ -30,17 +32,32 @@ 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();
OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/');
+ 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');
+
//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);
+ }
}
diff --git a/tests/lib/share/backend.php b/tests/lib/share/backend.php
new file mode 100644
index 00000000000..4f2fcce235e
--- /dev/null
+++ b/tests/lib/share/backend.php
@@ -0,0 +1,66 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+abstract class Test_Share_Backend extends UnitTestCase {
+
+ protected $userBackend;
+ protected $user1;
+ protected $user2;
+ protected $groupBackend;
+ protected $group;
+ protected $itemType;
+ protected $item;
+
+ public function setUp() {
+ OC_User::clearBackends();
+ OC_User::useBackend('dummy');
+ $this->user1 = uniqid('user_');
+ $this->user2 = uniqid('user_');
+ OC_User::createUser($this->user1, 'pass1');
+ OC_User::createUser($this->user2, 'pass2');
+ OC_Group::clearBackends();
+ OC_Group::useBackend(new OC_Group_Dummy);
+ $this->group = uniqid('group_');
+ OC_Group::createGroup($this->group);
+ }
+
+ public function testShareWithUserNonExistentItem() {
+ $this->assertFalse(OCP\Share::share($this->itemType, uniqid('foobar_'), OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithUserItem() {
+ $this->assertTrue(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithGroupNonExistentItem() {
+ $this->assertFalse(OCP\Share::share($this->itemType, uniqid('foobar_'), OCP\Share::SHARETYPE_GROUP, $this->group, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithGroupItem() {
+ $this->assertTrue(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_GROUP, $this->group, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithUserAlreadySharedWith() {
+ $this->assertTrue(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
+ $this->assertFalse(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
+ }
+
+}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
new file mode 100644
index 00000000000..eca2c9bc58a
--- /dev/null
+++ b/tests/lib/share/share.php
@@ -0,0 +1,161 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+class Test_Share_Base extends UnitTestCase {
+
+ protected $itemType;
+ protected $userBackend;
+ protected $user1;
+ protected $user2;
+ protected $groupBackend;
+ protected $group1;
+ protected $group2;
+
+
+ public function setUp() {
+ OC_User::clearBackends();
+ OC_User::useBackend('dummy');
+ $this->user1 = uniqid('user_');
+ $this->user2 = uniqid('user_');
+ OC_User::createUser($this->user1, 'pass1');
+ OC_User::createUser($this->user2, 'pass2');
+ OC_Group::clearBackends();
+ OC_Group::useBackend(new OC_Group_Dummy);
+ $this->group1 = uniqid('group_');
+ $this->group2 = uniqid('group_');
+ OC_Group::createGroup($this->group1);
+ OC_Group::createGroup($this->group2);
+ }
+
+ public function testShareInvalidShareType() {
+ $this->assertFalse(OCP\Share::share('file', 'test.txt', 'foobar', $this->user1, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareInvalidItemType() {
+ $this->assertFalse(OCP\Share::share('foobar', 'test.txt', OCP\Share::SHARETYPE_USER, $this->user1, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithSelf() {
+ OC_User::setUserId($this->user1);
+ $this->assertFalse(OCP\Share::share('file', 'test.txt', OCP\Share::SHARETYPE_USER, $this->user1, OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithNonExistentUser() {
+ $this->assertFalse(OCP\Share::share('file', 'test.txt', OCP\Share::SHARETYPE_USER, 'foobar', OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithUserOwnerNotPartOfGroup() {
+
+ }
+
+ public function testShareWithUserAlreadySharedWith() {
+
+ }
+
+ public function testShareWithNonExistentGroup() {
+ $this->assertFalse(OCP\Share::share('file', 'test.txt', OCP\Share::SHARETYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ));
+ }
+
+ public function testShareWithGroupOwnerNotPartOfGroup() {
+
+ }
+
+
+ public function testShareWithGroupItem() {
+
+ }
+
+ public function testUnshareInvalidShareType() {
+
+ }
+
+ public function testUnshareNonExistentItem() {
+
+ }
+
+ public function testUnshareFromUserItem() {
+
+ }
+
+ public function testUnshareFromGroupItem() {
+
+ }
+
+
+
+
+
+ // Test owner not in same group (false)
+
+
+
+ // Test non-existant item type
+
+ // Test valid item
+
+ // Test existing shared item (false)
+
+ // Test unsharing item
+
+ // Test setting permissions
+
+ // Test setting permissions not as owner (false)
+
+ // Test setting target
+
+ // Test setting target as owner (false)
+
+ // Spam reshares
+
+
+
+ // Test non-existant group
+
+
+ // Test owner not part of group
+
+ // Test existing shared item with group
+
+ // Test valid item, valid name for all users
+
+ // Test unsharing item
+
+ // Test item with name conflicts
+
+ // Test unsharing item
+
+ // Test setting permissions
+
+ // Test setting target no name conflicts
+
+ // Test setting target with conflicts
+
+ // Spam reshares
+
+
+
+
+
+ public function testPrivateLink() {
+
+ }
+
+}
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