public function testDoDispatch() { $forward = new WindForward(); $forward->setIsReAction(true); $forward->setAction('/long/test'); ob_start(); $this->front->createApplication()->doDispatch($forward); $this->assertEquals(ob_get_clean(), 'LongController-test'); }
/** * Tests WindDispatcher->dispatch() */ public function testDispatch() { $_SERVER['SCRIPT_FILENAME'] = "index.php"; $_SERVER['SCRIPT_NAME'] = 'index.php'; $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_FILENAME'] . '?c=long&a=noPrint'; $front = Wind::application('long', array('web-apps' => array('long' => array('modules' => array('default' => array('controller-path' => 'data', 'controller-suffix' => 'Controller', 'error-handler' => 'TEST:data.ErrorControllerTest'))))))->run(); $forward = new WindForward(); $forward->setIsReAction(true); $forward->setAction('/long/test'); ob_start(); Wind::getApp()->doDispatch($forward); $this->assertEquals(ob_get_clean(), 'LongController-test'); }
/** * 重定向请求到新的action操作 * * 该种重定向类型,是中断当前的请求执行过程,开启另外的action操作处理.是在一次请求内部进行重定向, * 所以之前的一些处理的结果变量,在重定向后是会继续存在,并可通过forward变量进行访问的.也就是不仅仅是过程的重定向, * 也是状态的重定向. * @param WindForward $forward * @param WindRouter $router * @param boolean $display * @return void */ protected function dispatchWithAction($forward, $router, $display) { if (!($action = $forward->getAction())) { throw new WindException('[web.WindDispatcher.dispatchWithAction] forward fail.', WindException::ERROR_PARAMETER_TYPE_ERROR); } $this->display = $display; list($_a, $_c, $_m) = WindUrlHelper::resolveAction($action); if ($_var = $forward->getArgs()) { $this->getResponse()->setData($_var, 'F'); } $_a && $router->setAction($_a); $_c && $router->setController($_c); $_m && $router->setModule($_m); Wind::getApp()->run(); }
/** * Tests WindForwardException->__construct() */ public function test__construct() { $f1 = new WindForward(); $f1->setIsReAction(true); $f2 = new WindForward(); $f2->setIsReAction(false); try { throw new WindForwardException($f1); } catch (Exception $e) { $this->assertEquals("WindForwardException", get_class($e)); $this->assertEquals($f1, $e->getForward()); $e->setForward($f2); $this->assertEquals($f2, $e->getForward()); $this->assertNotEquals($f1, $e->getForward()); } }
/** * Tests WindForward->setWindView() */ public function testSetWindView() { $windView = new WindView(); $windView->setConfig(array('template-dir' => 'template/long', 'compile-dir' => 'compile/data')); $this->WindForward->setWindView($windView); $this->assertEquals($this->WindForward->getWindView(), $windView); }
/** * 重定向请求到新的action操作 * * 该种重定向类型,是中断当前的请求执行过程,开启另外的action操作处理.是在一次请求内部进行重定向, * 所以之前的一些处理的结果变量,在重定向后是会继续存在,并可通过forward变量进行访问的.也就是不仅仅是过程的重定向, * 也是状态的重定向. * @param WindForward $forward * @param WindRouter $router * @param boolean $display * @return void */ protected function dispatchWithAction($forward, $router, $display) { if (!($action = $forward->getAction())) { throw new WindException('[web.WindDispatcher.dispatchWithAction] forward fail.', WindException::ERROR_PARAMETER_TYPE_ERROR); } $this->display = $display; list($_a, $_c, $_m, $arg) = WindUrlHelper::resolveAction($action); foreach ($arg as $key => $value) { $_GET[$key] = $value; } foreach ($forward->getArgs() as $key => $value) { $_POST[$key] = $value; } $_a && $router->setAction($_a); $_c && $router->setController($_c); $_m && $router->setModule($_m); Wind::getApp()->run(); }
public function testResolveActionFilter() { require_once 'data/Listener.php'; Wind::application()->createApplication(); $errorMessage = new WindErrorMessage("shi"); $this->testController->setErrorMessage($errorMessage); $forward = new WindForward(); $forward->setAction("long"); $this->testController->setForward($forward); $_GET['name'] = 'shilong'; $this->testController->setGlobal('shilong', 'name'); $forward->setVars('name', 'xxxxx'); $_GET['wuq'] = 'wuq'; $this->testController->resolveActionFilter($this->dataForResolveActionFilter()); $this->assertEquals("post_post_post_pre_pre_pre_shi", $errorMessage->getError(0)); $this->assertEquals("post_post_post_pre_pre_pre_long", $forward->getAction()); }
/** * 设置模板数据 * * 此方法设置的参数,作用域仅仅只是在当前模板中可用,调用的方法为{$varName} * * @param string|array|object $data 需要设置输出的参数 * @param string $key 参数的名字,默认为空,如果key为空,并且$data是数组或是对象的时候,则$data中的元素将会作为单独的参数保存到输出数据中. */ protected function setOutput($data, $key = '') { $this->forward->setVars($data, $key); }
public function postHandle() { $this->forward->setAction('post_' . $this->forward->getAction()); $this->errorMessage->addError('post_' . $this->errorMessage->getError(0), 0); }