Exemplo n.º 1
0
 public function setUp()
 {
     $this->request = new \Symfony\Component\HttpFoundation\Request();
     $storage = new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage();
     $session = new \Symfony\Component\HttpFoundation\Session\Session($storage);
     $this->request->setSession($session);
     $this->request->initialize();
     $this->response = new \Symfony\Component\HttpFoundation\Response();
     $this->moduleConfig = new \Phruts\Config\ModuleConfig('');
     $actionConfig = new \Phruts\Config\ActionConfig();
     $actionConfig->setPath('/default');
     $actionConfig->setType('\\Phruts\\Actions\\ForwardAction');
     $this->moduleConfig->addActionConfig($actionConfig);
     $controllerConfig = new \Phruts\Config\ControllerConfig();
     $controllerConfig->setLocale('fr');
     $controllerConfig->setContentType('application/x-javascript');
     $this->moduleConfig->setControllerConfig($controllerConfig);
     // Add a default action mapping
     $this->actionConfig1 = new ActionMapping();
     $this->actionConfig1->setPath('/mypath');
     $this->actionConfig1->setType('\\Phruts\\Action\\Action');
     $forwardConfig = new ForwardConfig();
     $forwardConfig->setName('success');
     $forwardConfig->setPath('success.html.twig');
     $this->actionConfig1->setModuleConfig($this->moduleConfig);
     $this->moduleConfig->addActionConfig($this->actionConfig1);
     //        $this->application = new \Silex\Application();
     $this->application = $this->getMock('\\Silex\\Application', array('handle'));
     $this->application->expects($this->any())->method('handle')->willReturn(new Response());
     $this->actionKernel = new \Phruts\Action\ActionKernel($this->application);
     $this->requestProcessor = new \Phruts\Action\RequestProcessor();
     $this->requestProcessor->init($this->actionKernel, $this->moduleConfig);
 }
Exemplo n.º 2
0
 /**
  * Create (if necessary) and return a \Phruts\Action\AbstractActionForm instance appropriate
  * for this request.
  *
  * If no \Phruts\Action\AbstractActionForm instance is required, return null.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The actionKernel request we are
  * processing
  * @param \Phruts\Config\ActionConfig $mapping The action mapping for this request
  * @param \Phruts\Config\ModuleConfig $moduleConfig The configuration for this
  * module
  * @param \Phruts\Action\ActionKernel $actionKernel The action actionKernel
  * @return \Phruts\Action\AbstractActionForm Form instance associated with this
  * request
  */
 public static function createActionForm(\Symfony\Component\HttpFoundation\Request $request, \Phruts\Config\ActionConfig $mapping, \Phruts\Config\ModuleConfig $moduleConfig, \Phruts\Action\ActionKernel $kernel)
 {
     // Is there a form bean associated with this mapping?
     $attribute = $mapping->getAttribute();
     if (is_null($attribute)) {
         return null;
     }
     // Look up the form bean configuration information to use
     $name = $mapping->getName();
     $config = $moduleConfig->findFormBeanConfig($name);
     if (is_null($config)) {
         return null;
     }
     $instance = null;
     $session = null;
     if ($mapping->getScope() == 'request') {
         $instance = $request->attributes->get($attribute);
     } else {
         \Phruts\Util\ClassLoader::loadClass($config->getType());
         $session = $request->getSession();
         if (!empty($session)) {
             $instance = $session->get($attribute);
         }
     }
     // Can we recycle the existing form bean instance (if there is one)?
     if (!is_null($instance)) {
         $configClass = $config->getType();
         $instanceClass = get_class($instance);
         if (\Phruts\Util\ClassLoader::classIsAssignableFrom($configClass, $instanceClass)) {
             return $instance;
         }
     }
     // Create and return a new form bean instance
     try {
         /** @var \Phruts\Action\AbstractActionForm $instance */
         $instance = \Phruts\Util\ClassLoader::newInstance($config->getType(), '\\Phruts\\Action\\AbstractActionForm');
         $instance->setActionKernel($kernel);
     } catch (\Exception $e) {
         $msg = $kernel->getInternal()->getMessage(null, 'formBean', $config->getType());
         throw new \Phruts\Exception($msg);
     }
     return $instance;
 }
Exemplo n.º 3
0
 public function testModuleConfig()
 {
     $config = new ModuleConfig('prefix2');
     $this->assertEquals('prefix2', $config->getPrefix());
     $config->setPrefix('prefix');
     $this->assertEquals('prefix', $config->getPrefix());
     $controllerConfig = new ControllerConfig();
     $controllerConfig->setProcessorClass('\\Mock\\Proccessor');
     $controllerConfig->setContentType('application/x-javascript');
     $controllerConfig->setNocache('true');
     $controllerConfig->setInputForward('true');
     $controllerConfig->setLocale('true');
     $expected = "\\Phruts\\Config\\ControllerConfig[processorClass='\\\\Mock\\\\Proccessor',contentType='application/x-javascript',nocache=true,inputForward=true,locale=true]";
     $this->assertEquals($expected, (string) $controllerConfig);
     $config->setControllerConfig($controllerConfig);
     $this->assertNotEmpty($config->getControllerConfig());
     $actionConfig1 = new ActionConfig();
     $actionConfig1->setPath('action1');
     $actionConfig1->setType('\\ForwardConfig');
     $config->addActionConfig($actionConfig1);
     $actionConfig2 = new ActionConfig();
     $actionConfig2->setPath('action2');
     $actionConfig2->setType('\\ForwardConfig');
     $config->addActionConfig($actionConfig2);
     $this->assertNotEmpty($config->findActionConfig('/action1'));
     $this->assertNotEmpty($config->findActionConfig('/action2'));
     $config->removeActionConfig($actionConfig2);
     $this->assertEmpty($config->findActionConfig('/action2'));
     $actionClass = '\\MyActionConfigClass';
     $config->setActionClass($actionClass);
     $this->assertEquals('\\MyActionConfigClass', $config->getActionClass());
     $formBeanConfig1 = new FormBeanConfig();
     $formBeanConfig1->setName('myForm1');
     $formBeanConfig1->setType('\\MyForm1');
     $formBeanConfig2 = new FormBeanConfig();
     $formBeanConfig2->setName('myForm2');
     $formBeanConfig2->setType('\\MyForm2');
     $config->addFormBeanConfig($formBeanConfig1);
     $config->addFormBeanConfig($formBeanConfig2);
     $this->assertEquals(2, count($config->findFormBeanConfigs()));
     $this->assertEquals($formBeanConfig1, $config->findFormBeanConfig('myForm1'));
     $this->assertEquals($formBeanConfig2, $config->findFormBeanConfig('myForm2'));
     $config->removeFormBeanConfig($formBeanConfig2);
     $this->assertEmpty($config->findFormBeanConfig('myForm2'));
     $forwardConfig1 = new ForwardConfig();
     $forwardConfig1->setName('welcome');
     $forwardConfig1->setPath('welcome.html.twig');
     $forwardConfig2 = new ForwardConfig();
     $forwardConfig2->setName('login');
     $forwardConfig1->setPath('login.html.twig');
     $config->addForwardConfig($forwardConfig1);
     $config->addForwardConfig($forwardConfig2);
     $this->assertEquals($forwardConfig1, $config->findForwardConfig('welcome'));
     $this->assertEquals($forwardConfig2, $config->findForwardConfig('login'));
     $config->removeForwardConfig($forwardConfig1);
     $this->assertEmpty($config->findForwardConfig('welcome'));
     $dataSourceConfig = new DataSourceConfig();
     $dataSourceConfig->setKey('key1');
     $config->addDataSourceConfig($dataSourceConfig);
     $dataSourceConfig2 = new DataSourceConfig();
     $dataSourceConfig2->setKey('key2');
     $config->addDataSourceConfig($dataSourceConfig2);
     $this->assertEquals(2, count($config->findDataSourceConfigs()));
     $this->assertEquals($dataSourceConfig, $config->findDataSourceConfig('key1'));
     $this->assertEquals($dataSourceConfig2, $config->findDataSourceConfig('key2'));
     $config->removeDataSourceConfig($dataSourceConfig);
     $this->assertEmpty($config->findDataSourceConfig('key1'));
     $messageConfig = new MessageResourcesConfig();
     $messageConfig->setKey('key1');
     $config->addMessageResourcesConfig($messageConfig);
     $this->assertEquals($messageConfig, $config->findMessageResourcesConfig('key1'));
     $this->assertEquals(1, count($config->findMessageResourcesConfigs()));
     $config->removeMessageResourcesConfig($messageConfig);
     $this->assertEmpty($config->findMessageResourcesConfig('key1'));
     $plugInConfig = new PlugInConfig();
     $plugInConfig->setKey('test');
     $plugInConfig->setClassName('\\stdClass');
     $config->addPlugInConfig($plugInConfig);
     $this->assertEquals(1, count($config->findPlugInConfigs()));
     $exceptionConfig = new ExceptionConfig();
     $exceptionConfig->setType('\\Exception');
     $config->addExceptionConfig($exceptionConfig);
     $this->assertEquals(1, count($config->findExceptionConfigs()));
     $this->assertEquals($exceptionConfig, $config->findExceptionConfig('\\Exception'));
     $config->removeExceptionConfig($exceptionConfig);
     $this->assertEmpty($config->findExceptionConfig('\\Exception'));
     // Test exception
     $config->freeze();
     $this->assertTrue($config->getConfigured());
     $this->setExpectedException('\\Phruts\\Exception\\IllegalStateException');
     $config->setPrefix('prefix2');
 }
Exemplo n.º 4
0
 /**
  * Remove the specified action configuration instance.
  *
  * @param \Phruts\Config\ActionConfig $config \Phruts\Config\ActionConfig instance to be
  * removed
  * @throws \Phruts\Exception\IllegalStateException - If this module configuration has
  * been frozen
  */
 public function removeActionConfig(\Phruts\Config\ActionConfig $config)
 {
     if ($this->configured) {
         throw new \Phruts\Exception\IllegalStateException('Configuration is frozen');
     }
     unset($this->actionConfigs[$config->getPath()]);
 }