wrote this file. * As long as you retain this notice you can do whatever you want with * this stuff. If we meet some day, and you think this stuff is worth it, * you can buy me a beer in return. * * @author Sven Strittmatter * @copyright Copyright (c) 2010, Sven Strittmatter. * @version 0.2.0 * @license http://www.weltraumschaf.de/the-beer-ware-license.txt */ /** * Test helper */ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'TestHelper.php'; require_once 'Api/Controller.php'; $_GET; $_POST; class Api_ControllerTest extends PHPUnit_Extensions_OutputTestCase { protected function setUp() { $_GET = array(); $_POST = array(); } protected function getDefaultController() { $config = $this->getMock('Api_Kwick_Config', array(), array('config' => array())); $request = $this->getMock('Api_Kwick_Request', array(), array('config' => $config)); return new Api_Controller($request); } public function testGetRequestParameter() { $_GET['foo'] = 'bar'; $_POST['baz'] = 3; $controller = $this->getDefaultController(); $this->assertEquals('bar', $controller->getRequestParameter('foo')); $this->assertEquals(3, $controller->getRequestParameter('baz')); $this->assertEquals('default', $controller->getRequestParameter('test', 'default')); $this->assertNull($controller->getRequestParameter('test')); } public function testGetMethod() { $controller = $this->getDefaultController(); $this->assertEquals(Api_Kwick_Request::DEFAULT_METHOD, $controller->getMethod()); $_GET['method'] = 'aMethod'; $this->assertEquals('aMethod', $controller->getMethod()); unset($_GET['method']); $_POST['method'] = 'bMethod'; $this->assertEquals('bMethod', $controller->getMethod()); unset($_POST['method']); } public function testGetService() { $controller = $this->getDefaultController(); $this->assertEquals(Api_Kwick_Request::DEFAULT_SERVICE, $controller->getService()); $_GET['service'] = 'aService'; $this->assertEquals('aService', $controller->getService()); unset($_GET['service']); $_POST['service'] = 'bService'; $this->assertEquals('bService', $controller->getService()); unset($_POST['service']); } public function testDispatch() { $_GET['service'] = 'aService'; $_GET['method'] = 'aMethod'; $config = $this->getMock('Api_Kwick_Config', array(), array('config' => array())); $request = $this->getMock('Api_Kwick_Request', array('send', 'setMethod', 'setService'), array('config' => $config)); $request->expects($this->once()) ->method('setMethod') ->with($this->equalTo($_GET['method'])); $request->expects($this->once()) ->method('setService') ->with($this->equalTo($_GET['service'])); $request->expects($this->once()) ->method('send') ->will($this->returnValue('result')); $this->expectOutputString('result'); $controller = new Api_Controller($request); $controller->dispatch(); } public function testThrowExceptionOnDispatching() { $config = $this->getMock('Api_Kwick_Config', array(), array('config' => array())); $request = $this->getMock('Api_Kwick_Request', array('send', 'setMethod', 'setService'), array('config' => $config)); $request->expects($this->once()) ->method('setMethod'); $request->expects($this->once()) ->method('setService'); $exception = new Exception('A testexception', 5); $request->expects($this->once()) ->method('send') ->will($this->throwException($exception)); $this->expectOutputString(json_encode(array('exception' => $exception->__toString()))); $controller = new Api_Controller($request); $controller->dispatch(); } public function testPrepareParametersOnRequest() { $this->markTestIncomplete(); } public function testExternalSecret() { $this->markTestIncomplete(); } }