Exemplo n.º 1
0
 public function testActionConfig()
 {
     $moduleConfig = new ModuleConfig('prefix');
     $globalForward = new ForwardConfig();
     $globalForward->setPath("login.html.twig");
     $globalForward->setName('login');
     $moduleConfig->addForwardConfig($globalForward);
     $config = new ActionConfig();
     $config->setType('\\MyAction');
     $this->assertEquals('\\MyAction', $config->getType());
     $config->setScope('session');
     $this->assertEquals('session', $config->getScope());
     $config->setScope('request');
     $config->setName('myForm');
     $this->assertEquals('myForm', $config->getName());
     $config->setPath('mypath');
     $this->assertEquals('/mypath', $config->getPath());
     $config->setInput('form.php');
     $this->assertEquals('form.php', $config->getInput());
     $config->setPrefix('prefix');
     $this->assertEquals('prefix', $config->getPrefix());
     $config->setRoles("role1,role2,role3");
     $this->assertEquals('role1,role2,role3', $config->getRoles());
     $this->assertEquals(array('role1', 'role2', 'role3'), $config->getRoleNames());
     $config->setAttribute('attribute');
     $config->setModuleConfig($moduleConfig);
     // Test our sets
     $expected = "\\Phruts\\Config\\ActionConfig[path='/mypath',type='\\\\MyAction',name='myForm',scope='request',attribute='attribute',prefix='prefix',validate=true,input='form.php',roles='role1,role2,role3',unknown=false]";
     $this->assertEquals($expected, (string) $config);
     $config->setParameter('abc');
     $this->assertEquals('abc', $config->getParameter());
     // Test we can find the forward config
     $forwardConfig1 = new ForwardConfig();
     $forwardConfig1->setName('success');
     $forwardConfig1->setPath('mypath.html.twig');
     $config->addForwardConfig($forwardConfig1);
     $this->assertNotEmpty($config->findForwardConfig('success'));
     $config->removeForwardConfig($forwardConfig1);
     $this->assertEmpty($config->findForwardConfig('success'));
     $this->assertNotEmpty($config->findForwardConfigs());
     $this->assertNotEmpty($config->findForwardConfig('login'));
     $config->setParameter('myparam');
     $this->assertEquals('myparam', $config->getParameter());
     $exceptionConfig = new ExceptionConfig();
     $exceptionConfig->setType('\\Exception');
     $exceptionConfig->setPath('exception.html.twig');
     $config->addExceptionConfig($exceptionConfig);
     $this->assertNotEmpty($config->findExceptionConfig('\\Exception'));
     $this->assertEmpty($config->findExceptionConfig('\\MyOtherException'));
     $config->removeExceptionConfig($exceptionConfig);
     $this->assertEmpty($config->findExceptionConfig('\\Exception'));
     $this->assertTrue($config->getValidate());
     $config->setValidate('no');
     $this->assertNotTrue($config->getValidate());
     $config->setValidate('yes');
     $this->assertTrue($config->getValidate());
     $config->setValidate('false');
     $this->assertNotTrue($config->getValidate());
     $config->setValidate('true');
     $this->assertTrue($config->getValidate());
     $this->assertNotTrue($config->getUnknown());
     $config->setUnknown('yes');
     $this->assertTrue($config->getUnknown());
     $config->setUnknown('false');
     $this->assertNotTrue($config->getUnknown());
     $config->setUnknown('true');
     $this->assertTrue($config->getUnknown());
     $config->setUnknown('no');
     $this->assertNotTrue($config->getUnknown());
     $config->setPath('path');
     $this->assertEquals('/path', $config->getPath());
     // TODO: Test exception
     $config->freeze();
     $this->setExpectedException('\\Phruts\\Exception\\IllegalStateException');
     $config->setType('\\MyOtherActionActually');
 }