From: Gunnar Wrobel Date: Thu, 29 Oct 2009 15:52:58 +0000 (+0100) Subject: Add testing for the search handler. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5210f3ffbee8f023ab87572e73095ef9bd85d7e4;p=horde.git Add testing for the search handler. --- 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 index 000000000..5a6ca1c63 --- /dev/null +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php @@ -0,0 +1,160 @@ + + * @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 + * @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'); + } +}