From: Arthur Schiwon Date: Mon, 18 Aug 2014 14:55:08 +0000 (+0200) Subject: unify tests X-Git-Tag: v8.0.0alpha1~875^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=97fd39e983645bf743f8abd5c05bfe619f859690;p=nextcloud-server.git unify tests --- 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'])); + } } }