Author: Chad Sikorra (Chad.Sikorra@gmail.com)
 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);
 }
Ejemplo n.º 2
0
 function it_should_hydrate_a_ldap_object_wihtout_a_schema_with_batch_modification()
 {
     $ldapObject = new LdapObject(['dn' => 'cn=foo,dc=foo,dc=bar'], [], 'user', '');
     $ldapObject->set('givenName', 'Chad');
     $ldapObject->add('sn', 'Sikorra');
     $ldapObject->remove('sAMAccountName', 'csikorra');
     $ldapObject->reset('mail');
     $this->hydrateToLdap($ldapObject)->shouldBeEqualTo($this->batch);
     $this->hydrateToLdap($ldapObject)->shouldHaveCount(4);
 }
Ejemplo n.º 3
0
 /**
  * The DN attribute must be present to perform LDAP operations.
  *
  * @param LdapObject $ldapObject
  */
 protected function validateObject(LdapObject $ldapObject)
 {
     if (!$ldapObject->has('dn')) {
         throw new InvalidArgumentException('To persist/delete/move/restore a LDAP object it must have the DN attribute.');
     }
 }
Ejemplo n.º 4
0
 public function it_should_error_trying_to_do_a_non_set_method_on_many_aggregated_values($connection)
 {
     $ldapObject = new LdapObject(['dn' => 'cn=foo,dc=foo,dc=bar'], [], 'user', 'user');
     $ldapObject->set('disabled', true);
     $ldapObject->add('trustedForAllDelegation', true);
     $batch = $ldapObject->getBatchCollection();
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == '(&(objectClass=*))' && $operation->getBaseDn() == 'cn=foo,dc=foo,dc=bar' && $operation->getAttributes() == ['userAccountControl'];
     }))->willReturn($this->expectedResult);
     $this->beConstructedWith($this->schema, $batch, AttributeConverterInterface::TYPE_MODIFY);
     $this->setLdapConnection($connection);
     $this->setDn('cn=foo,dc=foo,dc=bar');
     $this->shouldThrow(new \LogicException('Unable to modify "trustedForAllDelegation". The "ADD" action is not allowed.'))->duringToLdap();
 }
Ejemplo n.º 5
0
 function it_should_persist_an_ldap_object_that_has_no_schema_type($connection)
 {
     $dn = 'cn=user,dc=foo,dc=bar';
     $ldapObject = new LdapObject(['dn' => $dn]);
     $ldapObject->set('foo', 'bar');
     $batch = new BatchCollection($dn);
     $batch->add(new Batch(Batch::TYPE['REPLACE'], 'foo', 'bar'));
     $connection->execute(new BatchModifyOperation($dn, $batch))->shouldBeCalled();
     $this->persist($ldapObject);
 }
Ejemplo n.º 6
0
 function it_should_delete_a_ldap_object(LdapConnectionInterface $connection)
 {
     $domainConfig = new DomainConfiguration('example.local');
     $connection->getConfig()->willReturn($domainConfig);
     $this->beConstructedWith(new Configuration(), $connection);
     $ldapObject = new LdapObject(['dn' => 'cn=foo,dc=foo,dc=bar'], 'user');
     $operation = new DeleteOperation($ldapObject->get('dn'));
     $connection->execute($operation)->shouldBeCalled();
     $this->delete($ldapObject);
     $operation->addControl((new LdapControl(LdapControlType::SUB_TREE_DELETE))->setCriticality(true));
     $connection->execute($operation)->shouldBeCalled();
     $this->delete($ldapObject, true);
 }
Ejemplo n.º 7
0
 /**
  * Temporary BC method for LdapObject construction.
  * 
  * @todo remove this at some point. This is to check for instances where the class/category was in the constructor.
  * @param LdapObject $ldapObject
  * @return array
  */
 protected function getParentArgs(LdapObject $ldapObject)
 {
     $constructor = (new \ReflectionClass(get_parent_class()))->getConstructor();
     if ($constructor->getNumberOfParameters() == 2) {
         $args = [$ldapObject->toArray(), $ldapObject->getType()];
     } else {
         $args = [$ldapObject->toArray(), [], '', $ldapObject->getType()];
     }
     return $args;
 }