From 67787f571edde70ed3cee8a4cd5b55d52208e9e4 Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Fri, 6 Nov 2009 00:08:03 +0100
Subject: [PATCH] Additional testing for the search operations.
---
.../Kolab/Server/Search/Operation/Guidforuid.php | 2 +-
.../Server/Search/Operation/Restrictgroups.php | 2 +-
.../Server/Search/Operation/GuidforuidTest.php | 61 ++++++++++++++++++++++
.../Server/Search/Operation/RestrictgroupsTest.php | 58 ++++++++++++++++++++
.../Server/Search/Operation/RestrictkolabTest.php | 58 ++------------------
.../Kolab/Server/Constraints/Restrictgroups.php | 46 ++++++++++++++++
.../Server/Constraints/Restrictkolabusers.php | 46 ++++++++++++++++
.../Horde/Kolab/Server/Constraints/Searchuid.php | 45 ++++++++++++++++
.../test/Horde/Kolab/Server/TestCase.php | 19 +++++++
9 files changed, 281 insertions(+), 56 deletions(-)
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforuidTest.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictgroups.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictkolabusers.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchuid.php
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php
index 0acbc678f..27247eada 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php
@@ -40,7 +40,7 @@ extends Horde_Kolab_Server_Search_Operation_Restrictkolab
public function searchGuidForUid($uid)
{
$criteria = new Horde_Kolab_Server_Query_Element_Equals(
- 'Uid', $uid
+ 'uid', $uid
);
return parent::searchRestrictKolab($criteria);
}
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictgroups.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictgroups.php
index bdd083a76..494e838da 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictgroups.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictgroups.php
@@ -43,7 +43,7 @@ extends Horde_Kolab_Server_Search_Operation_Guid
$criteria = new Horde_Kolab_Server_Query_Element_And(
array(
new Horde_Kolab_Server_Query_Element_Equals(
- 'Objectclass',
+ 'objectBlass',
Horde_Kolab_Server_Object_Groupofnames::OBJECTCLASS_GROUPOFNAMES
),
$criteria
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforuidTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforuidTest.php
new file mode 100644
index 000000000..b7bd5e8ec
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforuidTest.php
@@ -0,0 +1,61 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * Require our basic test case definition
+ */
+require_once dirname(__FILE__) . '/../../../../TestCase.php';
+
+/**
+ * Test the search operations by uid.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Kolab_Server_Class_Server_Search_Operation_GuidforuidTest
+extends Horde_Kolab_Server_TestCase
+{
+ public function setUp()
+ {
+ $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface');
+ }
+
+ public function testMethodRestrictkolabHasResultRestrictedToKolabUsers()
+ {
+ $result = $this->getMock('Horde_Kolab_Server_Result_Interface');
+ $result->expects($this->once())
+ ->method('asArray')
+ ->will($this->returnValue(array('a' => 'a')));
+ $this->structure->expects($this->once())
+ ->method('find')
+ ->with(
+ $this->logicalAnd(
+ $this->isRestrictedToKolabUsers(),
+ $this->isSearchingByUid()
+ ),
+ array('attributes' => 'guid')
+ )
+ ->will($this->returnValue($result));
+ $search = new Horde_Kolab_Server_Search_Operation_Guidforuid($this->structure);
+ $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface');
+ $this->assertEquals(array('a'), $search->searchGuidForUid('test'));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.php
new file mode 100644
index 000000000..ff8ad7c5d
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.php
@@ -0,0 +1,58 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * Require our basic test case definition
+ */
+require_once dirname(__FILE__) . '/../../../../TestCase.php';
+
+/**
+ * Test the search operations restricted to groups.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Kolab_Server_Class_Server_Search_Operation_RestrictgroupsTest
+extends Horde_Kolab_Server_TestCase
+{
+ public function setUp()
+ {
+ $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface');
+ }
+
+ public function testMethodSearchrestrictgroupsHasResultRestrictedToGroups()
+ {
+ $result = $this->getMock('Horde_Kolab_Server_Result_Interface');
+ $result->expects($this->once())
+ ->method('asArray')
+ ->will($this->returnValue(array('a' => 'a')));
+ $this->structure->expects($this->once())
+ ->method('find')
+ ->with(
+ $this->isRestrictedToGroups(),
+ array('attributes' => 'guid')
+ )
+ ->will($this->returnValue($result));
+ $search = new Horde_Kolab_Server_Search_Operation_Restrictgroups($this->structure);
+ $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface');
+ $this->assertEquals(array('a'), $search->searchRestrictGroups($criteria));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php
index 2f44cf322..59f72c0fb 100644
--- a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php
@@ -12,9 +12,9 @@
*/
/**
- * Prepare the test setup.
+ * Require our basic test case definition
*/
-require_once dirname(__FILE__) . '/../../../../Autoload.php';
+require_once dirname(__FILE__) . '/../../../../TestCase.php';
/**
* Test the search operations restricted to Kolab users.
@@ -31,7 +31,7 @@ require_once dirname(__FILE__) . '/../../../../Autoload.php';
* @link http://pear.horde.org/index.php?package=Kolab_Server
*/
class Horde_Kolab_Server_Class_Server_Search_Operation_RestrictkolabTest
-extends PHPUnit_Framework_TestCase
+extends Horde_Kolab_Server_TestCase
{
public function setUp()
{
@@ -55,54 +55,4 @@ extends PHPUnit_Framework_TestCase
$criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface');
$this->assertEquals(array('a'), $search->searchRestrictkolab($criteria));
}
-
- public function isRestrictedToKolabUsers()
- {
- return new Constraint_RestrictedToKolabUsers();
- }
-}
-
-class Constraint_RestrictedToKolabUsers extends PHPUnit_Framework_Constraint
-{
- public function evaluate($other)
- {
- if ($other instanceOf Horde_Kolab_Server_Query_Element_Interface) {
- if ($other instanceOf Horde_Kolab_Server_Query_Element_Group) {
- $elements = $other->getElements();
- foreach ($elements as $element) {
- if ($this->evaluate($element)) {
- return true;
- }
- }
- return true;
- } else {
- if ($other->getName() == 'objectClass'
- && $other->getValue() == Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON) {
- return true;
- } else {
- return false;
- }
- }
- } else {
- return false;
- }
- }
-
- public function fail($other, $description, $not = FALSE)
- {
- throw new PHPUnit_Framework_ExpectationFailedException(
- sprintf(
- '%sFailed asserting that %s contains a query element that restricts the search to Kolab users',
-
- !empty($description) ? $description . "\n" : '',
- PHPUnit_Util_Type::toString($other, TRUE)
- ),
- NULL
- );
- }
-
- public function toString()
- {
- return 'contains a query element that restricts the search to Kolab users';
- }
-}
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictgroups.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictgroups.php
new file mode 100644
index 000000000..19278a371
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictgroups.php
@@ -0,0 +1,46 @@
+getElements();
+ foreach ($elements as $element) {
+ if ($this->evaluate($element)) {
+ return true;
+ }
+ }
+ return true;
+ } else {
+ if ($other->getName() == 'objectClass'
+ && $other->getValue() == Horde_Kolab_Server_Object_Groupofnames::OBJECTCLASS_GROUPOFNAMES) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function fail($other, $description, $not = FALSE)
+ {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ sprintf(
+ '%sFailed asserting that %s contains a query element that restricts the search to groups',
+
+ !empty($description) ? $description . "\n" : '',
+ PHPUnit_Util_Type::toString($other, TRUE)
+ ),
+ NULL
+ );
+ }
+
+ public function toString()
+ {
+ return 'contains a query element that restricts the search to groups';
+ }
+}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictkolabusers.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictkolabusers.php
new file mode 100644
index 000000000..03f184d5c
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictkolabusers.php
@@ -0,0 +1,46 @@
+getElements();
+ foreach ($elements as $element) {
+ if ($this->evaluate($element)) {
+ return true;
+ }
+ }
+ return true;
+ } else {
+ if ($other->getName() == 'objectClass'
+ && $other->getValue() == Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function fail($other, $description, $not = FALSE)
+ {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ sprintf(
+ '%sFailed asserting that %s contains a query element that restricts the search to Kolab users',
+
+ !empty($description) ? $description . "\n" : '',
+ PHPUnit_Util_Type::toString($other, TRUE)
+ ),
+ NULL
+ );
+ }
+
+ public function toString()
+ {
+ return 'contains a query element that restricts the search to Kolab users';
+ }
+}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchuid.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchuid.php
new file mode 100644
index 000000000..9fdf80ccf
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchuid.php
@@ -0,0 +1,45 @@
+getElements();
+ foreach ($elements as $element) {
+ if ($this->evaluate($element)) {
+ return true;
+ }
+ }
+ return true;
+ } else {
+ if ($other->getName() == 'uid') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function fail($other, $description, $not = FALSE)
+ {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ sprintf(
+ '%sFailed asserting that %s contains a query element that is searching by uid',
+
+ !empty($description) ? $description . "\n" : '',
+ PHPUnit_Util_Type::toString($other, TRUE)
+ ),
+ NULL
+ );
+ }
+
+ public function toString()
+ {
+ return 'contains a query element that is searching by uid';
+ }
+}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php
index 6de7c27e1..f2957a5e8 100644
--- a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php
@@ -16,6 +16,10 @@
*/
require_once dirname(__FILE__) . '/Autoload.php';
+require_once dirname(__FILE__) . '/Constraints/Restrictkolabusers.php';
+require_once dirname(__FILE__) . '/Constraints/Restrictgroups.php';
+require_once dirname(__FILE__) . '/Constraints/Searchuid.php';
+
/**
* Skip LDAP based tests if we don't have ldap or Net_LDAP2.
*
@@ -49,4 +53,19 @@ class Horde_Kolab_Server_TestCase extends PHPUnit_Framework_TestCase
$this->getMock('Horde_Kolab_Server_Schema_Interface')
);
}
+
+ public function isRestrictedToGroups()
+ {
+ return new Horde_Kolab_Server_Constraint_Restrictgroups();
+ }
+
+ public function isRestrictedToKolabUsers()
+ {
+ return new Horde_Kolab_Server_Constraint_Restrictedkolabusers();
+ }
+
+ public function isSearchingByUid()
+ {
+ return new Horde_Kolab_Server_Constraint_Searchuid();
+ }
}
\ No newline at end of file
--
2.11.0