summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/acceptance/tests/pages/files.page.js2
-rw-r--r--tests/data/testcal.ics13
-rw-r--r--tests/data/testcontact.vcf6
-rw-r--r--tests/lib/cache/file.php6
-rw-r--r--tests/lib/cache/usercache.php5
-rw-r--r--tests/lib/config.php3
-rw-r--r--tests/lib/connector/sabre/directory.php64
-rw-r--r--tests/lib/connector/sabre/file.php63
-rw-r--r--tests/lib/db.php55
-rw-r--r--tests/lib/files/cache/cache.php4
-rw-r--r--tests/lib/group/manager.php310
-rw-r--r--tests/lib/httphelper.php88
-rw-r--r--tests/lib/largefilehelpergetfilesize.php3
-rw-r--r--tests/lib/preview.php4
-rw-r--r--tests/lib/security/certificate.php5
-rw-r--r--tests/lib/streamwrappers.php10
-rw-r--r--tests/lib/updater.php34
-rw-r--r--tests/lib/util.php29
18 files changed, 651 insertions, 53 deletions
diff --git a/tests/acceptance/tests/pages/files.page.js b/tests/acceptance/tests/pages/files.page.js
index 8efe33ee99a..e5445309b26 100644
--- a/tests/acceptance/tests/pages/files.page.js
+++ b/tests/acceptance/tests/pages/files.page.js
@@ -78,7 +78,7 @@
};
FilesPage.prototype.deleteButtonId = function(fileName) {
- return by.css("tr[data-file='" + fileName + "'] .action.delete.delete-icon");
+ return by.css("tr[data-file='" + fileName + "'] .action.delete.icon-delete");
};
//================ SHARED ===============================================//
diff --git a/tests/data/testcal.ics b/tests/data/testcal.ics
deleted file mode 100644
index e05f01ba1c2..00000000000
--- a/tests/data/testcal.ics
+++ /dev/null
@@ -1,13 +0,0 @@
-BEGIN:VCALENDAR
-PRODID:-//some random cal software//EN
-VERSION:2.0
-BEGIN:VEVENT
-CREATED:20130102T120000Z
-LAST-MODIFIED:20130102T120000Z
-DTSTAMP:20130102T120000Z
-UID:f106ecdf-c716-43ef-9d94-4e6f19f2fcfb
-SUMMARY:a test cal file
-DTSTART;VALUE=DATE:20130101
-DTEND;VALUE=DATE:20130102
-END:VEVENT
-END:VCALENDAR \ No newline at end of file
diff --git a/tests/data/testcontact.vcf b/tests/data/testcontact.vcf
deleted file mode 100644
index 2af963d6916..00000000000
--- a/tests/data/testcontact.vcf
+++ /dev/null
@@ -1,6 +0,0 @@
-BEGIN:VCARD
-VERSION:3.0
-PRODID:-//some random contact software//EN
-N:def;abc;;;
-FN:abc def
-END:VCARD \ No newline at end of file
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index 3767c83fcb1..0e19c105cd1 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -46,8 +46,8 @@ class FileCache extends \Test_Cache {
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage,array(),'/');
$datadir = str_replace('local::', '', $storage->getId());
- $this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
- \OC_Config::setValue('datadirectory', $datadir);
+ $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');
+ \OC_Config::setValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -67,6 +67,6 @@ class FileCache extends \Test_Cache {
public function tearDown() {
\OC_User::setUserId($this->user);
- \OC_Config::setValue('datadirectory', $this->datadir);
+ \OC_Config::setValue('cachedirectory', $this->datadir);
}
}
diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php
index 21b7f848ab6..a1b6af1c55d 100644
--- a/tests/lib/cache/usercache.php
+++ b/tests/lib/cache/usercache.php
@@ -42,8 +42,8 @@ class UserCache extends \Test_Cache {
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage,array(),'/');
$datadir = str_replace('local::', '', $storage->getId());
- $this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
- \OC_Config::setValue('datadirectory', $datadir);
+ $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');
+ \OC_Config::setValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -63,6 +63,5 @@ class UserCache extends \Test_Cache {
public function tearDown() {
\OC_User::setUserId($this->user);
- \OC_Config::setValue('datadirectory', $this->datadir);
}
}
diff --git a/tests/lib/config.php b/tests/lib/config.php
index c67a66c832e..f739df3ce97 100644
--- a/tests/lib/config.php
+++ b/tests/lib/config.php
@@ -79,6 +79,9 @@ class Test_Config extends PHPUnit_Framework_TestCase {
* @expectedException \OC\HintException
*/
public function testWriteData() {
+ if (\OC_Util::runningOnWindows()) {
+ throw new \OC\HintException('this is ireelevent for windows');
+ }
$config = new OC\Config('/non-writable');
$config->setValue('foo', 'bar');
}
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php
index 8a1550ffa95..453d8e8d42a 100644
--- a/tests/lib/connector/sabre/directory.php
+++ b/tests/lib/connector/sabre/directory.php
@@ -8,18 +8,24 @@
*/
class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
+ private $view;
+ private $info;
+
+ public function setUp() {
+ $this->view = $this->getMock('OC\Files\View', array(), array(), '', false);
+ $this->info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
+ }
+
private function getRootDir() {
- $view = $this->getMock('OC\Files\View', array(), array(), '', false);
- $view->expects($this->once())
+ $this->view->expects($this->once())
->method('getRelativePath')
->will($this->returnValue(''));
- $info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
- $info->expects($this->once())
+ $this->info->expects($this->once())
->method('getPath')
->will($this->returnValue(''));
- return new OC_Connector_Sabre_Directory($view, $info);
+ return new OC_Connector_Sabre_Directory($this->view, $this->info);
}
/**
@@ -45,4 +51,52 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
$dir = $this->getRootDir();
$dir->delete();
}
+
+ /**
+ *
+ */
+ public function testDeleteFolderWhenAllowed() {
+ // deletion allowed
+ $this->info->expects($this->once())
+ ->method('isDeletable')
+ ->will($this->returnValue(true));
+
+ // but fails
+ $this->view->expects($this->once())
+ ->method('rmdir')
+ ->will($this->returnValue(true));
+
+ $dir = $this->getRootDir();
+ $dir->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteFolderFailsWhenNotAllowed() {
+ $this->info->expects($this->once())
+ ->method('isDeletable')
+ ->will($this->returnValue(false));
+
+ $dir = $this->getRootDir();
+ $dir->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteFolderThrowsWhenDeletionFailed() {
+ // deletion allowed
+ $this->info->expects($this->once())
+ ->method('isDeletable')
+ ->will($this->returnValue(true));
+
+ // but fails
+ $this->view->expects($this->once())
+ ->method('rmdir')
+ ->will($this->returnValue(false));
+
+ $dir = $this->getRootDir();
+ $dir->delete();
+ }
}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index 1602c5181fe..0993a27f372 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -143,4 +143,67 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
// action
$file->put('test data');
}
+
+ /**
+ *
+ */
+ public function testDeleteWhenAllowed() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array());
+
+ $view->expects($this->once())
+ ->method('unlink')
+ ->will($this->returnValue(true));
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteThrowsWhenDeletionNotAllowed() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array());
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => 0
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteThrowsWhenDeletionFailed() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array());
+
+ // but fails
+ $view->expects($this->once())
+ ->method('unlink')
+ ->will($this->returnValue(false));
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->delete();
+ }
}
diff --git a/tests/lib/db.php b/tests/lib/db.php
index 1f62413cbe4..fb673b8092b 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -27,6 +27,11 @@ class Test_DB extends PHPUnit_Framework_TestCase {
*/
private $table3;
+ /**
+ * @var string
+ */
+ private $table4;
+
public function setUp() {
$dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml';
@@ -263,4 +268,54 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ? WHERE `fullname` = ?");
return $query->execute(array($uri, $fullname));
}
+
+ public function testILIKE() {
+ $table = "*PREFIX*{$this->table2}";
+
+ $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)");
+ $query->execute(array('fooBAR', 'foo', 'bar'));
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
+ $result = $query->execute(array('foobar'));
+ $this->assertCount(0, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
+ $result = $query->execute(array('foobar'));
+ $this->assertCount(1, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
+ $result = $query->execute(array('foo'));
+ $this->assertCount(0, $result->fetchAll());
+ }
+
+ public function testILIKEWildcard() {
+ $table = "*PREFIX*{$this->table2}";
+
+ $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)");
+ $query->execute(array('FooBAR', 'foo', 'bar'));
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
+ $result = $query->execute(array('%bar'));
+ $this->assertCount(0, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
+ $result = $query->execute(array('foo%'));
+ $this->assertCount(0, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?");
+ $result = $query->execute(array('%ba%'));
+ $this->assertCount(0, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
+ $result = $query->execute(array('%bar'));
+ $this->assertCount(1, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
+ $result = $query->execute(array('foo%'));
+ $this->assertCount(1, $result->fetchAll());
+
+ $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?");
+ $result = $query->execute(array('%ba%'));
+ $this->assertCount(1, $result->fetchAll());
+ }
}
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 03fe4b26e7f..969740419c6 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -336,6 +336,10 @@ class Cache extends \PHPUnit_Framework_TestCase {
$storageId = $this->storage->getId();
$data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
$id = $this->cache->put('foo', $data);
+
+ if (strlen($storageId) > 64) {
+ $storageId = md5($storageId);
+ }
$this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
}
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php
index 6799a598d42..70d9783946a 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -346,14 +346,80 @@ class Manager extends \PHPUnit_Framework_TestCase {
$this->assertEquals('group2', $group2->getGID());
}
- public function testDisplayNamesInGroupMultipleUserBackends() {
+ public function testDisplayNamesInGroupWithOneUserBackend() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $backend->expects($this->exactly(1))
+ ->method('groupExists')
+ ->with('testgroup')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->any())
+ ->method('InGroup')
+ ->will($this->returnCallback(function($uid, $gid) {
+ switch($uid) {
+ case 'user1' : return false;
+ case 'user2' : return true;
+ case 'user3' : return false;
+ case 'user33': return true;
+ default:
+ return null;
+ }
+ }));
+
+ $backend->expects($this->once())
+ ->method('implementsActions')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->once())
+ ->method('countUsersInGroup')
+ ->with('testgroup', '')
+ ->will($this->returnValue(2));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
$userBackend = $this->getMock('\OC_User_Backend');
- $user1 = new User('user1', $userBackend);
- $user2 = new User('user2', $userBackend);
- $user3 = new User('user3', $userBackend);
- $user4 = new User('user33', $userBackend);
+ $userManager->expects($this->any())
+ ->method('search')
+ ->with('user3')
+ ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
+ switch($offset) {
+ case 0 : return array('user3' => new User('user3', $userBackend),
+ 'user33' => new User('user33', $userBackend));
+ case 2 : return array();
+ }
+ }));
+
+ $userManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($uid) use ($userBackend) {
+ switch($uid) {
+ case 'user1' : return new User('user1', $userBackend);
+ case 'user2' : return new User('user2', $userBackend);
+ case 'user3' : return new User('user3', $userBackend);
+ case 'user33': return new User('user33', $userBackend);
+ default:
+ return null;
+ }
+ }));
+
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ $users = $manager->displayNamesInGroup('testgroup', 'user3');
+ $this->assertEquals(1, count($users));
+ $this->assertFalse(isset($users['user1']));
+ $this->assertFalse(isset($users['user2']));
+ $this->assertFalse(isset($users['user3']));
+ $this->assertTrue(isset($users['user33']));
+ }
+ public function testDisplayNamesInGroupWithOneUserBackendWithLimitSpecified() {
/**
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
*/
@@ -363,7 +429,141 @@ class Manager extends \PHPUnit_Framework_TestCase {
->with('testgroup')
->will($this->returnValue(true));
- $backend->expects($this->once())
+ $backend->expects($this->any())
+ ->method('InGroup')
+ ->will($this->returnCallback(function($uid, $gid) {
+ switch($uid) {
+ case 'user1' : return false;
+ case 'user2' : return true;
+ case 'user3' : return false;
+ case 'user33': return true;
+ case 'user333': return true;
+ default:
+ return null;
+ }
+ }));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $userBackend = $this->getMock('\OC_User_Backend');
+
+ $userManager->expects($this->any())
+ ->method('search')
+ ->with('user3')
+ ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
+ switch($offset) {
+ case 0 : return array('user3' => new User('user3', $userBackend),
+ 'user33' => new User('user33', $userBackend));
+ case 2 : return array('user333' => new User('user333', $userBackend));
+ }
+ }));
+
+ $userManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($uid) use ($userBackend) {
+ switch($uid) {
+ case 'user1' : return new User('user1', $userBackend);
+ case 'user2' : return new User('user2', $userBackend);
+ case 'user3' : return new User('user3', $userBackend);
+ case 'user33': return new User('user33', $userBackend);
+ case 'user333': return new User('user333', $userBackend);
+ default:
+ return null;
+ }
+ }));
+
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ $users = $manager->displayNamesInGroup('testgroup', 'user3', 1);
+ $this->assertEquals(1, count($users));
+ $this->assertFalse(isset($users['user1']));
+ $this->assertFalse(isset($users['user2']));
+ $this->assertFalse(isset($users['user3']));
+ $this->assertTrue(isset($users['user33']));
+ $this->assertFalse(isset($users['user333']));
+ }
+
+ public function testDisplayNamesInGroupWithOneUserBackendWithLimitAndOffsetSpecified() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $backend->expects($this->exactly(1))
+ ->method('groupExists')
+ ->with('testgroup')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->any())
+ ->method('InGroup')
+ ->will($this->returnCallback(function($uid, $gid) {
+ switch($uid) {
+ case 'user1' : return false;
+ case 'user2' : return true;
+ case 'user3' : return false;
+ case 'user33': return true;
+ case 'user333': return true;
+ default:
+ return null;
+ }
+ }));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $userBackend = $this->getMock('\OC_User_Backend');
+
+ $userManager->expects($this->any())
+ ->method('search')
+ ->with('user3')
+ ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
+ switch($offset) {
+ case 0 : return array('user3' => new User('user3', $userBackend),
+ 'user33' => new User('user33', $userBackend));
+ case 2 : return array('user333' => new User('user333', $userBackend));
+ }
+ }));
+
+ $userManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($uid) use ($userBackend) {
+ switch($uid) {
+ case 'user1' : return new User('user1', $userBackend);
+ case 'user2' : return new User('user2', $userBackend);
+ case 'user3' : return new User('user3', $userBackend);
+ case 'user33': return new User('user33', $userBackend);
+ case 'user333': return new User('user333', $userBackend);
+ default:
+ return null;
+ }
+ }));
+
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ $users = $manager->displayNamesInGroup('testgroup', 'user3', 1, 1);
+ $this->assertEquals(1, count($users));
+ $this->assertFalse(isset($users['user1']));
+ $this->assertFalse(isset($users['user2']));
+ $this->assertFalse(isset($users['user3']));
+ $this->assertFalse(isset($users['user33']));
+ $this->assertTrue(isset($users['user333']));
+ }
+
+ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmpty() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $backend->expects($this->exactly(1))
+ ->method('groupExists')
+ ->with('testgroup')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->once())
->method('usersInGroup')
->with('testgroup', '', -1, 0)
->will($this->returnValue(array('user2', 'user33')));
@@ -373,10 +573,6 @@ class Manager extends \PHPUnit_Framework_TestCase {
*/
$userManager = $this->getMock('\OC\User\Manager');
$userBackend = $this->getMock('\OC_User_Backend');
- $userManager->expects($this->once())
- ->method('search')
- ->with('user3')
- ->will($this->returnValue(array('user3' => $user3, 'user33' => $user4)));
$userManager->expects($this->any())
->method('get')
@@ -394,8 +590,100 @@ class Manager extends \PHPUnit_Framework_TestCase {
$manager = new \OC\Group\Manager($userManager);
$manager->addBackend($backend);
- $users = $manager->displayNamesInGroup('testgroup', 'user3');
+ $users = $manager->displayNamesInGroup('testgroup', '');
+ $this->assertEquals(2, count($users));
+ $this->assertFalse(isset($users['user1']));
+ $this->assertTrue(isset($users['user2']));
+ $this->assertFalse(isset($users['user3']));
+ $this->assertTrue(isset($users['user33']));
+ }
+
+ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitSpecified() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $backend->expects($this->exactly(1))
+ ->method('groupExists')
+ ->with('testgroup')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->once())
+ ->method('usersInGroup')
+ ->with('testgroup', '', 1, 0)
+ ->will($this->returnValue(array('user2')));
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $userBackend = $this->getMock('\OC_User_Backend');
+
+ $userManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($uid) use ($userBackend) {
+ switch($uid) {
+ case 'user1' : return new User('user1', $userBackend);
+ case 'user2' : return new User('user2', $userBackend);
+ case 'user3' : return new User('user3', $userBackend);
+ case 'user33': return new User('user33', $userBackend);
+ default:
+ return null;
+ }
+ }));
+
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ $users = $manager->displayNamesInGroup('testgroup', '', 1);
+ $this->assertEquals(1, count($users));
+ $this->assertFalse(isset($users['user1']));
+ $this->assertTrue(isset($users['user2']));
+ $this->assertFalse(isset($users['user3']));
+ $this->assertFalse(isset($users['user33']));
+ }
+
+ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitAndOffsetSpecified() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $backend->expects($this->exactly(1))
+ ->method('groupExists')
+ ->with('testgroup')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->once())
+ ->method('usersInGroup')
+ ->with('testgroup', '', 1, 1)
+ ->will($this->returnValue(array('user33')));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $userBackend = $this->getMock('\OC_User_Backend');
+
+ $userManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($uid) use ($userBackend) {
+ switch($uid) {
+ case 'user1' : return new User('user1', $userBackend);
+ case 'user2' : return new User('user2', $userBackend);
+ case 'user3' : return new User('user3', $userBackend);
+ case 'user33': return new User('user33', $userBackend);
+ default:
+ return null;
+ }
+ }));
+
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ $users = $manager->displayNamesInGroup('testgroup', '', 1, 1);
$this->assertEquals(1, count($users));
+ $this->assertFalse(isset($users['user1']));
+ $this->assertFalse(isset($users['user2']));
+ $this->assertFalse(isset($users['user3']));
$this->assertTrue(isset($users['user33']));
}
diff --git a/tests/lib/httphelper.php b/tests/lib/httphelper.php
new file mode 100644
index 00000000000..191200aee3d
--- /dev/null
+++ b/tests/lib/httphelper.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class TestHTTPHelper extends \PHPUnit_Framework_TestCase {
+
+ /** @var \OC\AllConfig*/
+ private $config;
+ /** @var \OC\HTTPHelper */
+ private $httpHelperMock;
+
+ function setUp() {
+ $this->config = $this->getMockBuilder('\OC\AllConfig')
+ ->disableOriginalConstructor()->getMock();
+ $this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
+ ->setConstructorArgs(array($this->config))
+ ->setMethods(array('getHeaders'))
+ ->getMock();
+ }
+
+ public function testIsHTTPProvider() {
+ return array(
+ array('http://wwww.owncloud.org/enterprise/', true),
+ array('https://wwww.owncloud.org/enterprise/', true),
+ array('HTTPS://WWW.OWNCLOUD.ORG', true),
+ array('HTTP://WWW.OWNCLOUD.ORG', true),
+ array('FILE://WWW.OWNCLOUD.ORG', false),
+ array('file://www.owncloud.org', false),
+ array('FTP://WWW.OWNCLOUD.ORG', false),
+ array('ftp://www.owncloud.org', false),
+ );
+ }
+
+ /**
+ * Note: Not using a dataprovider because onConsecutiveCalls expects not
+ * an array but the function arguments directly
+ */
+ public function testGetFinalLocationOfURLValid() {
+ $url = 'https://www.owncloud.org/enterprise/';
+ $expected = 'https://www.owncloud.com/enterprise/';
+ $this->httpHelperMock->expects($this->any())
+ ->method('getHeaders')
+ ->will($this->onConsecutiveCalls(
+ array('Location' => 'http://www.owncloud.com/enterprise/'),
+ array('Location' => 'https://www.owncloud.com/enterprise/')
+ ));
+ $result = $this->httpHelperMock->getFinalLocationOfURL($url);
+ $this->assertSame($expected, $result);
+ }
+
+ /**
+ * Note: Not using a dataprovider because onConsecutiveCalls expects not
+ * an array but the function arguments directly
+ */
+ public function testGetFinalLocationOfURLInvalid() {
+ $url = 'https://www.owncloud.org/enterprise/';
+ $expected = 'http://www.owncloud.com/enterprise/';
+ $this->httpHelperMock->expects($this->any())
+ ->method('getHeaders')
+ ->will($this->onConsecutiveCalls(
+ array('Location' => 'http://www.owncloud.com/enterprise/'),
+ array('Location' => 'file://etc/passwd'),
+ array('Location' => 'http://www.example.com/')
+ ));
+ $result = $this->httpHelperMock->getFinalLocationOfURL($url);
+ $this->assertSame($expected, $result);
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage URL must begin with HTTPS or HTTP.
+ */
+ public function testGetFinalLocationOfURLException() {
+ $this->httpHelperMock->getFinalLocationOfURL('file://etc/passwd');
+ }
+
+ /**
+ * @dataProvider testIsHTTPProvider
+ */
+ public function testIsHTTP($url, $expected) {
+ $this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url));
+ }
+
+}
diff --git a/tests/lib/largefilehelpergetfilesize.php b/tests/lib/largefilehelpergetfilesize.php
index 86ce6d295cf..21a0aa9a233 100644
--- a/tests/lib/largefilehelpergetfilesize.php
+++ b/tests/lib/largefilehelpergetfilesize.php
@@ -19,7 +19,8 @@ class LargeFileHelperGetFileSize extends \PHPUnit_Framework_TestCase {
public function setUp() {
parent::setUp();
- $this->filename = __DIR__ . '/../data/data.tar.gz';
+ $ds = DIRECTORY_SEPARATOR;
+ $this->filename = dirname(__DIR__) . "{$ds}data{$ds}data.tar.gz";
$this->fileSize = 4195;
$this->helper = new \OC\LargeFileHelper;
}
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 4ef61fb8257..2febe524cba 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -97,13 +97,9 @@ class Preview extends \PHPUnit_Framework_TestCase {
public function txtBlacklist() {
$txt = 'random text file';
- $ics = file_get_contents(__DIR__ . '/../data/testcal.ics');
- $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf');
return array(
array('txt', $txt, false),
- array('ics', $ics, true),
- array('vcf', $vcf, true),
);
}
diff --git a/tests/lib/security/certificate.php b/tests/lib/security/certificate.php
index db33dd00d99..898f583a43c 100644
--- a/tests/lib/security/certificate.php
+++ b/tests/lib/security/certificate.php
@@ -49,11 +49,6 @@ class CertificateTest extends \PHPUnit_Framework_TestCase {
$this->assertSame('Internet Widgits Pty Ltd', $this->invalidCertificate->getOrganization());
}
- function testGetSerial() {
- $this->assertSame('7F:FF:FF:FF:FF:FF:FF:FF', $this->goodCertificate->getSerial());
- $this->assertSame('7F:FF:FF:FF:FF:FF:FF:FF', $this->invalidCertificate->getSerial());
- }
-
function testGetIssueDate() {
$expected = new DateTime('2014-08-27 08:45:52 GMT');
$this->assertEquals($expected->getTimestamp(), $this->goodCertificate->getIssueDate()->getTimestamp());
diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php
index d15b712139d..1b61446f4dc 100644
--- a/tests/lib/streamwrappers.php
+++ b/tests/lib/streamwrappers.php
@@ -79,6 +79,16 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase {
$this->assertEquals(array('.', '..', 'bar.txt', 'foo.txt'), scandir('oc:///'));
$this->assertEquals('qwerty', file_get_contents('oc:///bar.txt'));
+ $fh = fopen('oc:///bar.txt', 'rb');
+ $this->assertSame(0, ftell($fh));
+ $content = fread($fh, 4);
+ $this->assertSame(4, ftell($fh));
+ $this->assertSame('qwer', $content);
+ $content = fread($fh, 1);
+ $this->assertSame(5, ftell($fh));
+ $this->assertSame(0, fseek($fh, 0));
+ $this->assertSame(0, ftell($fh));
+
unlink('oc:///foo.txt');
$this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///'));
}
diff --git a/tests/lib/updater.php b/tests/lib/updater.php
new file mode 100644
index 00000000000..4488744fa1d
--- /dev/null
+++ b/tests/lib/updater.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC;
+
+class UpdaterTest extends \PHPUnit_Framework_TestCase {
+
+ public function testVersionCompatbility() {
+ return array(
+ array('1.0.0.0', '2.2.0', true),
+ array('1.1.1.1', '2.0.0', true),
+ array('5.0.3', '4.0.3', false),
+ array('12.0.3', '13.4.5', true),
+ array('1', '2', true),
+ array('2', '2', true),
+ array('6.0.5', '6.0.6', true),
+ array('5.0.6', '7.0.4', false)
+ );
+ }
+
+ /**
+ * @dataProvider testVersionCompatbility
+ */
+ function testIsUpgradePossible($oldVersion, $newVersion, $result) {
+ $updater = new Updater();
+ $this->assertSame($result, $updater->isUpgradePossible($oldVersion, $newVersion));
+ }
+
+} \ No newline at end of file
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 8964f9f2666..600b794d8b8 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -37,6 +37,30 @@ class Test_Util extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $result);
}
+ function testFormatDateWithTZ() {
+ date_default_timezone_set("UTC");
+
+ $result = OC_Util::formatDate(1350129205, false, 'Europe/Berlin');
+ $expected = 'October 13, 2012 13:53';
+ $this->assertEquals($expected, $result);
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ function testFormatDateWithInvalidTZ() {
+ OC_Util::formatDate(1350129205, false, 'Mordor/Barad-dûr');
+ }
+
+ function testFormatDateWithTZFromSession() {
+ date_default_timezone_set("UTC");
+
+ \OC::$server->getSession()->set('timezone', 3);
+ $result = OC_Util::formatDate(1350129205, false);
+ $expected = 'October 13, 2012 14:53';
+ $this->assertEquals($expected, $result);
+ }
+
function testCallRegister() {
$result = strlen(OC_Util::callRegister());
$this->assertEquals(30, $result);
@@ -116,7 +140,10 @@ class Test_Util extends PHPUnit_Framework_TestCase {
function testGetInstanceIdGeneratesValidId() {
OC_Config::deleteKey('instanceid');
- $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
+ $instanceId = OC_Util::getInstanceId();
+ $this->assertStringStartsWith('oc', $instanceId);
+ $matchesRegex = preg_match('/^[a-z0-9]+$/', $instanceId);
+ $this->assertSame(1, $matchesRegex);
}
/**