From 97fd39e983645bf743f8abd5c05bfe619f859690 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@owncloud.com>
Date: Mon, 18 Aug 2014 16:55:08 +0200
Subject: [PATCH] unify tests

---
 apps/user_ldap/tests/access.php | 91 +++++++++++++--------------------
 1 file changed, 36 insertions(+), 55 deletions(-)

diff --git a/apps/user_ldap/tests/access.php b/apps/user_ldap/tests/access.php
index 72b9780c01..f436784675 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']));
+		}
 	}
 }
-- 
GitLab