Created
June 10, 2013 08:33
-
-
Save whisher/5747285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<phpunit bootstrap="./Bootstrap.php" | |
colors="true" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
verbose="true" | |
stopOnFailure="false" | |
processIsolation="false" | |
backupGlobals="false" | |
syntaxCheck="true" | |
> | |
<testsuite name="Sharint Test Suite"> | |
<directory>./</directory> | |
</testsuite> | |
<filter> | |
<whitelist> | |
<directory suffix=".php">../library/</directory> | |
<directory suffix=".php">../application/</directory> | |
<exclude> | |
<directory suffix=".phtml">../application/</directory> | |
</exclude> | |
</whitelist> | |
</filter> | |
</phpunit> | |
error_reporting( E_ALL | E_STRICT ); | |
ini_set('display_startup_errors', 1); | |
ini_set('display_errors', 1); | |
date_default_timezone_set('Europe/London'); | |
defined('ROOT_DIR') | |
|| define('ROOT_DIR', dirname(__FILE__)); | |
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); | |
define('APPLICATION_ENV', 'testing'); | |
define('FB_DATA_NS','fb_data_ns'); | |
define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library')); | |
define('TESTS_PATH', realpath(dirname(__FILE__))); | |
$includePaths = array(LIBRARY_PATH,APPLICATION_PATH . '/models', get_include_path()); | |
set_include_path(implode(PATH_SEPARATOR, $includePaths)); | |
require_once "Zend/Loader/Autoloader.php"; | |
$autoloader = Zend_Loader_Autoloader::getInstance(); | |
$autoloader->registerNamespace('App'); | |
Zend_Session::$_unitTestEnabled = true; | |
Zend_Session::start(); | |
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase | |
{ | |
public $application; | |
public function setUp() | |
{ | |
$this->application = new Zend_Application( | |
APPLICATION_ENV, | |
APPLICATION_PATH . '/configs/application.ini' | |
); | |
$this->bootstrap = array($this, 'appBootstrap'); | |
parent::setUp(); | |
} | |
public function tearDown() | |
{ | |
Zend_Controller_Front::getInstance()->resetInstance(); | |
$this->resetRequest(); | |
$this->resetResponse(); | |
$this->request->setPost(array()); | |
$this->request->setQuery(array()); | |
} | |
public function appBootstrap() | |
{ | |
$this->application->bootstrap(); | |
/* | |
$controller = $this->getFrontController(); | |
$controller->registerPlugin( | |
new Initialize('development') | |
); | |
*/ | |
} | |
public function dispatch($url = null) | |
{ | |
// redirector should not exit | |
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); | |
$redirector->setExit(false); | |
// json helper should not exit | |
$json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); | |
$json->suppressExit = true; | |
$request = $this->getRequest(); | |
if (null !== $url) { | |
$request->setRequestUri($url); | |
} | |
$request->setPathInfo(null); | |
$this->getFrontController() | |
->setRequest($request) | |
->setResponse($this->getResponse()) | |
->throwExceptions(true) | |
->returnResponse(false); | |
$this->getFrontController()->dispatch(); | |
} | |
} | |
require_once TESTS_PATH . '/application/ControllerTestCase.php'; | |
require_once APPLICATION_PATH . '/modules/default/controllers/UserController.php'; | |
class UserControllerTest extends ControllerTestCase | |
{ | |
public function testShouldInvokeUserSignUpAction() | |
{ | |
$this->request->setMethod('POST'); | |
$this->dispatch('/user/signup'); | |
$this->assertController('user'); | |
$this->assertAction('xhrsignup'); | |
$this->assertRoute('usersignup'); | |
} | |
public function testUserSignUpIsXhrAction() | |
{ | |
$this->request->setMethod('POST'); | |
//$this->request->setHeader('X-Requested-With', 'XmlHttpRequest'); | |
$this->dispatch('/user/signup'); | |
$headers = $this->response->getHeaders(); | |
//$this->assertSame('application/json; charset=UTF-8',$headers[0]['value']); | |
var_dump($this->response->getBody()); | |
} | |
public function testUserSignUpIsAction() | |
{ | |
$this->request->setMethod('POST'); | |
$this->request->setHeader('X-Requested-With', 'XmlHttpRequest'); | |
$this->dispatch('/user/signup'); | |
$headers = $this->response->getHeaders(); | |
$this->assertSame('application/json; charset=UTF-8',$headers[0]['value']); | |
var_dump($this->response->getBody()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment