unify tests

This commit is contained in:
Arthur Schiwon 2014-08-18 16:55:08 +02:00
parent eb7d70fc39
commit 97fd39e983
1 changed files with 37 additions and 56 deletions

View File

@ -157,26 +157,48 @@ class Test_Access extends \PHPUnit_Framework_TestCase {
$this->assertSame($expected, $access->getDomainDNFromDN($inputDN));
}
public function stringResemblesDNYes() {
private function getResemblesDNInputData() {
return $cases = array(
array(
'input' => 'foo=bar,bar=foo,dc=foobar',
'interResult' => array(
'count' => 3,
0 => 'foo=bar',
1 => 'bar=foo',
2 => 'dc=foobar'
),
'expectedResult' => true
),
array(
'input' => 'foobarbarfoodcfoobar',
'interResult' => false,
'expectedResult' => false
)
);
}
public function testStringResemblesDN() {
list($lw, $con, $um) = $this->getConnecterAndLdapMock();
$access = new Access($con, $lw, $um);
$input = 'foo=bar,bar=foo,dc=foobar';
$interResult = array(
'count' => 3,
0 => 'foo=bar',
1 => 'bar=foo',
2 => 'dc=foobar'
);
$cases = $this->getResemblesDNInputData();
$lw->expects($this->once())
$lw->expects($this->exactly(2))
->method('explodeDN')
->will($this->returnValue($interResult));
->will($this->returnCallback(function ($dn) use ($cases) {
foreach($cases as $case) {
if($dn === $case['input']) {
return $case['interResult'];
}
}
}));
$this->assertTrue($access->stringResemblesDN($input));
foreach($cases as $case) {
$this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
}
}
public function stringResemblesDNYesLDAPmod() {
public function testStringResemblesDNLDAPmod() {
list($lw, $con, $um) = $this->getConnecterAndLdapMock();
$lw = new \OCA\user_ldap\lib\LDAP();
$access = new Access($con, $lw, $um);
@ -185,51 +207,10 @@ class Test_Access extends \PHPUnit_Framework_TestCase {
$this->markTestSkipped('LDAP Module not available');
}
$input = 'foo=bar,bar=foo,dc=foobar';
$interResult = array(
'count' => 3,
0 => 'foo=bar',
1 => 'bar=foo',
2 => 'dc=foobar'
);
$cases = $this->getResemblesDNInputData();
$lw->expects($this->once())
->method('explodeDN')
->will($this->returnValue($interResult));
$this->assertTrue($access->stringResemblesDN($input));
}
public function stringResemblesDNNo() {
list($lw, $con, $um) = $this->getConnecterAndLdapMock();
$access = new Access($con, $lw, $um);
$input = 'foobarbarfoodcfoobar';
$interResult = false;
$lw->expects($this->once())
->method('explodeDN')
->will($this->returnValue($interResult));
$this->assertFalse($access->stringResemblesDN($input));
}
public function stringResemblesDNNoLDAPMod() {
list($lw, $con, $um) = $this->getConnecterAndLdapMock();
$lw = new \OCA\user_ldap\lib\LDAP();
$access = new Access($con, $lw, $um);
if(!function_exists('ldap_explode_dn')) {
$this->markTestSkipped('LDAP Module not available');
foreach($cases as $case) {
$this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
}
$input = 'foobarbarfoodcfoobar';
$interResult = false;
$lw->expects($this->once())
->method('explodeDN')
->will($this->returnValue($interResult));
$this->assertFalse($access->stringResemblesDN($input));
}
}