Some more testing of the different search operations.
authorGunnar Wrobel <p@rdus.de>
Wed, 11 Nov 2009 07:12:13 +0000 (08:12 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Wed, 17 Feb 2010 09:14:00 +0000 (10:14 +0100)
framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforaliasTest.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforcnTest.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidformailTest.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchalias.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchcn.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Constraints/Searchmail.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/TestCase.php

index 3465ada..fa256ad 100644 (file)
@@ -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);
     }
index 3657ebc..561a225 100644 (file)
@@ -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);
     }
index 80110e6..7a1fe14 100644 (file)
@@ -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 (file)
index 0000000..bae3c26
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Test the search operations by alias.
+ *
+ * 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 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 <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_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 (file)
index 0000000..cba9011
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Test the search operations by cn.
+ *
+ * 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 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 <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_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 (file)
index 0000000..03427ce
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Test the search operations by mail.
+ *
+ * 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 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 <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_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 (file)
index 0000000..81f8bc8
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+class Horde_Kolab_Server_Constraint_Searchalias 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() == '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 (file)
index 0000000..6079798
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+class Horde_Kolab_Server_Constraint_Searchcn 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() == '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 (file)
index 0000000..329087a
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+class Horde_Kolab_Server_Constraint_Searchmail 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() == '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';
+    }
+}
index 26f7cd2..0843e9e 100644 (file)
@@ -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