From 539a0e62767e2e51e1f3be84b51bf0ee5eb4ae11 Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Wed, 11 Nov 2009 08:12:13 +0100
Subject: [PATCH] Some more testing of the different search operations.
---
.../Kolab/Server/Search/Operation/Guidforalias.php | 2 +-
.../Kolab/Server/Search/Operation/Guidforcn.php | 2 +-
.../Kolab/Server/Search/Operation/Guidformail.php | 2 +-
.../Server/Search/Operation/GuidforaliasTest.php | 61 ++++++++++++++++++++++
.../Server/Search/Operation/GuidforcnTest.php | 58 ++++++++++++++++++++
.../Server/Search/Operation/GuidformailTest.php | 61 ++++++++++++++++++++++
.../Horde/Kolab/Server/Constraints/Searchalias.php | 45 ++++++++++++++++
.../Horde/Kolab/Server/Constraints/Searchcn.php | 45 ++++++++++++++++
.../Horde/Kolab/Server/Constraints/Searchmail.php | 45 ++++++++++++++++
.../test/Horde/Kolab/Server/TestCase.php | 18 +++++++
10 files changed, 336 insertions(+), 3 deletions(-)
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforaliasTest.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforcnTest.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidformailTest.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchalias.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchcn.php
create mode 100644 framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchmail.php
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php
index 3465adab3..fa256adfc 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php
@@ -40,7 +40,7 @@ extends Horde_Kolab_Server_Search_Operation_Restrictkolab
public function searchGuidForAlias($alias)
{
$criteria = new Horde_Kolab_Server_Query_Element_Equals(
- 'Alias', $alias
+ 'alias', $alias
);
return parent::searchRestrictKolab($criteria);
}
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php
index 3657ebc74..561a225d5 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php
@@ -40,7 +40,7 @@ extends Horde_Kolab_Server_Search_Operation_Guid
public function searchGuidForCn($cn)
{
$criteria = new Horde_Kolab_Server_Query_Element_Equals(
- 'Cn', $cn
+ 'cn', $cn
);
return parent::searchGuid($criteria);
}
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php
index 80110e628..7a1fe14d9 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php
@@ -40,7 +40,7 @@ extends Horde_Kolab_Server_Search_Operation_Restrictkolab
public function searchGuidForMail($mail)
{
$criteria = new Horde_Kolab_Server_Query_Element_Equals(
- 'Mail', $mail
+ 'mail', $mail
);
return parent::searchRestrictKolab($criteria);
}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforaliasTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforaliasTest.php
new file mode 100644
index 000000000..bae3c265d
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforaliasTest.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 alias.
+ *
+ * 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_GuidforaliasTest
+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->isSearchingByAlias()
+ ),
+ array('attributes' => 'guid')
+ )
+ ->will($this->returnValue($result));
+ $search = new Horde_Kolab_Server_Search_Operation_Guidforalias($this->structure);
+ $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface');
+ $this->assertEquals(array('a'), $search->searchGuidForAlias('test'));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforcnTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforcnTest.php
new file mode 100644
index 000000000..cba901175
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforcnTest.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 by cn.
+ *
+ * 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_GuidforcnTest
+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->isSearchingByCn(),
+ array('attributes' => 'guid')
+ )
+ ->will($this->returnValue($result));
+ $search = new Horde_Kolab_Server_Search_Operation_Guidforcn($this->structure);
+ $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface');
+ $this->assertEquals(array('a'), $search->searchGuidForCn('test'));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidformailTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidformailTest.php
new file mode 100644
index 000000000..03427ce42
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidformailTest.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 mail.
+ *
+ * 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_GuidformailTest
+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->isSearchingByMail()
+ ),
+ array('attributes' => 'guid')
+ )
+ ->will($this->returnValue($result));
+ $search = new Horde_Kolab_Server_Search_Operation_Guidformail($this->structure);
+ $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface');
+ $this->assertEquals(array('a'), $search->searchGuidForMail('test'));
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchalias.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchalias.php
new file mode 100644
index 000000000..81f8bc80e
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchalias.php
@@ -0,0 +1,45 @@
+getElements();
+ foreach ($elements as $element) {
+ if ($this->evaluate($element)) {
+ return true;
+ }
+ }
+ return true;
+ } else {
+ if ($other->getName() == 'alias') {
+ 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 alias',
+
+ !empty($description) ? $description . "\n" : '',
+ PHPUnit_Util_Type::toString($other, TRUE)
+ ),
+ NULL
+ );
+ }
+
+ public function toString()
+ {
+ return 'contains a query element that is searching by alias';
+ }
+}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchcn.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchcn.php
new file mode 100644
index 000000000..6079798a5
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchcn.php
@@ -0,0 +1,45 @@
+getElements();
+ foreach ($elements as $element) {
+ if ($this->evaluate($element)) {
+ return true;
+ }
+ }
+ return true;
+ } else {
+ if ($other->getName() == 'cn') {
+ 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 cn',
+
+ !empty($description) ? $description . "\n" : '',
+ PHPUnit_Util_Type::toString($other, TRUE)
+ ),
+ NULL
+ );
+ }
+
+ public function toString()
+ {
+ return 'contains a query element that is searching by cn';
+ }
+}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchmail.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchmail.php
new file mode 100644
index 000000000..329087a4b
--- /dev/null
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchmail.php
@@ -0,0 +1,45 @@
+getElements();
+ foreach ($elements as $element) {
+ if ($this->evaluate($element)) {
+ return true;
+ }
+ }
+ return true;
+ } else {
+ if ($other->getName() == 'mail') {
+ 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 mail',
+
+ !empty($description) ? $description . "\n" : '',
+ PHPUnit_Util_Type::toString($other, TRUE)
+ ),
+ NULL
+ );
+ }
+
+ public function toString()
+ {
+ return 'contains a query element that is searching by mail';
+ }
+}
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php
index 26f7cd27a..0843e9e0d 100644
--- a/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php
+++ b/framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php
@@ -19,6 +19,9 @@ 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';
+require_once dirname(__FILE__) . '/Constraints/Searchmail.php';
+require_once dirname(__FILE__) . '/Constraints/Searchcn.php';
+require_once dirname(__FILE__) . '/Constraints/Searchalias.php';
/**
* Skip LDAP based tests if we don't have ldap or Net_LDAP2.
@@ -68,4 +71,19 @@ class Horde_Kolab_Server_TestCase extends PHPUnit_Framework_TestCase
{
return new Horde_Kolab_Server_Constraint_Searchuid();
}
+
+ public function isSearchingByMail()
+ {
+ return new Horde_Kolab_Server_Constraint_Searchmail();
+ }
+
+ public function isSearchingByCn()
+ {
+ return new Horde_Kolab_Server_Constraint_Searchcn();
+ }
+
+ public function isSearchingByAlias()
+ {
+ return new Horde_Kolab_Server_Constraint_Searchcn();
+ }
}
\ No newline at end of file
--
2.11.0