Fix, rename and move ReorderFormTest

refs #5525
This commit is contained in:
Johannes Meyer 2014-09-09 12:02:51 +02:00
parent 7dbc83e21f
commit 40947acd16
2 changed files with 61 additions and 80 deletions

View File

@ -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'
);
}
}

View File

@ -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'
);
}
}