This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Added recursive restore to allow also versions of children #108
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
use Jackalope\Version\Version as JackalopeVersion; | ||
use Jackalope\Workspace; | ||
use PHPCR\NodeInterface; | ||
use PHPCR\NodeType\NodeDefinitionInterface; | ||
use PHPCR\PropertyInterface; | ||
use PHPCR\SessionInterface; | ||
use PHPCR\Version\OnParentVersionAction; | ||
use PHPCR\Version\VersionHistoryInterface; | ||
use PHPCR\Version\VersionInterface; | ||
use PHPCR\Version\VersionManagerInterface; | ||
|
@@ -343,6 +345,7 @@ public function testRestoreLocalizedProperties() | |
$property3 = $this->prophesize(PropertyInterface::class); | ||
$property3->getName()->willReturn('jcr:uuid'); | ||
$node->getProperties()->willReturn([$property1->reveal(), $property2->reveal(), $property3->reveal()]); | ||
$node->getNodes()->willReturn([]); | ||
|
||
$property1->remove()->shouldBeCalled(); | ||
$property2->remove()->shouldBeCalled(); | ||
|
@@ -351,6 +354,7 @@ public function testRestoreLocalizedProperties() | |
$this->propertyEncoder->localizedContentName('', 'de')->willReturn('i18n:de-'); | ||
$this->propertyEncoder->localizedSystemName('', 'de')->willReturn('i18n:de-'); | ||
|
||
$frozenNode->getNodes()->willReturn([]); | ||
$frozenNode->getPropertiesValues()->willReturn([ | ||
'i18n:de-test' => 'Title', | ||
'non-translatable-test' => 'Article', | ||
|
@@ -372,4 +376,133 @@ public function testRestoreLocalizedProperties() | |
|
||
$this->versionSubscriber->restoreProperties($event->reveal()); | ||
} | ||
|
||
public function testRestoreChildren() | ||
{ | ||
$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('child1')->willReturn(false); | ||
$node->hasNode('child2')->willReturn(true); | ||
$node->hasNode('child3')->willReturn(true); | ||
|
||
$definition = $this->prophesize(NodeDefinitionInterface::class); | ||
$definition->getOnParentVersion()->willReturn(OnParentVersionAction::COPY); | ||
|
||
$newChild2Node = $this->prophesize(NodeInterface::class); | ||
$newChild2Node->getName()->willReturn('child2'); | ||
$newChild2Node->getProperties()->willReturn([]); | ||
$newChild2Node->getNodes()->willReturn([]); | ||
$newChild2Node->getDefinition()->willReturn($definition->reveal()); | ||
|
||
$newChild3Node = $this->prophesize(NodeInterface::class); | ||
$newChild3Node->getName()->willReturn('child3'); | ||
$newChild3Node->getDefinition()->willReturn($definition->reveal()); | ||
$newChild3Node->remove()->shouldBeCalled(); | ||
|
||
$newChild1Node = $this->prophesize(NodeInterface::class); | ||
$newChild1Node->getName()->willReturn('child1'); | ||
$newChild1Node->setMixins(['jcr:referencable'])->shouldBeCalled(); | ||
$newChild1Node->getProperties()->willReturn([]); | ||
$newChild1Node->getNodes()->willReturn([]); | ||
$newChild1Node->getDefinition()->willReturn($definition->reveal()); | ||
$node->addNode('child1')->will( | ||
function () use ($node, $newChild1Node, $newChild2Node, $newChild3Node) { | ||
$node->getNode('child1')->willReturn($newChild1Node->reveal()); | ||
$node->getNodes()->willReturn( | ||
[$newChild1Node->reveal(), $newChild2Node->reveal(), $newChild3Node->reveal()] | ||
); | ||
|
||
return $newChild1Node->reveal(); | ||
} | ||
); | ||
|
||
$node->getNode('child2')->willReturn($newChild2Node->reveal()); | ||
$node->getNode('child3')->willReturn($newChild3Node->reveal()); | ||
$node->getNodes()->willReturn([$newChild2Node->reveal(), $newChild3Node->reveal()]); | ||
|
||
$this->propertyEncoder->localizedContentName('', 'de')->willReturn('i18n:de-'); | ||
$this->propertyEncoder->localizedSystemName('', 'de')->willReturn('i18n:de-'); | ||
|
||
$child1 = $this->prophesize(NodeInterface::class); | ||
$child1->getName()->willReturn('child1'); | ||
$child1->getPropertyValueWithDefault('jcr:frozenMixinTypes', [])->willReturn(['jcr:referencable']); | ||
$child1->getPropertiesValues()->willReturn([]); | ||
$child1->getNodes()->willReturn([]); | ||
$child2 = $this->prophesize(NodeInterface::class); | ||
$child2->getName()->willReturn('child2'); | ||
$child2->getPropertiesValues()->willReturn([]); | ||
$child2->getNodes()->willReturn([]); | ||
|
||
$frozenNode->getNodes()->willReturn([$child1->reveal(), $child2->reveal()]); | ||
$frozenNode->getPropertiesValues()->willReturn([]); | ||
$frozenNode->hasNode('child1')->willReturn(true); | ||
$frozenNode->hasNode('child2')->willReturn(true); | ||
$frozenNode->hasNode('child3')->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()); | ||
|
||
$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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danrot i have added assertions |
||
$childNode->remove()->shouldNotBeCalled(); | ||
$childNode->setProperty(Argument::cetera())->shouldNotBeCalled(); | ||
|
||
$this->versionSubscriber->restoreProperties($event->reveal()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's not a single assertion in this test, so we cannot be sure that the child node has not been touched... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not explicit but we could. every not mocked method call would let this test fail - but i will add some assertions. |
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add also a test where the node has children, which should not be copied (as it is the case with the pages).