0
- * This file is subject to the GNU Lesser General Public License Version 3
0
- * that is bundled with this package in the file LICENSE.
0
- * It is also available through the world-wide-web at this URL:
0
- * http://www.gnu.org/licenses/lgpl-3.0.txt
0
- * If you did not receive a copy of the license and are unable to
0
- * obtain it through the world-wide-web, please send an email
0
- * to license@phpspec.org so we can send you a copy immediately.
0
- * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
-require_once 'Zend/Controller/Front.php';
0
-require_once 'Zend/Controller/Request/Http.php';
0
- * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
-class PHPSpec_Context_Zend extends PHPSpec_Context
0
- protected static $_moduleDirectories = array();
0
- protected $_controller = '';
0
- * Zend Framework; instance of Front Controller
0
- * @var Zend_Controller_Front
0
- protected $_frontController = null;
0
- * Zend Framework; instance of HTTP Request
0
- * @var Zend_Controller_Request_Http
0
- protected $_request = null;
0
- * Zend Framework; instance of HTTP Response
0
- * @var Zend_Controller_Response_Http
0
- protected $_response = null;
0
- public function __construct()
0
- parent::__construct();
0
- $this->_setController();
0
- $this->_frontController = Zend_Controller_Front::getInstance();
0
- public static function addModuleDirectory($path)
0
- self::$_moduleDirectories[] = $path;
0
- public static function getModuleDirectories()
0
- return self::$_moduleDirectories;
0
- public function beforeEach()
0
- $this->_request = new Zend_Controller_Request_Http;
0
- $this->_clearFrontController();
0
- public function get($actionName, array $getArray = null, array $paramArray = null)
0
- $this->request()->setControllerName($this->getController());
0
- $this->request()->setActionName($actionName);
0
+ * This file is subject to the GNU Lesser General Public License Version 3
0
+ * that is bundled with this package in the file LICENSE.
0
+ * It is also available through the world-wide-web at this URL:
0
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
0
+ * If you did not receive a copy of the license and are unable to
0
+ * obtain it through the world-wide-web, please send an email
0
+ * to license@phpspec.org so we can send you a copy immediately.
0
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
+require_once 'Zend/Controller/Front.php';
0
+require_once 'Zend/Controller/Request/Http.php';
0
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
+class PHPSpec_Context_Zend extends PHPSpec_Context
0
+ const BASE_URL = 'http://www.example.com';
0
+ protected static $_moduleDirectories = array();
0
+ protected static $_controllerDirectories = array();
0
+ protected static $_frontControllerSetupCallback = null;
0
+ * Name of the Controller being specified; captured usually
0
+ * from the Context classname.
0
+ protected $_controller = '';
0
+ * Zend Framework; instance of Front Controller
0
+ * @var Zend_Controller_Front
0
+ protected $_frontController = null;
0
+ * Zend Framework; instance of HTTP Request
0
+ * @var Zend_Controller_Request_Http
0
+ protected $_request = null;
0
+ * Zend Framework; instance of HTTP Response
0
+ * @var Zend_Controller_Response_Http
0
+ protected $_response = null;
0
+ public function __construct()
0
+ parent::__construct();
0
+ $this->_setController();
0
+ $this->_frontController = Zend_Controller_Front::getInstance();
0
+ public static function setFrontControllerSetupCallback($callback)
0
+ self::$_frontControllerSetupCallback = $callback;
0
+ public static function clearFrontControllerSetupCallback()
0
+ self::$_frontControllerSetupCallback = null;
0
+ public static function addModuleDirectory($path)
0
+ self::$_moduleDirectories[] = $path;
0
+ public static function getModuleDirectories()
0
+ return self::$_moduleDirectories;
0
+ public static function clearModuleDirectories()
0
+ self::$_moduleDirectories = array();
0
+ public static function addControllerDirectory($path, $module = null)
0
+ if (!isset($module)) {
0
+ self::$_controllerDirectories[$module] = $path;
0
+ public static function getControllerDirectories()
0
+ return self::$_controllerDirectories;
0
+ public static function clearControllerDirectories()
0
+ self::$_controllerDirectories = array();
0
+ public function beforeEach()
0
+ $this->_clearFrontController();
0
+ public function get($actionName, array $getArray = null, array $paramArray = null)
0
if (!empty($getArray)) {
0
- $this->request()->setParams($getArray); // override later with subclass!
0
- if (!empty($paramArray)) {
0
- $this->request()->setParams($paramArray);
0
- $this->_response = $this->_frontController->dispatch($this->request());
0
- return $this->response();
0
- * Returns current Request_Http object
0
- * @return Zend_Controller_Request_Http
0
- public function request()
0
- return $this->_request;
0
- public function response()
0
+ $this->_response = $this->_makeRequest($actionName, $paramArray);
0
+ return $this->response();
0
+ public function post($actionName, array $postArray = null, array $paramArray = null)
0
+ if (!empty($postArray)) {
0
+ $this->_response = $this->_makeRequest($actionName, $paramArray);
0
+ return $this->response();
0
+ * Returns current Request_Http object
0
+ * @return Zend_Controller_Request_Http
0
+ public function request()
0
+ return $this->_request;
0
+ public function response()
0
if (!isset($this->_response)) {
0
- throw new PHPSpec_Exception('No response has been retrieved yet;
0
+ throw new PHPSpec_Exception('No response has been retrieved yet;
0
make a get or post request first');
0
- return $this->_response;
0
- public function setController($controllerName)
0
- $this->_controller = $controllerName;
0
- public function getController()
0
- return $this->_controller;
0
- public function getFrontController()
0
- return $this->_frontController;
0
- protected function _clearFrontController() {
0
- $this->_frontController->resetInstance();
0
- $this->_frontController->returnResponse(true);
0
- foreach (self::getModuleDirectories() as $path) {
0
- $this->_frontController->addModuleDirectory($path);
0
- protected function _setController()
0
- $this->_controller = substr(get_class($this), 8, strlen(substr(get_class($this), 8))-10);
0
+ return $this->_response;
0
+ public function setController($controllerName)
0
+ $this->_controller = $controllerName;
0
+ public function getController()
0
+ return $this->_controller;
0
+ public function getFrontController()
0
+ return $this->_frontController;
0
+ protected function _makeRequest($actionName, array $paramArray = null)
0
+ if (preg_match("%/%", $actionName)) {
0
+ . (substr($actionName, 0, 1) == '/' ? $actionName : '/' . $actionName);
0
+ $uri = self::BASE_URL . '/' . $this->getController()
0
+ . (!empty($actionName) ? '/' . $actionName : '');
0
+ $this->_request = new Zend_Controller_Request_Http($uri);
0
+ if (!empty($paramArray)) {
0
+ $this->request()->setParams($paramArray);
0
+ $response = $this->_frontController->dispatch(
0
+ new PHPSpec_Context_Zend_Response
0
+ $response->setContext($this);
0
+ protected function _clearFrontController() {
0
+ $this->_frontController->resetInstance();
0
+ if (count(self::$_frontControllerSetupCallback) > 0) {
0
+ self::$_frontControllerSetupCallback[0],
0
+ self::$_frontControllerSetupCallback[1]
0
+ $this->_frontController->returnResponse(true);
0
+ $this->_frontController->throwExceptions(true);
0
+ foreach (self::getControllerDirectories() as $module=>$path) {
0
+ if ($module == 'NULL') {
0
+ $this->_frontController->addControllerDirectory($path, $module);
0
+ foreach (self::getModuleDirectories() as $path) {
0
+ $this->_frontController->addModuleDirectory($path);
0
+ protected function _setController()
0
+ $controllerClassName = substr(get_class($this), 8);
0
+ $this->_controller = substr($controllerClassName, 0, strlen($controllerClassName)-10);
0
\ No newline at end of file
Comments
No one has commented yet.