|
13 | 13 |
|
14 | 14 | use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter; |
15 | 15 | use Symfony\Component\Ldap\Adapter\ExtLdap\Collection; |
| 16 | +use Symfony\Component\Ldap\Adapter\ExtLdap\Query; |
16 | 17 | use Symfony\Component\Ldap\Entry; |
17 | 18 | use Symfony\Component\Ldap\LdapInterface; |
18 | 19 |
|
@@ -65,4 +66,37 @@ public function testLdapQueryIterator() |
65 | 66 | $this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn')); |
66 | 67 | $this->assertEquals(array('fabpot@symfony.com', 'fabien@potencier.com'), $entry->getAttribute('mail')); |
67 | 68 | } |
| 69 | + |
| 70 | + public function testLdapQueryScopeBase() |
| 71 | + { |
| 72 | + $ldap = new Adapter($this->getLdapConfig()); |
| 73 | + |
| 74 | + $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); |
| 75 | + |
| 76 | + $query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', array( |
| 77 | + 'scope' => Query::SCOPE_BASE, |
| 78 | + )); |
| 79 | + $result = $query->execute(); |
| 80 | + |
| 81 | + $entry = $result[0]; |
| 82 | + $this->assertEquals($result->count(), 1); |
| 83 | + $this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn')); |
| 84 | + } |
| 85 | + |
| 86 | + public function testLdapQueryScopeOneLevel() |
| 87 | + { |
| 88 | + $ldap = new Adapter($this->getLdapConfig()); |
| 89 | + |
| 90 | + $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); |
| 91 | + |
| 92 | + $one_level_result = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)', array( |
| 93 | + 'scope' => Query::SCOPE_ONE, |
| 94 | + ))->execute(); |
| 95 | + |
| 96 | + $subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count(); |
| 97 | + |
| 98 | + $this->assertNotEquals($one_level_result->count(), $subtree_count); |
| 99 | + $this->assertEquals($one_level_result->count(), 1); |
| 100 | + $this->assertEquals($one_level_result[0]->getAttribute('ou'), array('Ldap')); |
| 101 | + } |
68 | 102 | } |
0 commit comments