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