Автор: Chad Sikorra (Chad.Sikorra@gmail.com)
Наследование: implements IteratorAggregate
Пример #1
0
 function it_should_hydrate_a_modify_operation_to_ldap($connection)
 {
     $this->setLdapObjectSchema($this->schema);
     $this->setOperationType(AttributeConverterInterface::TYPE_CREATE);
     $this->setLdapConnection($connection);
     $dn = 'cn=foo,dc=example,dc=local';
     $batches = new BatchCollection($dn);
     $batches->add(new Batch(Batch::TYPE['REPLACE'], 'username', 'foobar'));
     $batches->add(new Batch(Batch::TYPE['REMOVE'], 'password', 'bar'));
     $expected = [['attrib' => "sAMAccountName", 'modtype' => 3, 'values' => [0 => "foobar"]], ['attrib' => "unicodePwd", 'modtype' => 2, 'values' => [0 => (new EncodeWindowsPassword())->toLdap('bar')]]];
     $operation = new BatchModifyOperation($dn, $batches);
     $this->hydrateToLdap($operation)->getBatchCollection()->getBatchArray()->shouldBeEqualTo($expected);
 }
 /**
  * Add the correct operation for the action as a post operation to the current operation.
  *
  * @param string $dn
  * @param int $batchType
  * @throws \LdapTools\Exception\AttributeConverterException
  */
 protected function addOperation($dn, $batchType)
 {
     $collection = new BatchCollection($dn);
     $valueDn = $this->getDn();
     // The DN is unknown in the case of an add, as value/parameter resolution most occur first. If there is a better
     // way to do this I'm not sure what it would be. The batch will resolve closures when producing an array to ldap.
     if ($this->getOperationType() == AttributeConverterInterface::TYPE_CREATE) {
         /** @var AddOperation $parentOp */
         $parentOp = $this->getOperation();
         $valueDn = function () use($parentOp) {
             return $parentOp->getDn();
         };
     }
     $collection->add(new Batch($batchType, $this->getOptionsArray()['to_attribute'], $valueDn));
     $operation = new BatchModifyOperation($dn, $collection);
     $this->operation->addPostOperation($operation);
 }
 function it_should_remove_batches_when_specified_by_a_converter_implementing_OperationGeneratorInterface($connection)
 {
     $dn = 'cn=Chad,dc=foo,dc=bar';
     $batch = new BatchCollection($dn);
     $operation = new BatchModifyOperation($dn);
     $batch->add(new Batch(Batch::TYPE['ADD'], 'groups', ['cn=foo,dc=example,dc=local', 'cn=bar,dc=foo,dc=bar']));
     $batch->add(new Batch(Batch::TYPE['REMOVE'], 'groups', ['cn=foo,dc=example,dc=local', 'cn=foobar,dc=foo,dc=bar']));
     $this->beConstructedWith($this->schema, $batch, AttributeConverterInterface::TYPE_MODIFY);
     $this->setLdapConnection($connection);
     $this->setDn($dn);
     $this->setOperation($operation);
     $this->toLdap()->toArray()->shouldHaveCount(0);
 }
Пример #4
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);
 }
 function it_should_clone_the_batch_collection()
 {
     $batch = new Batch(Batch::TYPE['ADD'], 'foo', 'bar');
     $batches = new BatchCollection();
     $batches->add($batch);
     $operation = new BatchModifyOperation('foo', $batches);
     $new = clone $operation;
     $batch->setAttribute('foobar');
     $this->setBatchCollection($new->getBatchCollection());
     $this->getBatchCollection()->get(0)->getAttribute()->shouldNotBeEqualTo('foobar');
 }
Пример #6
0
 /**
  * Reset a specific attribute. This removes any value(s) it might have.
  *
  * @param string $attribute
  * @return $this
  */
 public function reset($attribute)
 {
     $this->batches->add(new Batch(Batch::TYPE['REMOVE_ALL'], $attribute));
     return $this;
 }
Пример #7
0
 function it_should_clone_the_batch_objects_when_cloning_the_collection()
 {
     $batch = new Batch(Batch::TYPE['ADD'], 'foo');
     $batches = new BatchCollection();
     $batches->add($batch);
     $new = clone $batches;
     $batch->setAttribute('foobar');
     $this->add($new->get(0));
     $this->get(0)->getAttribute()->shouldBeEqualTo('foo');
 }