aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/appconfig.php3
-rw-r--r--tests/lib/group/manager.php37
-rw-r--r--tests/lib/request.php15
-rw-r--r--tests/lib/share/searchresultsorter.php47
4 files changed, 100 insertions, 2 deletions
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index 23dd2549e32..6ae790a9edd 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -1,6 +1,7 @@
<?php
/**
* Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -41,6 +42,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
while ($row = $result->fetchRow()) {
$expected[] = $row['appid'];
}
+ sort($expected);
$apps = \OC_Appconfig::getApps();
$this->assertEquals($expected, $apps);
}
@@ -52,6 +54,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
while($row = $result->fetchRow()) {
$expected[] = $row["configkey"];
}
+ sort($expected);
$keys = \OC_Appconfig::getKeys('testapp');
$this->assertEquals($expected, $keys);
}
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php
index 9d3adf51a0c..90f0e1b35e2 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase {
/**
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
*/
+ $backendGroupCreated = false;
$backend = $this->getMock('\OC_Group_Database');
$backend->expects($this->any())
->method('groupExists')
->with('group1')
- ->will($this->returnValue(false));
+ ->will($this->returnCallback(function () use (&$backendGroupCreated) {
+ return $backendGroupCreated;
+ }));
$backend->expects($this->once())
->method('implementsActions')
->will($this->returnValue(true));
$backend->expects($this->once())
- ->method('createGroup');
+ ->method('createGroup')
+ ->will($this->returnCallback(function () use (&$backendGroupCreated) {
+ $backendGroupCreated = true;
+ }));;
/**
* @var \OC\User\Manager $userManager
@@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getGroups')
->with('1')
->will($this->returnValue(array('group1')));
+ $backend->expects($this->once())
+ ->method('groupExists')
+ ->with('group1')
+ ->will($this->returnValue(true));
/**
* @var \OC\User\Manager $userManager
@@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getGroups')
->with('1')
->will($this->returnValue(array('group1')));
+ $backend1->expects($this->any())
+ ->method('groupExists')
+ ->will($this->returnValue(true));
/**
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
@@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getGroups')
->with('1')
->will($this->returnValue(array('group12', 'group1')));
+ $backend2->expects($this->any())
+ ->method('groupExists')
+ ->will($this->returnValue(true));
/**
* @var \OC\User\Manager $userManager
@@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getGroups')
->with('1', 2, 1)
->will($this->returnValue(array('group1')));
+ $backend1->expects($this->any())
+ ->method('groupExists')
+ ->will($this->returnValue(true));
/**
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
@@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getGroups')
->with('1', 1, 0)
->will($this->returnValue(array('group12')));
+ $backend2->expects($this->any())
+ ->method('groupExists')
+ ->will($this->returnValue(true));
/**
* @var \OC\User\Manager $userManager
@@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getUserGroups')
->with('user1')
->will($this->returnValue(array('group1')));
+ $backend->expects($this->any())
+ ->method('groupExists')
+ ->with('group1')
+ ->will($this->returnValue(true));
/**
* @var \OC\User\Manager $userManager
@@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getUserGroups')
->with('user1')
->will($this->returnValue(array('group1')));
+ $backend1->expects($this->any())
+ ->method('groupExists')
+ ->will($this->returnValue(true));
+
/**
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
*/
@@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
->method('getUserGroups')
->with('user1')
->will($this->returnValue(array('group1', 'group2')));
+ $backend1->expects($this->any())
+ ->method('groupExists')
+ ->will($this->returnValue(true));
/**
* @var \OC\User\Manager $userManager
diff --git a/tests/lib/request.php b/tests/lib/request.php
index c6401a57144..1d77acc70ae 100644
--- a/tests/lib/request.php
+++ b/tests/lib/request.php
@@ -118,6 +118,21 @@ class Test_Request extends PHPUnit_Framework_TestCase {
),
true
),
+ array(
+ 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0',
+ OC_Request::USER_AGENT_FREEBOX,
+ false
+ ),
+ array(
+ 'Mozilla/5.0',
+ OC_Request::USER_AGENT_FREEBOX,
+ true
+ ),
+ array(
+ 'Fake Mozilla/5.0',
+ OC_Request::USER_AGENT_FREEBOX,
+ false
+ ),
);
}
}
diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php
new file mode 100644
index 00000000000..eaf93400a7d
--- /dev/null
+++ b/tests/lib/share/searchresultsorter.php
@@ -0,0 +1,47 @@
+<?php
+/**
+* ownCloud
+*
+* @author Arthur Schiwon
+* @copyright 2014 Arthur Schiwon <blizzz@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_Search extends \PHPUnit_Framework_TestCase {
+ public function testSort() {
+ $search = 'lin';
+ $sorter = new \OC\Share\SearchResultSorter($search, 'foobar');
+
+ $result = array(
+ array('foobar' => 'woot'),
+ array('foobar' => 'linux'),
+ array('foobar' => 'Linus'),
+ array('foobar' => 'Bicyclerepairwoman'),
+ );
+
+ usort($result, array($sorter, 'sort'));
+ $this->assertTrue($result[0]['foobar'] === 'Linus');
+ $this->assertTrue($result[1]['foobar'] === 'linux');
+ $this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman');
+ $this->assertTrue($result[3]['foobar'] === 'woot');
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testSortWrongLog() {
+ $sorter = new \OC\Share\SearchResultSorter('foo', 'bar', 'UTF-8', 'foobar');
+ }
+}