mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-06-29 18:14:26 +02:00
Fix unit tests that were broken by API changes to the resource form classes and contemplate life choices. refs #9630
97 lines
3.1 KiB
PHP
97 lines
3.1 KiB
PHP
<?php
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
namespace Tests\Icinga\Forms\Config\Resource;
|
|
|
|
// Necessary as some of these tests disable phpunit's preservation
|
|
// of the global state (e.g. autoloaders are in the global state)
|
|
require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');
|
|
|
|
use Mockery;
|
|
use Icinga\Test\BaseTestCase;
|
|
use Icinga\Forms\Config\Resource\LdapResourceForm;
|
|
|
|
class LdapResourceFormTest extends BaseTestCase
|
|
{
|
|
public function tearDown()
|
|
{
|
|
parent::tearDown();
|
|
Mockery::close(); // Necessary because some tests run in a separate process
|
|
}
|
|
|
|
/**
|
|
* @runInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
*/
|
|
public function testValidLdapResourceIsValid()
|
|
{
|
|
$this->setUpResourceFactoryMock(
|
|
Mockery::mock()->shouldReceive('inspect')->andReturn(self::createInspector(false))->getMock()
|
|
);
|
|
|
|
// Passing array(null) is required to make Mockery call the constructor...
|
|
$form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null));
|
|
$form->shouldReceive('getView->escape')
|
|
->with(Mockery::type('string'))
|
|
->andReturnUsing(function ($s) {
|
|
return $s;
|
|
});
|
|
$form->setTokenDisabled();
|
|
|
|
$this->assertTrue(
|
|
LdapResourceForm::isValidResource($form->create()),
|
|
'ResourceForm claims that a valid ldap resource is not valid'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @runInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
*/
|
|
public function testInvalidLdapResourceIsNotValid()
|
|
{
|
|
$this->setUpResourceFactoryMock(
|
|
Mockery::mock()->shouldReceive('inspect')->andReturn(self::createInspector(true))->getMock()
|
|
);
|
|
|
|
// Passing array(null) is required to make Mockery call the constructor...
|
|
$form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null));
|
|
$form->shouldReceive('getView->escape')
|
|
->with(Mockery::type('string'))
|
|
->andReturnUsing(function ($s) {
|
|
return $s;
|
|
});
|
|
$form->setTokenDisabled();
|
|
|
|
$this->assertFalse(
|
|
LdapResourceForm::isValidResource($form->create()),
|
|
'ResourceForm claims that an invalid ldap resource is valid'
|
|
);
|
|
}
|
|
|
|
protected function setUpResourceFactoryMock($resourceMock)
|
|
{
|
|
Mockery::mock('alias:Icinga\Data\ResourceFactory')
|
|
->shouldReceive('createResource')
|
|
->with(Mockery::type('Icinga\Data\ConfigObject'))
|
|
->andReturn($resourceMock);
|
|
}
|
|
|
|
public static function createInspector($error = false, $log = array('log'))
|
|
{
|
|
if (! $error) {
|
|
$calls = array(
|
|
'hasError' => false,
|
|
'toArray' => $log
|
|
);
|
|
} else {
|
|
$calls = array(
|
|
'hasError' => true,
|
|
'getError' => 'Error',
|
|
'toArray' => $log
|
|
);
|
|
}
|
|
return Mockery::mock('Icinga\Data\Inspection', $calls);
|
|
}
|
|
}
|