Form: split constructor to make tests easier
This commit is contained in:
parent
94ce4112c7
commit
bab23c8f9b
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Test\Web;
|
||||
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
|
||||
class TestDirectorObjectForm extends DirectorObjectForm
|
||||
{
|
||||
protected function getActionFromRequest()
|
||||
{
|
||||
$this->setAction('director/test/url');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function regenerateCsrfToken()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -16,8 +16,18 @@ abstract class QuickBaseForm extends Zend_Form
|
|||
|
||||
public function __construct($options = null)
|
||||
{
|
||||
parent::__construct($this->handleOptions($options));
|
||||
$this->callZfConstructor($this->handleOptions($options))
|
||||
->initializePrefixPaths();
|
||||
}
|
||||
|
||||
protected function callZfConstructor($options = null)
|
||||
{
|
||||
parent::__construct($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function initializePrefixPaths()
|
||||
{
|
||||
if ($this->icingaModule) {
|
||||
$basedir = sprintf(
|
||||
'%s/%s/Web/Form',
|
||||
|
|
|
@ -65,12 +65,23 @@ abstract class QuickForm extends QuickBaseForm
|
|||
|
||||
public function __construct($options = null)
|
||||
{
|
||||
parent::__construct($this->handleOptions($options));
|
||||
parent::__construct($options);
|
||||
|
||||
$this->setMethod('post');
|
||||
$this->getActionFromRequest()
|
||||
->createIdElement()
|
||||
->regenerateCsrfToken()
|
||||
->setPreferredDecorators();
|
||||
}
|
||||
|
||||
protected function getActionFromRequest()
|
||||
{
|
||||
$this->setAction(Url::fromRequest());
|
||||
$this->createIdElement();
|
||||
$this->regenerateCsrfToken();
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setPreferredDecorators()
|
||||
{
|
||||
$this->setDecorators(
|
||||
array(
|
||||
'Description',
|
||||
|
@ -79,6 +90,8 @@ abstract class QuickForm extends QuickBaseForm
|
|||
'Form'
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function addSubmitButtonIfSet()
|
||||
|
@ -140,6 +153,7 @@ abstract class QuickForm extends QuickBaseForm
|
|||
$this->detectName();
|
||||
$this->addHidden(self::ID, $this->getName());
|
||||
$this->getElement(self::ID)->setIgnore(true);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSentValue($name, $default = null)
|
||||
|
|
Loading…
Reference in New Issue