Exemple #1
0
 /**
  * Tests node level diff tracking
  *
  * @return void
  */
 public function testNodeLevelDiffTracking()
 {
     $node = new Node();
     $node->setDn('test_dn');
     $attr = new NodeAttribute('attr0');
     $attr->add('value0');
     $node->setAttribute($attr);
     $node->snapshot();
     $attr = new NodeAttribute('attr1');
     $attr->add(array('value1', 'value2'));
     $node->mergeAttribute($attr);
     $attr = new NodeAttribute('attr2');
     $attr->add(array('value3', 'value1'));
     $node->mergeAttribute($attr);
     $attr = new NodeAttribute('attr3');
     $attr->add('value5');
     $node->mergeAttribute($attr);
     $node->removeAttribute('attr0');
     $node->removeAttribute('attr4');
     $this->assertEquals(array('attr1' => array('value1', 'value2'), 'attr2' => array('value3', 'value1'), 'attr3' => array('value5')), $node->getDiffAdditions(), 'Basic node additions tracking works');
     $this->assertEquals(array('attr0' => array()), $node->getDiffDeletions(), 'Basic node deletions tracking works and inexistant attributes are not logged');
     $this->assertEquals(array(), $node->getDiffReplacements(), 'No replacement done at this stage');
     $attr = new NodeAttribute('attr0');
     $attr->add('value6');
     $node->mergeAttribute($attr);
     $node->removeAttribute('attr2');
     $this->assertEquals(array(), $node->getDiffDeletions(), 'attr0 is now replaced and attr2 should no more be an addition');
     $this->assertEquals(array('attr1' => array('value1', 'value2'), 'attr3' => array('value5')), $node->getDiffAdditions(), 'attr2 is not part of additions anymore');
     $this->assertEquals(array('attr0' => array('value6')), $node->getDiffReplacements(), 'attr0 has been marked for replacement');
     $node->snapshot();
     $this->assertEquals(array(), array_merge($node->getDiffDeletions(), $node->getDiffAdditions(), $node->getDiffReplacements()), 'Diff has been reset');
     $attr = new NodeAttribute('attr4');
     $attr->add(array('value7', 'value8', 'value9'));
     $node->setAttribute($attr);
     $attr = new NodeAttribute('attr0');
     $attr->add(array('value6', 'value10'));
     $node->setAttribute($attr);
     $this->assertEquals(array('attr4' => array('value7', 'value8', 'value9'), 'attr0' => array('value6', 'value10')), $node->getDiffReplacements(), 'Replacements enforced for both attributes');
     $this->assertEquals(array(), $node->getDiffDeletions(), 'No new deletion logged');
     $this->assertEquals(array(), $node->getDiffAdditions(), 'No new addition logged');
 }