示例#1
0
 public function testLdapFind()
 {
     $collection = $this->getMock(CollectionInterface::class);
     $collection->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array(new Entry('cn=qux,dc=foo,dc=com', array('dn' => array('cn=qux,dc=foo,dc=com'), 'cn' => array('qux'), 'dc' => array('com', 'foo'), 'givenName' => array('Qux'))), new Entry('cn=baz,dc=foo,dc=com', array('dn' => array('cn=baz,dc=foo,dc=com'), 'cn' => array('baz'), 'dc' => array('com', 'foo'), 'givenName' => array('Baz')))))));
     $query = $this->getMock(QueryInterface::class);
     $query->expects($this->once())->method('execute')->will($this->returnValue($collection));
     $this->ldap->expects($this->once())->method('query')->with('dc=foo,dc=com', 'bar', array('filter' => 'baz'))->willReturn($query);
     $expected = array('count' => 2, 0 => array('count' => 4, 0 => array('count' => 1, 0 => 'cn=qux,dc=foo,dc=com'), 'dn' => array('count' => 1, 0 => 'cn=qux,dc=foo,dc=com'), 1 => array('count' => 1, 0 => 'qux'), 'cn' => array('count' => 1, 0 => 'qux'), 2 => array('count' => 2, 0 => 'com', 1 => 'foo'), 'dc' => array('count' => 2, 0 => 'com', 1 => 'foo'), 3 => array('count' => 1, 0 => 'Qux'), 'givenName' => array('count' => 1, 0 => 'Qux')), 1 => array('count' => 4, 0 => array('count' => 1, 0 => 'cn=baz,dc=foo,dc=com'), 'dn' => array('count' => 1, 0 => 'cn=baz,dc=foo,dc=com'), 1 => array('count' => 1, 0 => 'baz'), 'cn' => array('count' => 1, 0 => 'baz'), 2 => array('count' => 2, 0 => 'com', 1 => 'foo'), 'dc' => array('count' => 2, 0 => 'com', 1 => 'foo'), 3 => array('count' => 1, 0 => 'Baz'), 'givenName' => array('count' => 1, 0 => 'Baz')));
     $this->assertEquals($expected, $this->client->find('dc=foo,dc=com', 'bar', 'baz'));
 }
示例#2
0
 /**
  * @group functional
  * @requires extension ldap
  */
 public function testLdapClientFunctional()
 {
     $config = $this->getLdapConfig();
     $ldap = new LdapClient($config['host'], $config['port']);
     $ldap->bind('cn=admin,dc=symfony,dc=com', 'symfony');
     $result = $ldap->find('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
     $con = @ldap_connect($config['host'], $config['port']);
     @ldap_bind($con, 'cn=admin,dc=symfony,dc=com', 'symfony');
     $search = @ldap_search($con, 'dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array('*'));
     $expected = @ldap_get_entries($con, $search);
     $this->assertSame($expected, $result);
 }
示例#3
0
 public function testLdapEscape()
 {
     $ldap = new LdapClient();
     $this->assertEquals('\\20foo\\3dbar\\0d(baz)*\\20', $ldap->escape(" foo=bar\r(baz)* ", null, p::LDAP_ESCAPE_DN));
 }
示例#4
0
 /**
  * @dataProvider provideLdapEscapeValues
  */
 public function testLdapEscape($subject, $ignore, $flags, $expected)
 {
     $ldap = new LdapClient();
     $this->assertSame($expected, $ldap->escape($subject, $ignore, $flags));
 }