Drop LdapBackendFormTest
It's redundant now, we should test the inspection code directly instead.
This commit is contained in:
parent
f8f8a4c848
commit
75a48a3b35
|
@ -1,105 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Tests\Icinga\Forms\Config\UserBackend;
|
|
||||||
|
|
||||||
// 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\Data\ConfigObject;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
|
||||||
use Icinga\Forms\Config\UserBackend\LdapBackendForm;
|
|
||||||
use Icinga\Exception\AuthenticationException;
|
|
||||||
use Tests\Icinga\Forms\Config\Resource\LdapResourceFormTest;
|
|
||||||
|
|
||||||
class LdapBackendFormTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
parent::tearDown();
|
|
||||||
Mockery::close(); // Necessary because some tests run in a separate process
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @runInSeparateProcess
|
|
||||||
* @preserveGlobalState disabled
|
|
||||||
*/
|
|
||||||
public function testValidBackendIsValid()
|
|
||||||
{
|
|
||||||
$ldapUserBackendMock = Mockery::mock('overload:Icinga\Authentication\User\LdapUserBackend')
|
|
||||||
->shouldReceive('inspect')
|
|
||||||
->andReturn(self::createInspector(false))->getMock();
|
|
||||||
$this->setUpUserBackendMock($ldapUserBackendMock);
|
|
||||||
|
|
||||||
// Passing array(null) is required to make Mockery call the constructor...
|
|
||||||
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null));
|
|
||||||
$form->shouldReceive('getView->escape')
|
|
||||||
->with(Mockery::type('string'))
|
|
||||||
->andReturnUsing(function ($s) {
|
|
||||||
return $s;
|
|
||||||
});
|
|
||||||
$form->setTokenDisabled();
|
|
||||||
$form->setResources(array('test_ldap_backend'));
|
|
||||||
$form->populate(array('resource' => 'test_ldap_backend'));
|
|
||||||
|
|
||||||
$this->assertTrue(
|
|
||||||
LdapBackendForm::isValidUserBackend($form),
|
|
||||||
'LdapBackendForm claims that a valid user backend with users is not valid'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @runInSeparateProcess
|
|
||||||
* @preserveGlobalState disabled
|
|
||||||
*/
|
|
||||||
public function testInvalidBackendIsNotValid()
|
|
||||||
{
|
|
||||||
$ldapUserBackendMock = Mockery::mock('overload:Icinga\Authentication\User\LdapUserBackend')
|
|
||||||
->shouldReceive('inspect')
|
|
||||||
->andReturn(self::createInspector(true))->getMock();
|
|
||||||
$ldapUserBackendMock->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
|
|
||||||
$this->setUpUserBackendMock($ldapUserBackendMock);
|
|
||||||
|
|
||||||
// Passing array(null) is required to make Mockery call the constructor...
|
|
||||||
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null));
|
|
||||||
$form->shouldReceive('getView->escape')
|
|
||||||
->with(Mockery::type('string'))
|
|
||||||
->andReturnUsing(function ($s) {
|
|
||||||
return $s;
|
|
||||||
});
|
|
||||||
$form->setTokenDisabled();
|
|
||||||
$form->setResources(array('test_ldap_backend'));
|
|
||||||
$form->populate(array('resource' => 'test_ldap_backend'));
|
|
||||||
|
|
||||||
$this->assertFalse(
|
|
||||||
LdapBackendForm::isValidUserBackend($form),
|
|
||||||
'LdapBackendForm claims that an invalid user backend without users is valid'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setUpUserBackendMock($ldapUserBackendMock)
|
|
||||||
{
|
|
||||||
Mockery::mock('alias:Icinga\Authentication\User\UserBackend')
|
|
||||||
->shouldReceive('create')
|
|
||||||
->andReturn($ldapUserBackendMock);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue