summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-08-18 16:55:08 +0200
committerArthur Schiwon <blizzz@owncloud.com>2014-08-18 16:55:08 +0200
commit97fd39e983645bf743f8abd5c05bfe619f859690 (patch)
tree7b3720dc07c6e448af38c1860f5fd5916f9a60b0
parenteb7d70fc393a0a3b4441872de4a7ceb8bf0c7cc2 (diff)
downloadnextcloud-server-97fd39e983645bf743f8abd5c05bfe619f859690.tar.gz
nextcloud-server-97fd39e983645bf743f8abd5c05bfe619f859690.zip
unify tests
-rw-r--r--apps/user_ldap/tests/access.php91
1 files changed, 36 insertions, 55 deletions
diff --git a/apps/user_ldap/tests/access.php b/apps/user_ldap/tests/access.php
index 72b9780c018..f436784675d 100644
--- a/apps/user_ldap/tests/access.php
+++ b/apps/user_ldap/tests/access.php
@@ -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']));
+ }
}
}