<?php
require_once APPLICATION_PATH . '/controllers/ExampleController.php';
class ExampleControllerTest extends ExampleController
{
public function __construct($url = null)
{
$front = Zend_Controller_Front::getInstance();
$front->resetInstance();
$front->setControllerDirectory(APPLICATION_PATH . '/controllers');
$front->setRequest(new Zend_Controller_Request_Http($url));
$front->setResponse(new Zend_Controller_Response_Http());
parent::__construct($front->getRequest(), $front->getResponse());
}
}
class ExampleControllerTestCase extends PHPUnit_Framework_TestCase
{
public function testDefaultAction()
{
$controller = new ExampleControllerTest();
$isDispatched = $controller->indexAction();
$this->assertTrue($isDispatched);
}
public function testFirstAction()
{
$url = 'http://localhost/example/first';
$controller = new ExampleControllerTest($url);
$controller->firstAction();
$errorMsg = $controller->getRequest()->getParam('error_message', null);
$this->assertEquals(null, $errorMsg);
}
public function testGetParameterName()
{
$url = 'http://localhost/example/first/fed';
$controller = new ExampleControllerTest($url);
$name = $controller->getRequest()->getParam('name', null);
$this->assertEquals('fed', $name);
}
public function testGetNameMethod()
{
$url = 'http://localhost/example/first/fed';
$controller = new ExampleControllerTest($url);
$name = $controller->getName();
$this->assertEquals('fed', $name);
}
}