Add testing for the search handler.
authorGunnar Wrobel <p@rdus.de>
Thu, 29 Oct 2009 15:52:58 +0000 (16:52 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 29 Oct 2009 15:52:58 +0000 (16:52 +0100)
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php [new file with mode: 0644]

diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php
new file mode 100644 (file)
index 0000000..5a6ca1c
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+/**
+ * Test the search handler.
+ *
+ * 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
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../TestCase.php';
+
+/**
+ * Test the search handler.
+ *
+ * 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_BaseTest
+extends Horde_Kolab_Server_TestCase
+{
+    public function testSetcompositeHasParameterServercomposite()
+    {
+        $composite = $this->getMockedComposite();
+        $composite->structure->expects($this->once())
+            ->method('getSupportedObjects')
+            ->will($this->returnValue(array()));
+        $search = new Horde_Kolab_Server_Search_Base();
+        $search->setComposite($composite);
+    }
+
+    public function testSetcompositeHasPostconditionThatTheAvailableSearchOperationsAreSet()
+    {
+        $composite = $this->getMockedComposite();
+        $composite->structure->expects($this->once())
+            ->method('getSupportedObjects')
+            ->will($this->returnValue(array('Object_Search')));
+        $search = new Horde_Kolab_Server_Search_Base();
+        $search->setComposite($composite);
+        $this->assertEquals(
+            array('call' => array('class' => 'Object_Search')),
+            $search->getSearchOperations()
+        );
+    }
+
+    public function testSetcompositeThrowsExceptionIfADeclaredSearchOperationDoesNotExist()
+    {
+        $composite = $this->getMockedComposite();
+        $composite->structure->expects($this->once())
+            ->method('getSupportedObjects')
+            ->will($this->returnValue(array('Object_Search_Fail')));
+        $search = new Horde_Kolab_Server_Search_Base();
+        try {
+            $search->setComposite($composite);
+        } catch (Horde_Kolab_Server_Exception $e) {
+            $this->assertContains(
+                'Class "Object_Search_Fail" does not support method "call"!',
+                $e->getMessage()
+            );
+        }
+    }
+
+    public function testGetsearchoperationsHasResultTheSearchOperationsSupportedByThisServer()
+    {
+        $this->testSetcompositeHasPostconditionThatTheAvailableSearchOperationsAreSet();
+    }
+
+    public function testCallHasResultTheResultOfTheSearchOperation()
+    {
+        $composite = $this->getMockedComposite();
+        $composite->structure->expects($this->once())
+            ->method('getSupportedObjects')
+            ->will($this->returnValue(array('Object_Search')));
+        $search = new Horde_Kolab_Server_Search_Base();
+        $search->setComposite($composite);
+        $this->assertEquals(1, $search->call());
+    }
+
+    public function testCallHasPostConditionThatTheSearchWasCalledWithTheServerRepresentation()
+    {
+        $composite = $this->getMockedComposite();
+        $composite->structure->expects($this->once())
+            ->method('getSupportedObjects')
+            ->will($this->returnValue(array('Object_Search')));
+        $search = new Horde_Kolab_Server_Search_Base();
+        $search->setComposite($composite);
+        $search->call();
+        $call = Object_Search::$last_call;
+        $this->assertType('Horde_Kolab_Server_Composite', $call[0]);
+    }
+
+    public function testCallThrowsExceptionIfTheSearchOperationIsNotSupported()
+    {
+        $composite = $this->getMockedComposite();
+        $composite->structure->expects($this->once())
+            ->method('getSupportedObjects')
+            ->will($this->returnValue(array('Object_Search')));
+        $search = new Horde_Kolab_Server_Search_Base();
+        $search->setComposite($composite);
+        try {
+            $search->search();
+            $this->fail('No exception!');
+        } catch (Horde_Kolab_Server_Exception $e) {
+            $this->assertContains(
+                'does not support method "search"',
+                $e->getMessage()
+            );
+        }
+    }
+
+    public function tearDown()
+    {
+        Object_Search::reset();
+    }
+}
+
+class Object_Search
+{
+    static public $calls = 0;
+
+    static public $last_call;
+
+    static public function getSearchOperations()
+    {
+        return array('call');
+    }
+
+    static public function call()
+    {
+        self::$last_call = func_get_args();
+        return ++self::$calls;
+    }
+
+    static public function reset()
+    {
+        self::$calls = 0;
+    }
+}
+
+class Object_Search_Fail
+{
+    static public function getSearchOperations()
+    {
+        return array('call');
+    }
+}