Exemplo n.º 1
0
 public function testUnspecified()
 {
     $this->mapping->setParameter('missing');
     $this->action->execute($this->mapping, null, $this->request, $this->response);
     $this->assertNotEmpty($this->response->getContent());
     $this->assertEquals(400, $this->response->getStatusCode());
 }
Exemplo n.º 2
0
 /**
  * Handle the exception.
  * Return the <code>ActionForward</code> instance (if any) returned by
  * the called <code>ExceptionHandler</code>.
  *
  * @param \Exception ex The exception to handle
  * @param \Phruts\Config\ExceptionConfig ae The ExceptionConfig corresponding to the exception
  * @param \Phruts\Action\ActionMapping mapping The ActionMapping we are processing
  * @param \Phruts\Action\AbstractActionForm formInstance The \Phruts\Action\AbstractActionForm we are processing
  * @param \Symfony\Component\HttpFoundation\Request request The actionKernel request we are processing
  * @param \Symfony\Component\HttpFoundation\Response response The actionKernel response we are creating
  * @return \Phruts\Config\ForwardConfig
  * @exception ActionKernelException if a actionKernel exception occurs
  *
  * @since Struts 1.1
  */
 public function execute(\Exception $ex, \Phruts\Config\ExceptionConfig $ae, \Phruts\Action\ActionMapping $mapping, \Phruts\Action\AbstractActionForm $formInstance = null, \Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response)
 {
     $forward = null;
     //ActionForward
     $error = null;
     //\Phruts\Action\ActionError
     $property = null;
     //String
     // Build the forward from the exception mapping if it exists
     // or from the form input
     if ($ae->getPath() != null) {
         $forward = new \Phruts\Config\ForwardConfig();
         $forward->setPath($ae->getPath());
     } else {
         $forward = $mapping->getInputForward();
     }
     // Figure out the error
     if ($ex instanceof \Phruts\Util\ModuleException) {
         $error = $ex->getActionMessage();
         $property = $ex->getProperty();
     } else {
         $error = new \Phruts\Action\ActionError($ae->getKey(), $ex->getMessage());
         $property = $error->getKey();
     }
     // Store the exception
     $request->attributes->set(\Phruts\Util\Globals::EXCEPTION_KEY, $ex);
     $this->storeException($request, $property, $error, $forward, $ae->getScope());
     return $forward;
 }
Exemplo n.º 3
0
 public function testEmptyParameter()
 {
     $actionConfig = new ActionMapping();
     $actionConfig->setPath('/test');
     // NO PARAM
     $moduleConfig = new ModuleConfig('');
     $moduleConfig->addActionConfig($actionConfig);
     $actionConfig->setModuleConfig($moduleConfig);
     $action = new ForwardAction();
     $request = new Request();
     $response = new Response();
     $this->setExpectedException('\\Phruts\\Exception');
     $action->execute($actionConfig, null, $request, $response);
 }
Exemplo n.º 4
0
 public function testGetInputForward()
 {
     // Input forward
     $this->actionMapping->setInput('aPath');
     $forward = $this->actionMapping->getInputForward();
     $this->assertNotEmpty($forward);
     $this->assertEquals('aPath', $forward->getPath());
     // Controller based input forward
     $controllerConfig = new \Phruts\Config\ControllerConfig();
     $controllerConfig->setInputForward(true);
     $this->actionMapping->setInput('path1');
     $this->moduleConfig->setControllerConfig($controllerConfig);
     $forward = $this->actionMapping->getInputForward();
     $this->assertNotEmpty($forward);
     $this->assertEquals('path1', $forward->getName());
 }
Exemplo n.º 5
0
 public function testExecute()
 {
     // Add an exception config
     $exceptionConfig = new ExceptionConfig();
     $exceptionConfig->setPath('/exception.php');
     $exceptionConfig->setKey('example.exception');
     $exceptionConfig->setType('\\Exception');
     // Action Mapping
     $actionMapping = new ActionMapping();
     $actionMapping->setType('\\Phruts\\Actions\\ForwardAction');
     $actionMapping->addExceptionConfig($exceptionConfig);
     $actionMapping->setPath('throw');
     $formInstance = null;
     $request = new Request();
     $response = new Response();
     $forward = $this->exceptionHandler->execute(new \Exception('Example Error'), $exceptionConfig, $actionMapping, $formInstance, $request, $response);
     $this->assertTrue($forward instanceof \Phruts\Config\ForwardConfig);
 }
Exemplo n.º 6
0
 public function execute(ActionMapping $mapping, AbstractActionForm $form = null, Request $request, Response $response)
 {
     // Identify the request parameters controlling our actions
     $page = $request->get("page");
     $prefix = $request->get("prefix");
     if ($page == null || $prefix == null) {
         $message = $this->getActionKernel()->getInternal()->getMessage("switch.required", $mapping->getPath());
         throw new \Phruts\Exception($message);
     }
     // Switch to the requested module
     \Phruts\Util\RequestUtils::selectModule($request, $this->getActionKernel()->getApplication());
     if ($request->attributes->get(\Phruts\Util\Globals::MODULE_KEY) == null) {
         $message = $this->getActionKernel()->getInternal()->getMessage("switch.prefix", $prefix);
         $response->setContent(400);
         $response->setContent($message);
         return null;
     }
     // Forward control to the specified module-relative URI
     $forward = new \Phruts\Config\ForwardConfig();
     $forward->setPath($page);
     return $forward;
 }
Exemplo n.º 7
0
 public function execute(ActionMapping $mapping, AbstractActionForm $form = null, Request $request, Response $response)
 {
     // Action Config defines the parameter for the forward configuration
     $parameter = $mapping->getParameter();
     if (empty($parameter)) {
         throw new \Phruts\Exception\IllegalArgumentException('Need to specify a parameter for this ForwardAction');
     }
     // Original strategy, let's assume it is a path
     if (!preg_match('/^[A-z]+$/', $parameter)) {
         $forward = new ForwardConfig();
         $forward->setPath($parameter);
         $forward->setContextRelative(true);
         return $forward;
     } else {
         // Forward the request
         $forward = $mapping->findForwardConfig($parameter);
         if (empty($forward)) {
             throw new \Phruts\Exception('ForwardAction parameter should reference a forward config name');
         }
         return $forward;
     }
 }
Exemplo n.º 8
0
 /**
  * Return a Action instance that will be used to process the current
  * request, creating a new one if necessary.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The kernel request we are
  * processing
  * @param \Symfony\Component\HttpFoundation\Response $response The kernel response we are
  * creating
  * @param \Phruts\Action\ActionMapping $mapping The mapping we are using
  * @return \Phruts\Config\ForwardConfig
  */
 protected function processActionCreate(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response, \Phruts\Action\ActionMapping $mapping)
 {
     // Acquire the Action instance we will be using (if there is one)
     $className = $mapping->getType();
     if (!empty($this->log)) {
         $this->log->debug('  Looking for Action instance for class ' . $className);
     }
     $instance = null;
     // Return any existing Action instance of this class
     if (array_key_exists($className, $this->actions)) {
         $instance = $this->actions[$className];
     }
     if (!is_null($instance)) {
         if (!empty($this->log)) {
             $this->log->debug('  Returning existing Action instance');
         }
         return $instance;
     }
     // Create an return a new Action instance
     if (!empty($this->log)) {
         $this->log->debug('  Creating new Action instance');
     }
     try {
         $instance = \Phruts\Util\ClassLoader::newInstance($className, '\\Phruts\\Action\\Action');
     } catch (\Exception $e) {
         $msg = $this->getInternal()->getMessage(null, 'actionCreate', $mapping->getPath());
         if (!empty($this->log)) {
             $this->log->error($msg . ' - ' . $e->getMessage());
         }
         throw new HttpException(500, $msg);
     }
     $instance->setActionKernel($this->actionKernel);
     $this->actions[$className] = $instance;
     return $instance;
 }
Exemplo n.º 9
0
 public function testInvalidActionForm()
 {
     // Mock a request
     $request = Request::create('http://localhost/test', 'GET', array(), array(), array(), array('PATH_INFO' => '/test'));
     $formConfig = new FormBeanConfig();
     $formConfig->setName('form1');
     $formConfig->setType('\\ActionTest\\MyInvalidForm');
     $this->moduleConfig->addFormBeanConfig($formConfig);
     $actionMapping = new ActionMapping();
     $actionMapping->setScope('request');
     $actionMapping->setPath('/test');
     $actionMapping->setType('\\Phruts\\Actions\\ForwardAction');
     $actionMapping->setParameter('success');
     $actionMapping->setName('form1');
     $actionMapping->setInput('myinput.html.twig');
     $forwardConfig = new ForwardConfig();
     $forwardConfig->setName('success');
     $forwardConfig->setPath('success.html.twig');
     $actionMapping->addForwardConfig($forwardConfig);
     $actionMapping->setModuleConfig($this->moduleConfig);
     $this->moduleConfig->addActionConfig($actionMapping);
     $this->requestProcessor->process($request, $this->response);
 }
Exemplo n.º 10
0
 /**
  * Method which is dispatched to when there is no value for specified
  * request parameter included in the request.  Subclasses of
  * <code>DispatchAction</code> should override this method if they wish
  * to provide default behavior different than producing an HTTP
  * "Bad Request" error.
  *
  */
 protected function unspecified(ActionMapping $mapping, AbstractActionForm $form = null, Request $request, Response $response)
 {
     $message = $this->getActionKernel()->getInternal()->getMessage("dispatch.parameter", $mapping->getPath(), $mapping->getParameter());
     $response->setStatusCode(400);
     $response->setContent($message);
     return null;
 }