/** * @param \LdapTools\LdapManager $ldap * @param \LdapTools\Query\LdapQueryBuilder $qb * @param \LdapTools\Query\LdapQuery $query * @param \LdapTools\Connection\LdapConnectionInterface $connection */ function let($ldap, $qb, $query, $connection) { $groups = new LdapObjectCollection(); $groups->add(new LdapObject(['name' => 'Foo', 'dn' => 'cn=Foo,dc=example,dc=local'])); $groups->add(new LdapObject(['guid' => '291d8444-9d5b-4b0a-a6d7-853408f704d5', 'dn' => 'cn=Bar,dc=example,dc=local'])); $groups->add(new LdapObject(['sid' => 'S-1-5-18', 'dn' => 'cn=LocalSys,dc=example,dc=local'])); $groups->add(new LdapObject(['name' => 'Just a DN', 'dn' => 'cn=Stuff,dc=example,dc=local'])); $roleMap = ['ROLE_AWESOME' => ['foo'], 'ROLE_ADMIN' => ['291d8444-9d5b-4b0a-a6d7-853408f704d5'], 'ROLE_DN' => ['cn=Stuff,dc=example,dc=local'], 'ROLE_SID' => ['S-1-5-18']]; $attrMap = ['username' => 'username', 'accountNonLocked' => 'locked', 'accountNonExpired' => 'accountExpirationDate', 'enabled' => 'disabled', 'credentialsNonExpired' => 'passwordMustChange', 'guid' => 'guid', 'groups' => 'groups', 'stringRepresentation' => 'username']; $this->ldap = $ldap; $this->qb = $qb; $this->query = $query; $this->connection = $connection; $this->config = new DomainConfiguration('foo.bar'); $this->filter = new ADFilterBuilder(); $this->ldapObject = new LdapObject($this->attr, ['user'], ['user'], 'user'); $query->getSingleResult()->willReturn($this->ldapObject); $query->getResult()->willReturn($groups); $query->getArrayResult()->willReturn([['name' => 'foo'], ['name' => 'bar']]); $qb->from(LdapObjectType::USER)->willReturn($qb); $qb->from('group')->willReturn($qb); $qb->select(["username", "locked", "accountExpirationDate", "disabled", "passwordMustChange", "guid", "groups", "username"])->willReturn($qb); $qb->select(["name", "sid", "guid"])->willReturn($qb); $qb->select('name')->willReturn($qb); $qb->where(['username' => 'foo'])->willReturn($qb); $qb->getLdapQuery()->willReturn($query); $qb->filter()->willReturn($this->filter); $qb->where($this->filter->hasMemberRecursively($this->attr['guid'], 'members'))->willReturn($qb); $this->ldap->buildLdapQuery()->willReturn($qb); $connection->getConfig()->willReturn($this->config); $this->ldap->getConnection()->willReturn($connection); $this->beConstructedWith($ldap, $attrMap, $roleMap, true); }
function it_should_transform_a_ldap_object_collection_to_its_id_values_specified_by_the_annotation($entity, $eventArgs, $reader, $metadata, \ReflectionProperty $rp, LdapObjectCollection $collection, \LdapTools\Object\LdapObject $ldapObject1, \LdapTools\Object\LdapObject $ldapObject2) { $annotation = new LdapObject(); $collection->toArray()->shouldBeCalled()->willReturn([$ldapObject1, $ldapObject2]); $metadata->getReflectionProperties()->shouldBeCalled()->willReturn([$rp]); $reader->getPropertyAnnotation($rp, Argument::any())->shouldBeCalled()->willReturn($annotation); $rp->getValue($entity)->shouldBeCalled()->willReturn($collection); // This is the default attribute value to use... $ldapObject1->get('guid')->shouldBeCalled()->willReturn('foo'); $ldapObject2->get('guid')->shouldBeCalled()->willReturn('bar'); $rp->setValue($entity, ['foo', 'bar'])->shouldBeCalled(); $this->prePersist($eventArgs); }
function it_should_sort_case_sensitive_if_specified() { $results = $this->toSortUtf8; array_push($results, ['name' => 'mike']); array_unshift($results, ['name' => 'mIkE']); array_push($results, ['name' => 'MikE']); $this->collection = new LdapObjectCollection(); foreach ($results as $sort) { $this->collection->add(new LdapObject($sort, 'user')); } $this->beConstructedWith(['name' => 'ASC']); $arrayResult = [['name' => "Ädam"], ['name' => "Böb"], ['name' => "mike"], ['name' => "mIkE"], ['name' => "Mike"], ['name' => "MikE"], ['name' => "Müller"], ['name' => "Tim"]]; $objectResult = new LdapObjectCollection(); foreach ($arrayResult as $entry) { $objectResult->add(new LdapObject($entry, 'user')); } $this->setIsCaseSensitive(true)->shouldReturnAnInstanceOf('LdapTools\\Query\\LdapResultSorter'); $this->sort($results)->shouldBeEqualTo($arrayResult); $this->sort($this->collection)->shouldBeLike($objectResult); }
function it_should_load_values_for_choices($qb, $query) { $collection = new LdapObjectCollection(new LdapObject(['name' => 'foo', 'guid' => '123'], ['user'], 'user', 'user'), new LdapObject(['name' => 'bar', 'guid' => '456'], ['user'], 'user', 'user')); $this->loadValuesForChoices($collection->toArray())->shouldBeEqualTo(['123', '456']); $qb->select(['guid', 'name'])->shouldBeCalled()->willReturn($qb); $qb->from("user")->shouldBeCalled()->willReturn($qb); $collection = new LdapObjectCollection(new LdapObject(['name' => 'foo', 'guid' => '123'], ['user'], 'user', 'user'), new LdapObject(['name' => 'bar', 'guid' => '456'], ['user'], 'user', 'user')); $query->getResult()->shouldBeCalled()->willReturn($collection); $this->loadChoiceList(); $this->loadValuesForChoices($collection->toArray())->shouldBeEqualTo(['123', '456']); }