icingaweb2/test/php/application/forms/Config/Resource/LdapResourceFormTest.php

69 lines
2.0 KiB
PHP
Raw Normal View History

2014-09-09 13:06:30 +02:00
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Form\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\Form\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(
2014-09-29 12:56:36 +02:00
Mockery::mock()->shouldReceive('testCredentials')->once()->andReturn(true)->getMock()
2014-09-09 13:06:30 +02:00
);
2014-09-29 12:56:36 +02:00
$form = new LdapResourceForm();
$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(
2014-09-29 12:56:36 +02:00
Mockery::mock()->shouldReceive('testCredentials')->once()->andThrow('\Exception')->getMock()
2014-09-09 13:06:30 +02:00
);
2014-09-29 12:56:36 +02:00
$form = new LdapResourceForm();
$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')
->with(Mockery::type('Icinga\Application\Config'))
2014-09-09 13:06:30 +02:00
->andReturn($resourceMock);
}
}