Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-32361: Fixed Subtree copying when child is invisible #3104

Merged
merged 2 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,49 @@ public function testCopySubtreeIncrementsChildCountOfNewParent()
$this->assertEquals($childCountBefore + 1, $childCountAfter);
}

/**
* @covers \eZ\Publish\API\Repository\LocationService::copySubtree()
*/
public function testCopySubtreeWithInvisibleChild(): void
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();

// Hide child Location
$locationService->hideLocation($locationService->loadLocation($this->generateId('location', 53)));

$this->refreshSearch($repository);

$locationToCopy = $locationService->loadLocation($this->generateId('location', 43));

$expected = $this->loadSubtreeProperties($locationToCopy);

$mediaLocationId = $this->generateId('location', 43);
$demoDesignLocationId = $this->generateId('location', 56);
$locationService = $repository->getLocationService();

$locationToCopy = $locationService->loadLocation($mediaLocationId);

$newParentLocation = $locationService->loadLocation($demoDesignLocationId);

$copiedLocation = $locationService->copySubtree(
$locationToCopy,
$newParentLocation
);

$this->refreshSearch($repository);

// Load Subtree properties after copy
$actual = $this->loadSubtreeProperties($copiedLocation);

self::assertEquals(count($expected), count($actual));

foreach ($actual as $key => $properties) {
self::assertEquals($expected[$key]['hidden'], $properties['hidden']);
self::assertEquals($expected[$key]['invisible'], $properties['invisible']);
}
Comment on lines +2558 to +2563
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general usage of self::assertSame is preferred. It's similar to using == vs === - if there is no reason for non-strict comparison, strict should be used.

}

/**
* Test for the copySubtree() method.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
$createStruct->contentId = $contentMap[$child['contentobject_id']];
$parentData = $locationMap[$child['parent_node_id']];
$createStruct->parentId = $parentData['id'];
$createStruct->invisible = $createStruct->hidden || $parentData['hidden'] || $parentData['invisible'];
$createStruct->invisible = $createStruct->invisible
|| $createStruct->hidden
|| $parentData['hidden']
|| $parentData['invisible'];
$pathString = explode('/', $child['path_identification_string']);
$pathString = end($pathString);
$createStruct->pathIdentificationString = strlen($pathString) > 0
Expand Down