From 40947acd163d56658578e75fe076a6d50b96aa13 Mon Sep 17 00:00:00 2001 From: Johannes Meyer <johannes.meyer@netways.de> Date: Tue, 9 Sep 2014 12:02:51 +0200 Subject: [PATCH] Fix, rename and move ReorderFormTest refs #5525 --- .../Config/Authentication/ReorderFormTest.php | 80 ------------------- .../AuthenticationBackendReorderFormTest.php | 61 ++++++++++++++ 2 files changed, 61 insertions(+), 80 deletions(-) delete mode 100644 test/php/application/forms/Config/Authentication/ReorderFormTest.php create mode 100644 test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php diff --git a/test/php/application/forms/Config/Authentication/ReorderFormTest.php b/test/php/application/forms/Config/Authentication/ReorderFormTest.php deleted file mode 100644 index 808806f1a..000000000 --- a/test/php/application/forms/Config/Authentication/ReorderFormTest.php +++ /dev/null @@ -1,80 +0,0 @@ -<?php -// {{{ICINGA_LICENSE_HEADER}}} -// {{{ICINGA_LICENSE_HEADER}}} - -namespace Tests\Icinga\Form\Config\Authentication; - -use Mockery; -use Zend_Config; -use Icinga\Test\BaseTestCase; -use Icinga\Form\Config\Authentication\ReorderForm; - -class RequestLessReorderForm extends ReorderForm -{ - public $order; - - public function getValues($suppressArrayNotation = false) - { - return array('form_backend_order' => $this->order); - } -} - -class ReorderFormTest extends BaseTestCase -{ - public function setUp() - { - parent::setUp(); - $this->viewMock = Mockery::mock('\Zend_View'); - $this->viewMock->shouldReceive('icon')->andReturn(''); - } - - public function testMoveBackendUp() - { - $config = new Zend_Config( - array( - 'test1' => '', - 'test2' => '', - 'test3' => '' - ) - ); - $oldOrder = array_keys($config->toArray()); - - $form = new RequestLessReorderForm(); - $form->setCurrentOrder($oldOrder); - $form->setBackendName('test3'); - $form->setView($this->viewMock); - $form->create(); - - $form->order = $form->getSubForm('btn_reorder_up')->getElement('form_backend_order')->getValue(); - $this->assertSame( - $form->getReorderedConfig($config), - array('test1' => '', 'test3' => '', 'test2' => ''), - 'Moving elements up with ReorderForm does not seem to properly work' - ); - } - - public function testMoveBackendDown() - { - $config = new Zend_Config( - array( - 'test1' => '', - 'test2' => '', - 'test3' => '' - ) - ); - $oldOrder = array_keys($config->toArray()); - - $form = new RequestLessReorderForm(); - $form->setCurrentOrder($oldOrder); - $form->setBackendName('test1'); - $form->setView($this->viewMock); - $form->create(); - - $form->order = $form->getSubForm('btn_reorder_down')->getElement('form_backend_order')->getValue(); - $this->assertSame( - $form->getReorderedConfig($config), - array('test2' => '', 'test1' => '', 'test3' => ''), - 'Moving elements down with ReorderForm does not seem to properly work' - ); - } -} diff --git a/test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php b/test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php new file mode 100644 index 000000000..c79b12fd9 --- /dev/null +++ b/test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php @@ -0,0 +1,61 @@ +<?php +// {{{ICINGA_LICENSE_HEADER}}} +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Tests\Icinga\Form\Config; + +use Icinga\Test\BaseTestCase; +use Icinga\Application\Config; +use Icinga\Form\Config\AuthenticationBackendConfigForm; +use Icinga\Form\Config\AuthenticationBackendReorderForm; + +class AuthenticationBackendConfigFormWithoutSave extends AuthenticationBackendConfigForm +{ + public static $newConfig; + + public function save() + { + self::$newConfig = $this->config; + return false; + } +} + +class AuthenticationBackendReorderFormProvidingConfigFormWithoutSave extends AuthenticationBackendReorderForm +{ + public function getConfigForm() + { + $form = new AuthenticationBackendConfigFormWithoutSave(); + $form->setIniConfig($this->config); + return $form; + } +} + +class AuthenticationBackendReorderFormTest extends BaseTestCase +{ + public function testMoveBackend() + { + $config = new Config( + array( + 'test1' => '', + 'test2' => '', + 'test3' => '' + ) + ); + + $this->getRequestMock()->shouldReceive('getMethod')->andReturn('POST') + ->shouldReceive('isPost')->andReturn(true) + ->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1')); + + $form = new AuthenticationBackendReorderFormProvidingConfigFormWithoutSave(); + $form->setIniConfig($config); + $form->setTokenDisabled(); + $form->setUidDisabled(); + $form->handleRequest(); + + $this->assertEquals( + array('test1', 'test3', 'test2'), + AuthenticationBackendConfigFormWithoutSave::$newConfig->keys(), + 'Moving elements with AuthenticationBackendReorderForm does not seem to properly work' + ); + } +}