Exemple #1
0
 /**
  * Tests retrieving raw node attributes for Ldap persistence
  *
  * @return void
  */
 public function testGetRawAttributes()
 {
     $node = new Node();
     $this->assertEquals(array(), $node->getRawAttributes(), 'No attributes set so an empty array is retrieved');
     $node->mergeAttribute(new NodeAttribute('attr1'));
     $attr = new NodeAttribute('attr2');
     $attr->add(array('value1', 'value2'));
     $node->mergeAttribute($attr);
     $attr = new NodeAttribute('attr3');
     $attr->add('value3');
     $node->mergeAttribute($attr);
     $this->assertEquals(array('attr1' => array(), 'attr2' => array('value1', 'value2'), 'attr3' => array('value3')), $node->getRawAttributes(), 'All combinations are parsed correctly');
 }
Exemple #2
0
 /**
  * Tests attributes diff tracking
  *
  * @return void
  */
 public function testDiffTracking()
 {
     $test = new NodeAttribute('test');
     $test->add(array('value4', 'value5'));
     $test->snapshot();
     $test->add(array('value1', 'value2', 'value3'));
     $test->remove(array('value4', 'value1', 'value5'));
     $test[] = 'value6';
     $test[] = 'value4';
     $test[] = 'value7';
     unset($test[5]);
     //value6
     $this->assertEquals(array('value2', 'value3', 'value7'), $test->getDiffAdditions(), 'Additions have been tracked');
     $this->assertEquals(array('value5'), $test->getDiffDeletions(), 'Deletions have been tracked');
     $this->assertEquals(array('value4'), $test->getDiffReplacements(), 'Replacements have been tracked');
     $test->snapshot();
     $this->assertEquals(array(), $test->getDiffAdditions(), 'Diff tracking has been reset');
     $this->assertEquals(array(), $test->getDiffDeletions(), 'Diff tracking has been reset');
     $this->assertEquals(array(), $test->getDiffReplacements(), 'Diff tracking has been reset');
 }
Exemple #3
0
 /**
  * Merges an attribute in the node store (add if it is new)
  *
  * @param NodeAttribute $attribute Attribute to be added
  *
  * @return void
  */
 public function mergeAttribute(NodeAttribute $attribute)
 {
     if (!$this->has($attribute->getName())) {
         $this->attributes[$attribute->getName()] = $attribute;
         $this->tracker->logAddition($attribute->getName());
         return;
     }
     $backup = $attribute;
     $attribute = $this->get($attribute->getName());
     $attribute->add($backup->getValues());
     $this->attributes[$attribute->getName()] = $attribute;
 }
Exemple #4
0
 /**
  * Tests saving existing nodes to the Ldap
  *
  * @return void
  */
 public function testSaveExistingNodes()
 {
     $manager = new Manager($this->minimal, $this->driver);
     $manager->connect();
     $manager->bind();
     // Basic node update with search first
     $data = array('attr1' => array('value1'), 'attr2' => array('value1', 'value2'), 'attr3' => array('value3'));
     $node = $this->buildNode('test_dn', $data);
     $entry = new Entry('test_dn', array('attr' => array('value2')));
     $this->driver->getConnection()->stackResults(array($entry));
     $this->assertFalse($manager->save($node), 'Node persistence resulted in an update');
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'test_dn', '(objectclass=*)', SearchInterface::SCOPE_BASE, null, array($entry));
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_add', 'test_dn', $data);
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'No other log');
     $this->assertSnapshot($node, 'A node is snapshot after update');
     try {
         $node->setDn('other');
         $this->fail('Saving is like hydrating and so dn should be locked');
     } catch (\InvalidArgumentException $e) {
         $this->assertRegExp('/Dn cannot be updated manually/', $e->getMessage());
     }
     // Node updated again without underlying search
     $node->removeAttribute('attr1');
     $node->get('attr2')->add('value4');
     $node->get('attr2')->remove('value1');
     $this->assertFalse($manager->save($node), 'Node has been marked hydrated so it is always an update - No need to feed a new entry');
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_add', 'test_dn', array('attr2' => array('value4')));
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_del', 'test_dn', array('attr1' => array(), 'attr2' => array('value1')));
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'No search performed, node was already hydrated');
     $this->assertSnapshot($node, 'A node is snapshot after update');
     // Support for all kinds of attributes manipulation
     $node->removeAttribute('attr2');
     $attr = new NodeAttribute('attr2');
     $attr->add(array('new1', 'new2'));
     $node->mergeAttribute($attr);
     $node->get('attr3')->add('new3');
     $node->get('attr3')->remove('value3');
     $this->assertFalse($manager->save($node), 'Node got updated');
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_add', 'test_dn', array('attr3' => array('new3')));
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_del', 'test_dn', array('attr3' => array('value3')));
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_rep', 'test_dn', array('attr2' => array('new1', 'new2')));
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'No search performed, node was already hydrated');
     $this->assertSnapshot($node, 'A node is snapshot after update');
 }
Exemple #5
0
 /**
  * Shows that case sensitivity switch correctly returns attributes
  */
 public function testCaseSensitivity()
 {
     $test = new NodeAttribute('Test', null, true);
     $this->assertEquals('Test', $test->getName());
     // default is no sensitivity
     $test = new NodeAttribute('Test', null);
     $this->assertEquals('test', $test->getName());
 }
Exemple #6
0
 /**
  * Node factory
  *
  * @param string $dn         Distinguished name for the node
  * @param array  $attributes Array of attributes
  *
  * @return Node node
  */
 protected function buildNode($dn, $attributes)
 {
     $node = new Node();
     $node->setDn($dn);
     foreach ($attributes as $name => $data) {
         $attr = new NodeAttribute($name);
         $attr->add($data);
         $node->mergeAttribute($attr);
     }
     return $node;
 }