Skip to content

Commit

Permalink
Fix form tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Meyer committed Sep 29, 2014
1 parent 243dd19 commit 07d25e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Expand Up @@ -9,6 +9,7 @@
require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');

use Mockery;
use Zend_Config;
use Icinga\Test\BaseTestCase;
use Icinga\Form\Config\Authentication\DbBackendForm;

Expand Down Expand Up @@ -67,7 +68,9 @@ public function testInvalidBackendIsNotValid()
protected function setUpResourceFactoryMock()
{
Mockery::mock('alias:Icinga\Data\ResourceFactory')
->shouldReceive('create')
->andReturn(Mockery::mock('Icinga\Data\Db\DbConnection'));
->shouldReceive('createResource')
->andReturn(Mockery::mock('Icinga\Data\Db\DbConnection'))
->shouldReceive('getResourceConfig')
->andReturn(new Zend_Config(array()));
}
}
Expand Up @@ -9,6 +9,7 @@
require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');

use Mockery;
use Zend_Config;
use Icinga\Test\BaseTestCase;
use Icinga\Form\Config\Authentication\LdapBackendForm;
use Icinga\Exception\AuthenticationException;
Expand Down Expand Up @@ -66,9 +67,9 @@ public function testInvalidBackendIsNotValid()
protected function setUpResourceFactoryMock()
{
Mockery::mock('alias:Icinga\Data\ResourceFactory')
->shouldReceive('createResource')
->andReturn(Mockery::mock('Icinga\Protocol\Ldap\Connection'))
->shouldReceive('getResourceConfig')
->andReturn(new \Zend_Config(array()))
->shouldReceive('create')
->andReturn(Mockery::mock('Icinga\Protocol\Ldap\Connection'));
->andReturn(new Zend_Config(array()));
}
}
Expand Up @@ -27,11 +27,14 @@ public function tearDown()
public function testValidLdapResourceIsValid()
{
$this->setUpResourceFactoryMock(
Mockery::mock()->shouldReceive('connect')->getMock()
Mockery::mock()->shouldReceive('testCredentials')->once()->andReturn(true)->getMock()
);

$form = new LdapResourceForm();
$form->setTokenDisabled();

$this->assertTrue(
LdapResourceForm::isValidResource(new LdapResourceForm()),
LdapResourceForm::isValidResource($form->create()),
'ResourceForm claims that a valid ldap resource is not valid'
);
}
Expand All @@ -43,11 +46,14 @@ public function testValidLdapResourceIsValid()
public function testInvalidLdapResourceIsNotValid()
{
$this->setUpResourceFactoryMock(
Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
Mockery::mock()->shouldReceive('testCredentials')->once()->andThrow('\Exception')->getMock()
);

$form = new LdapResourceForm();
$form->setTokenDisabled();

$this->assertFalse(
LdapResourceForm::isValidResource(new LdapResourceForm()),
LdapResourceForm::isValidResource($form->create()),
'ResourceForm claims that an invalid ldap resource is valid'
);
}
Expand Down

0 comments on commit 07d25e8

Please sign in to comment.