Skip to content

Commit

Permalink
Merge branch '7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Dec 22, 2017
2 parents b83501e + c10d621 commit acd6b47
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 24 deletions.
2 changes: 1 addition & 1 deletion doc/specifications/cache/persistence/Readme.md
Expand Up @@ -30,7 +30,7 @@ List of tags and their meaning:
_Same as above, additional tags for all parents, for operations that changes the tree itself, like move/remove/(..)._

- `location-data-<location-id>` :
_Used on location, and invalidated when operations affect the properties on location only, e.g. swap/update._
_Used on location, and invalidated when operations affect the properties on location only, e.g. update._

- `location-path-data-<location-id>` :
_Same as above, but for operations affecting data in the tree, e.g. hide/unhide._
Expand Down
21 changes: 0 additions & 21 deletions eZ/Publish/API/Repository/Tests/ContentServiceTest.php
Expand Up @@ -5617,27 +5617,6 @@ public function testDeleteTranslationFromDraftThrowsInvalidArgumentException()
$contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode);
}

/**
* Simplify creating custom role with limited set of policies.
*
* @param $roleName
* @param array $policies e.g. [ ['content', 'create'], ['content', 'edit'], ]
*/
private function createRoleWithPolicies($roleName, array $policies)
{
$repository = $this->getRepository();
$roleService = $repository->getRoleService();

$roleCreateStruct = $roleService->newRoleCreateStruct($roleName);
foreach ($policies as $policy) {
$policyCreateStruct = $roleService->newPolicyCreateStruct($policy[0], $policy[1]);
$roleCreateStruct->addPolicy($policyCreateStruct);
}

$roleDraft = $roleService->createRole($roleCreateStruct);
$roleService->publishRoleDraft($roleDraft);
}

/**
* Asserts that all aliases defined in $expectedAliasProperties with the
* given properties are available in $actualAliases and not more.
Expand Down
68 changes: 68 additions & 0 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Expand Up @@ -1209,6 +1209,43 @@ public function testSwapLocation()
);
}

/**
* Test swapping Main Location of a Content with another one updates Content item Main Location.
*
* @covers \eZ\Publish\API\Repository\LocationService::swapLocation
*/
public function testSwapLocationUpdatesMainLocation()
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();
$contentService = $repository->getContentService();

$mainLocationParentId = 60;
$secondaryLocationId = 43;

$publishedContent = $this->publishContentWithParentLocation(
'Content for Swap Location Test', $mainLocationParentId
);

// sanity check
$mainLocation = $locationService->loadLocation($publishedContent->contentInfo->mainLocationId);
self::assertEquals($mainLocationParentId, $mainLocation->parentLocationId);

// load another pre-existing location
$secondaryLocation = $locationService->loadLocation($secondaryLocationId);

// swap the Main Location with a secondary one
$locationService->swapLocation($mainLocation, $secondaryLocation);

// check if Main Location has been updated
$mainLocation = $locationService->loadLocation($secondaryLocation->id);
self::assertEquals($publishedContent->contentInfo->id, $mainLocation->contentInfo->id);
self::assertEquals($mainLocation->id, $mainLocation->contentInfo->mainLocationId);

$reloadedContent = $contentService->loadContentByContentInfo($publishedContent->contentInfo);
self::assertEquals($mainLocation->id, $reloadedContent->contentInfo->mainLocationId);
}

/**
* Test for the hideLocation() method.
*
Expand Down Expand Up @@ -2248,4 +2285,35 @@ private function assertAliasesBeforeCopy($urlAliasService, array $expectedSubIte
}
}
}

/**
* Create and publish Content with the given parent Location.
*
* @param string $contentName
* @param int $parentLocationId
*
* @return \eZ\Publish\API\Repository\Values\Content\Content published Content
*/
private function publishContentWithParentLocation($contentName, $parentLocationId)
{
$repository = $this->getRepository(false);
$locationService = $repository->getLocationService();

$contentService = $repository->getContentService();
$contentTypeService = $repository->getContentTypeService();

$contentCreateStruct = $contentService->newContentCreateStruct(
$contentTypeService->loadContentTypeByIdentifier('folder'),
'eng-US'
);
$contentCreateStruct->setField('name', $contentName);
$contentDraft = $contentService->createContent(
$contentCreateStruct,
[
$locationService->newLocationCreateStruct($parentLocationId),
]
);

return $contentService->publishVersion($contentDraft->versionInfo);
}
}
7 changes: 6 additions & 1 deletion eZ/Publish/Core/Persistence/Cache/LocationHandler.php
Expand Up @@ -205,7 +205,12 @@ public function swap($locationId1, $locationId2)

$return = $locationHandler->swap($locationId1, $locationId2);

$this->cache->invalidateTags(['location-data-' . $locationId1, 'location-data-' . $locationId2]);
$this->cache->invalidateTags(
[
'location-' . $locationId1,
'location-' . $locationId2,
]
);

return $return;
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function providerForUnCachedMethods(): array
['markSubtreeModified', [12]],
['hide', [12], ['location-path-data-12']],
['unHide', [12], ['location-path-data-12']],
['swap', [12, 45], ['location-data-12', 'location-data-45']],
['swap', [12, 45], ['location-12', 'location-45']],
['update', [new UpdateStruct(), 12], ['location-data-12']],
['create', [new CreateStruct(['contentId' => 4, 'mainLocationId' => true])], ['content-4', 'role-assignment-group-list-4']],
['create', [new CreateStruct(['contentId' => 4, 'mainLocationId' => false])], ['content-4', 'role-assignment-group-list-4']],
Expand Down

0 comments on commit acd6b47

Please sign in to comment.