]> source.dussan.org Git - nextcloud-server.git/commitdiff
unify tests
authorArthur Schiwon <blizzz@owncloud.com>
Mon, 18 Aug 2014 14:55:08 +0000 (16:55 +0200)
committerArthur Schiwon <blizzz@owncloud.com>
Mon, 18 Aug 2014 14:55:08 +0000 (16:55 +0200)
apps/user_ldap/tests/access.php

index 72b9780c018d8f28663eca518f3116fa29d5e31b..f436784675dcff53bb71cc23f1366efdea327590 100644 (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']));
+               }
        }
 }