Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$runner->addTestsFromDirectory(__DIR__ . '/tests/SlapOM');
9 changes: 9 additions & 0 deletions .bootstrap.atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$ini = parse_ini_file(dirname(__FILE__) . '/tests/config/config.ini');
@define('LDAP_HOST', $ini['host']);
@define('LDAP_PORT', $ini['port']);
@define('LDAP_BIND_DN', $ini['bindDn']);
@define('LDAP_PASSWORD', $ini['password']);

require_once __DIR__ . '/vendor/autoload.php';
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/composer.lock
/nbproject
/tests/config/config.ini
/vendor
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: php
sudo: false

addons:
apt:
packages:
- ldap-utils
- slapd

install:
- composer install

before_script:
- test -e /tmp/slapd || mkdir /tmp/slapd
- slapd -f tests/config/ldap.conf -h ldap://localhost:3389 &
- sleep 3
- ldapadd -h localhost:3389 -D cn=admin,dc=example,dc=com -w test -f tests/fixtures/ldap_datas.ldif > /dev/null
- ln -sf config.ini.dist tests/config/config.ini

script: ./vendor/bin/atoum

after_script:
- kill -9 $(cat /tmp/slapd/slapd.pid)
- rm -r /tmp/slapd
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"php": ">=5.3.0",
"ext-ldap": "*"
},
"require-dev": {
"atoum/atoum": "~2.0"
},
"autoload": {
"psr-0": { "SlapOM": "lib/" }
}
Expand Down
60 changes: 28 additions & 32 deletions tests/SlapOM/Tests/Units/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

namespace SlapOM\Tests\Units;

include __DIR__ . '/../../../bootstrap/autoload.php';

require_once __DIR__ . '/../../../../../mageekguy.atoum.phar';

use \mageekguy\atoum;

class Connection extends atoum\test
class Connection extends \atoum
{

public function testGetMapFor()
{
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD);
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD, LDAP_PORT);

$userMap = $connection->getMapFor('SlapOM\Tests\Units\UserForTest1');

Expand Down Expand Up @@ -47,68 +41,70 @@ public function testGetMapFor()

public function testSearch()
{
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD);
$result = $connection->search('dc=knplabs,dc=com', '(objectClass=person)', array('cn'));
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD, LDAP_PORT);
$userMap = $connection->getMapFor('SlapOM\Tests\Units\UserForTest1');
$result = $connection->search($userMap, 'dc=example,dc=com', '(objectClass=person)', array('cn'));
$this->assert
->array($result)
->hasSize(2001);
->integer(count($result))
->isEqualTo(2000);

$connection = new \SlapOM\Connection('fakeHost', LDAP_BIND_DN, LDAP_PASSWORD);

$this->assert
->exception(function() use ($connection) {
$connection->search('dc=knplabs,dc=com', '(objectClass=person)', array('cn'));
->exception(function() use ($connection, $userMap) {
$connection->search($userMap, 'dc=example,dc=com', '(objectClass=person)', array('cn'));
})
->isInstanceOf('\SlapOM\Exception\Ldap')
->hasMessage('ERROR Could not bind to LDAP host=\'fakeHost:389\' with login=\'cn=root\'.. LDAP ERROR (-1) -- Can\'t contact LDAP server --. Can\'t contact LDAP server');
->hasMessage('ERROR Could not bind to LDAP host=\'fakeHost:389\' with login=\'cn=admin,dc=example,dc=com\'.. LDAP ERROR (-1) -- Can\'t contact LDAP server --. Can\'t contact LDAP server');


$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD);
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD, LDAP_PORT);

$this->assert
->exception(function() use ($connection) {
$connection->search('dc=knplabs,dc=com', '(&=test)', array('cn'));
->exception(function() use ($connection, $userMap) {
$connection->search($userMap, 'dc=example,dc=com', '(&=test)', array('cn'));
})
->isInstanceOf('\SlapOM\Exception\Ldap')
->hasMessage('ERROR Error while filtering dn \'dc=knplabs,dc=com\' with filter \'(&=test)\'.. LDAP ERROR (-7) -- Bad search filter --. Bad search filter');
->hasMessage('ERROR Error while filtering dn \'dc=example,dc=com\' with filter \'(&=test)\'.. LDAP ERROR (-7) -- Bad search filter --. Bad search filter');
}

public function testModify()
{
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD);
$dn = 'uid=user.1999,ou=People,dc=example,dc=com';

$result = $connection->modify('uid=user.1999,ou=People,dc=knplabs,dc=com', array('mail' => 'newMail@plop.com'));
$connection = new \SlapOM\Connection(LDAP_HOST, LDAP_BIND_DN, LDAP_PASSWORD, LDAP_PORT);

$result = $connection->modify($dn, array('mail' => 'newMail@plop.com'));

$this->assert
->boolean($result)
->isTrue();

$result = $connection->modify('uid=user.1999,ou=People,dc=knplabs,dc=com', array('mail' => array('newMail1@plop.com', 'newMail2@plop.com', 'newMail3@plop.com')));
$result = $connection->modify($dn, array('mail' => array('newMail1@plop.com', 'newMail2@plop.com', 'newMail3@plop.com')));

$this->assert
->boolean($result)
->isTrue();

$this->assert
->exception(function() use ($connection) {
$connection->modify('uid=user.1999,ou=People,dc=knplabs,dc=com', array('objectclass' => 'protectedObjectClass'));
->exception(function() use ($connection, $dn) {
$connection->modify($dn, array('objectClass' => 'protectedObjectClass'));
})
->isInstanceOf('\SlapOM\Exception\Ldap')
->hasMessage('ERROR Error while modifying dn \'uid=user.1999,ou=People,dc=knplabs,dc=com\'.. LDAP ERROR (65) -- Object class violation --. Object class violation');
->isInstanceOf('\SlapOM\Exception\Ldap');

$this->assert
->exception(function() use ($connection) {
$connection->modify('uid=user.1999,ou=People,dc=knplabs,dc=com', array('l' => null));
->exception(function() use ($connection, $dn) {
$connection->modify($dn, array('objectClass' => null));
})
->isInstanceOf('\SlapOM\Exception\Ldap')
->hasMessage('ERROR Error while modifying dn \'uid=user.1999,ou=People,dc=knplabs,dc=com\'.. LDAP ERROR (21) -- Invalid syntax --. Invalid syntax');
->hasMessage("ERROR Error while DELETING attributes {objectClass} in dn='$dn'.. LDAP ERROR (65) -- Object class violation --. Object class violation");
}

}

class UserForTest1 extends \SlapOM\Entity
{

}

class UserForTest1Map extends \SlapOM\EntityMap
Expand All @@ -118,10 +114,10 @@ class UserForTest1Map extends \SlapOM\EntityMap

protected function configure()
{
$this->base_dn = 'dc=knplabs,dc=com';
$this->base_dn = 'dc=example,dc=com';
$this->ldap_object_class = 'person';
$this->entity_class = 'SlapOM\Tests\Units\UserForTest1';
$this->addAttribute('cn');
}

}
}
20 changes: 7 additions & 13 deletions tests/SlapOM/Tests/Units/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

namespace SlapOM\Tests\Units;

include __DIR__ . '/../../../bootstrap/autoload.php';

require_once __DIR__ . '/../../../../../mageekguy.atoum.phar';

use \mageekguy\atoum;

class Entity extends atoum\test
class Entity extends \atoum
{

public function test_getState()
Expand Down Expand Up @@ -69,15 +63,15 @@ public function testIsModified()
$this->assert
->boolean($user->isModified())
->isTrue();

$user = new UserForTest2();

$this->assert
->boolean($user->isModified())
->isFalse();

$user->setWhatever(true);

$this->assert
->boolean($user->isModified())
->isTrue();
Expand Down Expand Up @@ -185,5 +179,5 @@ public function test_call()

class UserForTest2 extends \SlapOM\Entity
{
}

}
Loading