/** * Tests removing attribute * * @return void */ public function testRemoveAttribute() { $node = new Node(); $node->setDn('test_dn'); $attr = new NodeAttribute('attr1'); $attr->add(array('value1', 'value2')); $node->setAttribute($attr); $attr = new NodeAttribute('attr2'); $attr->add(array('value3', 'value1')); $node->setAttribute($attr); $attr = new NodeAttribute('attr3'); $attr->add(array('value5')); $node->setAttribute($attr); $this->assertTrue($node->removeAttribute('attr2')); $attributes = $node->getAttributes(); $this->assertArrayHasKey('attr1', $attributes); $this->assertArrayHasKey('attr3', $attributes); $this->assertEquals(2, count($attributes), 'attr2 has been removed'); $this->assertFalse($node->removeAttribute('invalid')); $this->assertEquals(2, count($attributes), 'No change in attributes'); }
/** * Rebase diff based on source node as an origin * * @param Node $node Node to use as a source for origin * * @return void * * @throws RebaseException If source of origin node has uncommitted changes */ public function rebaseDiff(Node $node) { $changes = array_merge($node->getDiffAdditions(), $node->getDiffDeletions(), $node->getDiffReplacements()); if (count($changes) > 0) { throw new RebaseException(sprintf('%s has some uncommitted changes - Cannot rebase %s on %s', $node->getDn(), $this->getDn(), $node->getDn())); } $additions = $this->getDiffAdditions(); $deletions = $this->getDiffDeletions(); $replacements = $this->getDiffReplacements(); $this->snapshot(); $this->attributes = $node->getAttributes(); foreach ($additions as $attribute => $values) { $this->get($attribute, true)->add($values); } foreach ($deletions as $attribute => $values) { if (count($values) == 0) { $this->removeAttribute($attribute); continue; } if ($this->has($attribute)) { $this->get($attribute)->remove($values); } } foreach ($replacements as $attribute => $values) { $this->get($attribute, true)->set($values); } }