aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-06-25 18:01:04 +0200
committerArthur Schiwon <blizzz@owncloud.com>2014-08-29 11:14:35 +0200
commitf47a4a8c158f538d5febedec7282f576360a4d02 (patch)
tree1a7f2b980b8c396ba9bdf44e158991eec0ef9c74 /apps/user_ldap/tests
parent441c600c906a2ec55bdab123840be5d1d63bb679 (diff)
downloadnextcloud-server-f47a4a8c158f538d5febedec7282f576360a4d02.tar.gz
nextcloud-server-f47a4a8c158f538d5febedec7282f576360a4d02.zip
add unit test for mail detection
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r--apps/user_ldap/tests/wizard.php138
1 files changed, 137 insertions, 1 deletions
diff --git a/apps/user_ldap/tests/wizard.php b/apps/user_ldap/tests/wizard.php
index fcf4d71087f..d6de83bbdd6 100644
--- a/apps/user_ldap/tests/wizard.php
+++ b/apps/user_ldap/tests/wizard.php
@@ -63,7 +63,7 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase {
$access = $this->getMock('\OCA\user_ldap\lib\Access',
$accMethods, array($connector, $lw, $um));
- return array(new Wizard($conf, $lw, $access), $conf, $lw);
+ return array(new Wizard($conf, $lw, $access), $conf, $lw, $access);
}
private function prepareLdapWrapperForConnections(&$ldap) {
@@ -218,6 +218,142 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase {
unset($uidnumber);
}
+ public function testDetectEmailAttributeAlreadySet() {
+ list($wizard, $configuration, $ldap, $access)
+ = $this->getWizardAndMocks();
+
+ $configuration->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function ($name) {
+ if($name === 'ldapEmailAttribute') {
+ return 'myEmailAttribute';
+ } else {
+ //for requirement checks
+ return 'let me pass';
+ }
+ }));
+
+ $access->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(42));
+
+ $wizard->detectEmailAttribute();
+ }
+
+ public function testDetectEmailAttributeOverrideSet() {
+ list($wizard, $configuration, $ldap, $access)
+ = $this->getWizardAndMocks();
+
+ $configuration->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function ($name) {
+ if($name === 'ldapEmailAttribute') {
+ return 'myEmailAttribute';
+ } else {
+ //for requirement checks
+ return 'let me pass';
+ }
+ }));
+
+ $access->expects($this->exactly(3))
+ ->method('combineFilterWithAnd')
+ ->will($this->returnCallback(function ($filterParts) {
+ return str_replace('=*', '', array_pop($filterParts));
+ }));
+
+ $access->expects($this->exactly(3))
+ ->method('countUsers')
+ ->will($this->returnCallback(function ($filter) {
+ if($filter === 'myEmailAttribute') {
+ return 0;
+ } else if($filter === 'mail') {
+ return 3;
+ } else if($filter === 'mailPrimaryAddress') {
+ return 17;
+ }
+ var_dump($filter);
+ }));
+
+ $resultAttribute = $wizard->detectEmailAttribute();
+ $this->assertSame('mailPrimaryAddress', $resultAttribute);
+ }
+
+ public function testDetectEmailAttributeFind() {
+ list($wizard, $configuration, $ldap, $access)
+ = $this->getWizardAndMocks();
+
+ $configuration->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function ($name) {
+ if($name === 'ldapEmailAttribute') {
+ return '';
+ } else {
+ //for requirement checks
+ return 'let me pass';
+ }
+ }));
+
+ $access->expects($this->exactly(2))
+ ->method('combineFilterWithAnd')
+ ->will($this->returnCallback(function ($filterParts) {
+ return str_replace('=*', '', array_pop($filterParts));
+ }));
+
+ $access->expects($this->exactly(2))
+ ->method('countUsers')
+ ->will($this->returnCallback(function ($filter) {
+ if($filter === 'myEmailAttribute') {
+ return 0;
+ } else if($filter === 'mail') {
+ return 3;
+ } else if($filter === 'mailPrimaryAddress') {
+ return 17;
+ }
+ var_dump($filter);
+ }));
+
+ $resultAttribute = $wizard->detectEmailAttribute();
+ $this->assertSame('mailPrimaryAddress', $resultAttribute);
+ }
+
+ public function testDetectEmailAttributeFindNothing() {
+ list($wizard, $configuration, $ldap, $access)
+ = $this->getWizardAndMocks();
+
+ $configuration->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function ($name) {
+ if($name === 'ldapEmailAttribute') {
+ return 'myEmailAttribute';
+ } else {
+ //for requirement checks
+ return 'let me pass';
+ }
+ }));
+
+ $access->expects($this->exactly(3))
+ ->method('combineFilterWithAnd')
+ ->will($this->returnCallback(function ($filterParts) {
+ return str_replace('=*', '', array_pop($filterParts));
+ }));
+
+ $access->expects($this->exactly(3))
+ ->method('countUsers')
+ ->will($this->returnCallback(function ($filter) {
+ if($filter === 'myEmailAttribute') {
+ return 0;
+ } else if($filter === 'mail') {
+ return 0;
+ } else if($filter === 'mailPrimaryAddress') {
+ return 0;
+ }
+ var_dump($filter);
+ }));
+
+ $resultAttribute = $wizard->detectEmailAttribute();
+ $this->assertSame('', $resultAttribute);
+ }
+
public function testCumulativeSearchOnAttributeSkipReadDN() {
// tests that there is no infinite loop, when skipping already processed
// DNs (they can be returned multiple times for multiple filters )