Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
added ignore children testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Apr 19, 2017
1 parent ed6bacb commit 0b55bf6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Subscriber/Behavior/VersionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private function restoreNode(
);
}

// remove child-nodes which does not exists in frozen-node
// remove child-nodes which do not exists in frozen-node
foreach ($node->getNodes() as $childNode) {
if ($childNode->getDefinition()->getOnParentVersion() !== OnParentVersionAction::COPY
|| $frozenNode->hasNode($childNode->getName())
Expand Down
48 changes: 48 additions & 0 deletions tests/Unit/Subscriber/Behavior/VersionSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,52 @@ function () use ($node, $newChild1Node, $newChild2Node, $newChild3Node) {

$this->versionSubscriber->restoreProperties($event->reveal());
}

public function testRestoreIgnoreChildren()
{
$event = $this->prophesize(RestoreEvent::class);
$document = $this->prophesize(VersionBehavior::class);
$node = $this->prophesize(NodeInterface::class);
$versionHistory = $this->prophesize(VersionHistoryInterface::class);
$version = $this->prophesize(JackalopeVersion::class);
$frozenNode = $this->prophesize(NodeInterface::class);

$node->getPath()->willReturn('/node');
$node->getProperties()->willReturn([]);
$node->hasNode('child')->willReturn(true);

$definition = $this->prophesize(NodeDefinitionInterface::class);
$definition->getOnParentVersion()->willReturn(OnParentVersionAction::IGNORE);

$childNode = $this->prophesize(NodeInterface::class);
$childNode->getName()->willReturn('child');
$childNode->getProperties()->willReturn([]);
$childNode->getNodes()->willReturn([]);
$childNode->getDefinition()->willReturn($definition->reveal());

$node->getNode('child')->willReturn($childNode->reveal());
$node->getNodes()->willReturn([$childNode->reveal()]);

$this->propertyEncoder->localizedContentName('', 'de')->willReturn('i18n:de-');
$this->propertyEncoder->localizedSystemName('', 'de')->willReturn('i18n:de-');

$frozenNode->getNodes()->willReturn([]);
$frozenNode->getPropertiesValues()->willReturn([]);
$frozenNode->hasNode(Argument::type('string'))->willReturn(false);

$event->getDocument()->willReturn($document->reveal());
$event->getNode()->willReturn($node->reveal());
$event->getVersion()->willReturn('1.0');
$event->getLocale()->willReturn('de');

$this->versionManager->getVersionHistory('/node')->willReturn($versionHistory->reveal());
$versionHistory->getVersion('1.0')->willReturn($version->reveal());
$version->getFrozenNode()->willReturn($frozenNode->reveal());

// the child-node should not be touched
$childNode->remove()->shouldNotBeCalled();
$childNode->setProperty(Argument::cetera())->shouldNotBeCalled();

$this->versionSubscriber->restoreProperties($event->reveal());
}
}

0 comments on commit 0b55bf6

Please sign in to comment.