Пример #1
0
 /**
  * Tests rebasing a node changes on an existing node
  *
  * @return void
  */
 public function testRebaseDiff()
 {
     $rebasedNode = new Node();
     $rebasedNode->setDn('rebased');
     $rebasedNode->get('a', true)->add(array('a2', 'a4'));
     $rebasedNode->get('b', true)->add(array('b1', 'b3'));
     $rebasedNode->get('c', true)->add(array('c1', 'c3'));
     $rebasedNode->get('d', true)->add(array('d1', 'd2', 'd3', 'd4'));
     $rebasedNode->get('g', true)->add('g1');
     $rebasedNode->get('h', true)->add(array('h1', 'h2'));
     $rebasedNode->get('i', true)->add(array('i1', 'i2'));
     $rebasedNode->snapshot();
     $rebasedNode->get('a')->add(array('a1', 'a3'));
     $rebasedNode->removeAttribute('b');
     $rebasedNode->get('c')->set(array('c4', 'c5'));
     $rebasedNode->get('d')->remove('d2');
     $rebasedNode->get('d')->remove('d3');
     $rebasedNode->get('d')->add('d5');
     $rebasedNode->get('f', true)->add(array('f1', 'f2'));
     $rebasedNode->removeAttribute('g');
     $rebasedNode->get('h')->set(array('h1', 'h3'));
     $rebasedNode->get('i')->remove('i2');
     $this->assertEquals(array('a' => array('a2', 'a4', 'a1', 'a3'), 'c' => array('c4', 'c5'), 'd' => array(0 => 'd1', 3 => 'd4', 4 => 'd5'), 'f' => array('f1', 'f2'), 'h' => array('h1', 'h3'), 'i' => array('i1')), $rebasedNode->getRawAttributes(), 'All attributes according to plan');
     $this->assertEquals(array('a' => array('a1', 'a3'), 'd' => array('d5'), 'f' => array('f1', 'f2')), $rebasedNode->getDiffAdditions(), 'Regular additions tracking');
     $this->assertEquals(array('b' => array(), 'd' => array('d2', 'd3'), 'g' => array(), 'i' => array('i2')), $rebasedNode->getDiffDeletions(), 'Regular deletions tracking');
     $this->assertEquals(array('c' => array('c4', 'c5'), 'h' => array('h1', 'h3')), $rebasedNode->getDiffReplacements(), 'Regular replacements tracking');
     $origNode = new Node();
     $origNode->setDn('origin');
     $origNode->get('a', true)->add(array('a1', 'a2'));
     $origNode->get('b', true)->add(array('b1', 'b2'));
     $origNode->get('c', true)->add(array('c1', 'c2'));
     $origNode->get('d', true)->add(array('d1', 'd2'));
     $origNode->get('e', true)->add(array('e1', 'e2'));
     try {
         $rebasedNode->rebaseDiff($origNode);
         $this->fail('Cannot rebase on a node which is not snapshot');
     } catch (RebaseException $e) {
         $this->assertRegExp('/origin has some uncommitted changes - Cannot rebase rebased on origin/', $e->getMessage());
     }
     $this->assertEquals(array('a' => array('a2', 'a4', 'a1', 'a3'), 'c' => array('c4', 'c5'), 'd' => array(0 => 'd1', 3 => 'd4', 4 => 'd5'), 'f' => array('f1', 'f2'), 'h' => array('h1', 'h3'), 'i' => array('i1')), $rebasedNode->getRawAttributes(), 'Rebased node values are unchanged');
     $origNode->snapshot();
     $backupNode = clone $origNode;
     $rebasedNode->rebaseDiff($origNode);
     $this->assertEquals(array('a' => array('a1', 'a2', 'a3'), 'c' => array('c4', 'c5'), 'd' => array(0 => 'd1', 2 => 'd5'), 'e' => array('e1', 'e2'), 'f' => array('f1', 'f2'), 'h' => array('h1', 'h3')), $rebasedNode->getRawAttributes(), 'Rebased diff got applied on origin node values');
     $this->assertEquals(array('a' => array('a3'), 'd' => array('d5'), 'f' => array('f1', 'f2'), 'h' => array('h1', 'h3')), $rebasedNode->getDiffAdditions(), 'A new additions diff has been computed (h did not exist in origin node so it is added)');
     $this->assertEquals(array('b' => array(), 'd' => array('d2')), $rebasedNode->getDiffDeletions(), 'g and i deletions got ignored in the new deletion diff as they were not set on origin');
     $this->assertEquals(array('c' => array('c4', 'c5')), $rebasedNode->getDiffReplacements(), 'h replacement was computed as an addition on origin node');
 }
Пример #2
0
 /**
  * _newNode($node).
  */
 protected function _newNode($dn = false)
 {
     try {
         if (!$this->tiesaManagerClass) {
             $this->_autentication();
         }
         $node = $this->_getNode($dn);
         if ($node) {
             $node->tracker->markOverridden();
             return $node;
         } else {
             $node = new Core\Node();
             $node->setDn($dn);
             $node->tracker->markOverridden();
             return $node;
         }
     } catch (\Exception $e) {
         $this->ldapError = $e;
         return false;
     }
 }
Пример #3
0
 /**
  * Tests complex updates with changeset merging when saving
  *
  * @return void
  */
 public function testSaveMergesChanges()
 {
     $manager = new Manager($this->minimal, $this->driver);
     $manager->connect();
     $manager->bind();
     $entry = new Entry('test_dn', array('a' => array('a1', 'a2'), 'b' => array('b1', 'b2'), 'c' => array('c1', 'c2'), 'd' => array('d1', 'd2'), 'e' => array('e1', 'e2')));
     $this->driver->getConnection()->stackResults(array($entry));
     $node = new Node();
     $node->setDn('test_dn');
     $node->get('a', true)->add(array('a2', 'a4'));
     $node->get('b', true)->add(array('b1', 'b3'));
     $node->get('c', true)->add(array('c1', 'c3'));
     $node->get('d', true)->add(array('d1', 'd2', 'd3', 'd4'));
     $node->get('g', true)->add('g1');
     $node->get('h', true)->add(array('h1', 'h2'));
     $node->get('i', true)->add(array('i1', 'i2'));
     $node->snapshot(false);
     $node->get('a')->add(array('a1', 'a3'));
     $node->removeAttribute('b');
     $node->get('c')->set(array('c4', 'c5'));
     $node->get('d')->remove('d2');
     $node->get('d')->remove('d3');
     $node->get('d')->add('d5');
     $node->get('f', true)->add(array('f1', 'f2'));
     $node->removeAttribute('g');
     $node->get('h')->set(array('h1', 'h3'));
     $node->get('i')->remove('i2');
     $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', array('a' => array('a3'), 'd' => array('d5'), 'f' => array('f1', 'f2'), 'h' => array('h1', 'h3')));
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_del', 'test_dn', array('b' => array(), 'd' => array('d2')));
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'attr_rep', 'test_dn', array('c' => array('c4', 'c5')));
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'All logs have been parsed');
     $this->assertSnapshot($node, 'A node is snapshot after update');
 }
Пример #4
0
 /**
  * Retrieve children Ldap nodes
  *
  * @return void
  */
 public function testGetChildren()
 {
     $manager = new Manager($this->minimal, $this->driver);
     $node = new Node();
     $node->setDn('test_node');
     $set = array();
     $set[] = new Entry('ent1', array('val1'));
     $set[] = new Entry('ent2', array('val2'));
     $set[] = new Entry('ent3', array('val3'));
     // Binding exception handling
     $this->assertBindingFirst($manager, 'getChildrenNodes', array($node));
     $manager->connect();
     $this->assertBindingFirst($manager, 'getChildrenNodes', array($node));
     $manager->bind();
     // Basic behaviour
     $this->driver->getConnection()->stackResults($set);
     $nodes = $manager->getChildrenNodes($node);
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'test_node', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $set);
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'No other log');
     $this->assertTrue(is_array($nodes), 'An array of nodes is retrieved');
     $this->assertCount(3, $nodes);
     $this->assertEquals('ent1', $nodes[0]->getDn());
     $this->assertEquals('ent2', $nodes[1]->getDn());
     $this->assertEquals('ent3', $nodes[2]->getDn());
     // Successful search with no entry in the result set
     $nodes = $manager->getChildrenNodes($node);
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'test_node', '(objectclass=*)', SearchInterface::SCOPE_ONE);
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'No other log');
     $this->assertTrue(is_array($nodes), 'An array of nodes is retrieved');
     $this->assertCount(0, $nodes);
     // Handling of NoResultException
     $this->driver->getConnection()->setFailure(Connection::ERR_NO_RESULT);
     $nodes = $manager->getChildrenNodes($node);
     $this->assertTrue(is_array($nodes), 'An array of nodes is retrieved');
     $this->assertCount(0, $nodes);
     // Handling of other search exceptions
     $this->driver->getConnection()->setFailure();
     try {
         $nodes = $manager->getChildrenNodes($node);
         $this->fail('Other search exceptions do not get processed and are populated');
     } catch (SearchException $e) {
         $this->assertRegExp('/Search failed/', $e->getMessage());
     }
 }
Пример #5
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;
 }