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); }
/** * It's possible a new location was not explicitly given and the attribute that contains the last know location * was not queried for when the object was originally found. In that case attempt to retrieve the last known * location from a separate LDAP query. * * @param LdapObject $ldapObject * @param string|null $location * @return string */ protected function getObjectRestoreLocation(LdapObject $ldapObject, $location) { // If a location was defined, use that. if ($location) { $newLocation = $location; // Check the attribute for the last known location first... } elseif ($ldapObject->has('lastKnownLocation')) { $newLocation = $ldapObject->get('lastKnownLocation'); // All else failed, so query it from the DN... } else { try { $newLocation = (new LdapQueryBuilder($this->connection, $this->schemaFactory))->select('lastKnownParent')->from(LdapObjectType::DELETED)->where(['dn' => $ldapObject->get('dn')])->getLdapQuery()->getSingleScalarOrNullResult(); } catch (Exception $e) { $newLocation = null; } } // Either this was not a deleted object or it no longer exists? if (is_null($newLocation)) { throw new InvalidArgumentException(sprintf('No restore location specified and cannot find the last known location for "%s".', $ldapObject->get('dn'))); } return $newLocation; }
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); }