Additional testing for the search operations.
authorGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 23:08:03 +0000 (00:08 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 23:08:03 +0000 (00:08 +0100)
framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Restrictgroups.php
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforuidTest.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php
framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictgroups.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Restrictkolabusers.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchuid.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php

index 0acbc67..27247ea 100644 (file)
@@ -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);
     }
index bdd083a..494e838 100644 (file)
@@ -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 (file)
index 0000000..b7bd5e8
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Test the search operations by uid.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..ff8ad7c
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Test the search operations restricted to groups.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
index 2f44cf3..59f72c0 100644 (file)
@@ -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 (file)
index 0000000..19278a3
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+class Horde_Kolab_Server_Constraint_Restrictgroups 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_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 (file)
index 0000000..03f184d
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+class Horde_Kolab_Server_Constraint_Restrictedkolabusers 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';
+    }
+}
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 (file)
index 0000000..9fdf80c
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+class Horde_Kolab_Server_Constraint_Searchuid 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() == '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';
+    }
+}
index 6de7c27..f2957a5 100644 (file)
  */
 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