2014-09-09 13:06:30 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-09 13:06:30 +02:00
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Tests\Icinga\Forms\Config\Resource;
|
2014-09-09 13:06:30 +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');
|
|
|
|
|
|
|
|
use Mockery;
|
|
|
|
use Icinga\Test\BaseTestCase;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\Config\Resource\LdapResourceForm;
|
2014-09-09 13:06:30 +02:00
|
|
|
|
|
|
|
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(
|
2015-06-23 16:56:34 +02:00
|
|
|
Mockery::mock()->shouldReceive('connect')->once()->shouldReceive('bind')->once()->getMock()
|
2014-09-09 13:06:30 +02:00
|
|
|
);
|
|
|
|
|
2015-04-30 15:20:19 +02:00
|
|
|
// Passing array(null) is required to make Mockery call the constructor...
|
|
|
|
$form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null));
|
2015-03-04 09:43:37 +01:00
|
|
|
$form->shouldReceive('getView->escape')
|
|
|
|
->with(Mockery::type('string'))
|
|
|
|
->andReturnUsing(function ($s) { return $s; });
|
2014-09-29 12:56:36 +02:00
|
|
|
$form->setTokenDisabled();
|
|
|
|
|
2014-09-09 13:06:30 +02:00
|
|
|
$this->assertTrue(
|
2014-09-29 12:56:36 +02:00
|
|
|
LdapResourceForm::isValidResource($form->create()),
|
2014-09-09 13:06:30 +02:00
|
|
|
'ResourceForm claims that a valid ldap resource is not valid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
|
|
|
public function testInvalidLdapResourceIsNotValid()
|
|
|
|
{
|
|
|
|
$this->setUpResourceFactoryMock(
|
2015-06-23 16:56:34 +02:00
|
|
|
Mockery::mock()->shouldReceive('connect')->once()->shouldReceive('bind')->andThrow('\Exception')->getMock()
|
2014-09-09 13:06:30 +02:00
|
|
|
);
|
|
|
|
|
2015-04-30 15:20:19 +02:00
|
|
|
// Passing array(null) is required to make Mockery call the constructor...
|
|
|
|
$form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null));
|
2015-03-04 09:43:37 +01:00
|
|
|
$form->shouldReceive('getView->escape')
|
|
|
|
->with(Mockery::type('string'))
|
|
|
|
->andReturnUsing(function ($s) { return $s; });
|
2014-09-29 12:56:36 +02:00
|
|
|
$form->setTokenDisabled();
|
|
|
|
|
2014-09-09 13:06:30 +02:00
|
|
|
$this->assertFalse(
|
2014-09-29 12:56:36 +02:00
|
|
|
LdapResourceForm::isValidResource($form->create()),
|
2014-09-09 13:06:30 +02:00
|
|
|
'ResourceForm claims that an invalid ldap resource is valid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setUpResourceFactoryMock($resourceMock)
|
|
|
|
{
|
|
|
|
Mockery::mock('alias:Icinga\Data\ResourceFactory')
|
|
|
|
->shouldReceive('createResource')
|
2014-11-18 13:11:52 +01:00
|
|
|
->with(Mockery::type('Icinga\Data\ConfigObject'))
|
2014-09-09 13:06:30 +02:00
|
|
|
->andReturn($resourceMock);
|
|
|
|
}
|
|
|
|
}
|