[icinga-checkins] icinga.org: icingaweb2-module-director/bugfix/loop-templateresolver-11803: Form: split constructor to make tests easier

git at icinga.org git at icinga.org
Mon Oct 31 13:31:44 CET 2016


Module: icingaweb2-module-director
Branch: bugfix/loop-templateresolver-11803
Commit: bab23c8f9b1f044946ca3be067808129f4316e69
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=bab23c8f9b1f044946ca3be067808129f4316e69

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 27 16:31:04 2016 +0000

Form: split constructor to make tests easier

---

 .../Test/Web/Form/TestDirectorObjectForm.php       |   19 +++++++++++++++++++
 library/Director/Web/Form/QuickBaseForm.php        |   12 +++++++++++-
 library/Director/Web/Form/QuickForm.php            |   20 +++++++++++++++++---
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/library/Director/Test/Web/Form/TestDirectorObjectForm.php b/library/Director/Test/Web/Form/TestDirectorObjectForm.php
new file mode 100644
index 0000000..0722e78
--- /dev/null
+++ b/library/Director/Test/Web/Form/TestDirectorObjectForm.php
@@ -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;
+    }
+}
diff --git a/library/Director/Web/Form/QuickBaseForm.php b/library/Director/Web/Form/QuickBaseForm.php
index 4ea5330..0f57710 100644
--- a/library/Director/Web/Form/QuickBaseForm.php
+++ b/library/Director/Web/Form/QuickBaseForm.php
@@ -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',
diff --git a/library/Director/Web/Form/QuickForm.php b/library/Director/Web/Form/QuickForm.php
index 4bf1452..19b1079 100644
--- a/library/Director/Web/Form/QuickForm.php
+++ b/library/Director/Web/Form/QuickForm.php
@@ -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)



More information about the icinga-checkins mailing list