2014-04-16 11:50:58 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Tests\Icinga\Form\Config\Authentication;
|
|
|
|
|
2014-04-25 16:39:54 +02:00
|
|
|
// 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');
|
|
|
|
|
2014-04-16 16:41:23 +02:00
|
|
|
use Mockery;
|
2014-11-11 12:11:14 +01:00
|
|
|
use Icinga\Application\Config;
|
2014-04-16 11:50:58 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
|
|
|
use Icinga\Form\Config\Authentication\DbBackendForm;
|
|
|
|
|
|
|
|
class DbBackendFormTest extends BaseTestCase
|
|
|
|
{
|
2014-04-16 16:41:23 +02:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
Mockery::close(); // Necessary because some tests run in a separate process
|
|
|
|
}
|
|
|
|
|
2014-04-16 11:50:58 +02:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
2014-04-25 16:39:54 +02:00
|
|
|
* @preserveGlobalState disabled
|
2014-04-16 11:50:58 +02:00
|
|
|
*/
|
|
|
|
public function testValidBackendIsValid()
|
|
|
|
{
|
2014-09-03 10:00:41 +02:00
|
|
|
$this->setUpResourceFactoryMock();
|
|
|
|
Mockery::mock('overload:Icinga\Authentication\Backend\DbUserBackend')
|
2014-06-30 18:16:21 +02:00
|
|
|
->shouldReceive('count')
|
|
|
|
->andReturn(2);
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
$form = new DbBackendForm();
|
2014-09-09 10:39:49 +02:00
|
|
|
$form->setTokenDisabled();
|
|
|
|
$form->setResources(array('test_db_backend'));
|
|
|
|
$form->populate(array('resource' => 'test_db_backend'));
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
$this->assertTrue(
|
2014-09-29 11:02:45 +02:00
|
|
|
DbBackendForm::isValidAuthenticationBackend($form),
|
2014-04-16 11:50:58 +02:00
|
|
|
'DbBackendForm claims that a valid authentication backend with users is not valid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
2014-04-25 16:39:54 +02:00
|
|
|
* @preserveGlobalState disabled
|
2014-04-16 11:50:58 +02:00
|
|
|
*/
|
|
|
|
public function testInvalidBackendIsNotValid()
|
|
|
|
{
|
2014-09-03 10:00:41 +02:00
|
|
|
$this->setUpResourceFactoryMock();
|
|
|
|
Mockery::mock('overload:Icinga\Authentication\Backend\DbUserBackend')
|
2014-06-30 18:16:21 +02:00
|
|
|
->shouldReceive('count')
|
|
|
|
->andReturn(0);
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
$form = new DbBackendForm();
|
2014-09-09 10:39:49 +02:00
|
|
|
$form->setTokenDisabled();
|
|
|
|
$form->setResources(array('test_db_backend'));
|
|
|
|
$form->populate(array('resource' => 'test_db_backend'));
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
$this->assertFalse(
|
2014-09-29 11:02:45 +02:00
|
|
|
DbBackendForm::isValidAuthenticationBackend($form),
|
2014-04-16 11:50:58 +02:00
|
|
|
'DbBackendForm claims that an invalid authentication backend without users is valid'
|
|
|
|
);
|
|
|
|
}
|
2014-06-30 18:16:21 +02:00
|
|
|
|
|
|
|
protected function setUpResourceFactoryMock()
|
|
|
|
{
|
|
|
|
Mockery::mock('alias:Icinga\Data\ResourceFactory')
|
2014-09-29 12:56:36 +02:00
|
|
|
->shouldReceive('createResource')
|
|
|
|
->andReturn(Mockery::mock('Icinga\Data\Db\DbConnection'))
|
|
|
|
->shouldReceive('getResourceConfig')
|
2014-11-11 12:11:14 +01:00
|
|
|
->andReturn(new Config());
|
2014-06-30 18:16:21 +02:00
|
|
|
}
|
2014-04-16 11:50:58 +02:00
|
|
|
}
|