Browse Source

unify tests

tags/v8.0.0alpha1
Arthur Schiwon 9 years ago
parent
commit
97fd39e983
1 changed files with 36 additions and 55 deletions
  1. 36
    55
      apps/user_ldap/tests/access.php

+ 36
- 55
apps/user_ldap/tests/access.php View File

@@ -157,64 +157,48 @@ class Test_Access extends \PHPUnit_Framework_TestCase {
$this->assertSame($expected, $access->getDomainDNFromDN($inputDN));
}

public function stringResemblesDNYes() {
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'
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
)
);

$lw->expects($this->once())
->method('explodeDN')
->will($this->returnValue($interResult));

$this->assertTrue($access->stringResemblesDN($input));
}

public function stringResemblesDNYesLDAPmod() {
public function testStringResemblesDN() {
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');
}
$cases = $this->getResemblesDNInputData();

$input = 'foo=bar,bar=foo,dc=foobar';
$interResult = array(
'count' => 3,
0 => 'foo=bar',
1 => 'bar=foo',
2 => 'dc=foobar'
);

$lw->expects($this->once())
$lw->expects($this->exactly(2))
->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));
->will($this->returnCallback(function ($dn) use ($cases) {
foreach($cases as $case) {
if($dn === $case['input']) {
return $case['interResult'];
}
}
}));

foreach($cases as $case) {
$this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
}
}

public function stringResemblesDNNoLDAPMod() {
public function testStringResemblesDNLDAPmod() {
list($lw, $con, $um) = $this->getConnecterAndLdapMock();
$lw = new \OCA\user_ldap\lib\LDAP();
$access = new Access($con, $lw, $um);
@@ -223,13 +207,10 @@ class Test_Access extends \PHPUnit_Framework_TestCase {
$this->markTestSkipped('LDAP Module not available');
}

$input = 'foobarbarfoodcfoobar';
$interResult = false;
$cases = $this->getResemblesDNInputData();

$lw->expects($this->once())
->method('explodeDN')
->will($this->returnValue($interResult));

$this->assertFalse($access->stringResemblesDN($input));
foreach($cases as $case) {
$this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
}
}
}

Loading…
Cancel
Save