Permalink
Browse files

Merge remote-tracking branch 'upstream/7.2'

  • Loading branch information...
ViniTou committed Oct 9, 2018
2 parents 915f3b3 + 5179158 commit c955a4fb10ce78a9b5cd2d8d17ab2d6348fc7c57
@@ -9,6 +9,7 @@
namespace eZ\Publish\API\Repository\Tests;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\User\User;
/**
* Base class for content specific tests.
@@ -68,8 +69,12 @@ protected function createContentVersion1EmptyBinaryField()
*
* @return \eZ\Publish\API\Repository\Values\Content\Content
*/
protected function createContentDraftVersion1($locationId = 56, $contentTypeIdentifier = 'forum', $contentFieldNameIdentifier = 'name')
{
protected function createContentDraftVersion1(
$locationId = 56,
$contentTypeIdentifier = 'forum',
$contentFieldNameIdentifier = 'name',
User $contentOwner = null
) {
$repository = $this->getRepository();
$parentLocationId = $this->generateId('location', $locationId);
@@ -102,6 +107,10 @@ protected function createContentDraftVersion1($locationId = 56, $contentTypeIden
$contentCreate->sectionId = $sectionId;
$contentCreate->alwaysAvailable = true;
if ($contentOwner) {
$contentCreate->ownerId = $contentOwner->id;
}
// Create a draft
$draft = $contentService->createContent($contentCreate, array($locationCreate));
/* END: Inline */
@@ -3258,6 +3258,60 @@ public function testCopyContent()
);
}
/**
* Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false
* See settings/test/integration_legacy.yml for service override.
*
* @see \eZ\Publish\API\Repository\ContentService::copyContent()
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
* @group field-type
*/
public function testCopyContentWithNewOwner()
{
$parentLocationId = $this->generateId('location', 56);
$repository = $this->getRepository();
$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();
$userService = $repository->getUserService();
$newOwner = $this->createUser('new_owner', 'foo', 'bar');
/* BEGIN: Use Case */
/** @var \eZ\Publish\API\Repository\Values\Content\Content $contentVersion2 */
$contentVersion2 = $this->createContentDraftVersion1(
$parentLocationId,
'forum',
'name',
$newOwner
);
// Configure new target location
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
$targetLocationCreate->priority = 42;
$targetLocationCreate->hidden = true;
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
// Copy content with all versions and drafts
$contentCopied = $contentService->copyContent(
$contentVersion2->contentInfo,
$targetLocationCreate
);
/* END: Use Case */
$this->assertEquals(
$newOwner->id,
$contentVersion2->contentInfo->ownerId
);
$this->assertEquals(
$userService->loadUserByLogin('admin')->getUserId(),
$contentCopied->contentInfo->ownerId
);
}
/**
* Test for the copyContent() method.
*
@@ -51,11 +51,15 @@ public function createDraftFromVersion($contentId, $srcVersion, $userId)
/**
* {@inheritdoc}
*/
public function copy($contentId, $versionNo = null)
public function copy($contentId, $versionNo = null, $newOwnerId = null)
{
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $versionNo));
$this->logger->logCall(__METHOD__, array(
'content' => $contentId,
'version' => $versionNo,
'newOwner' => $newOwnerId,
));
return $this->persistenceHandler->contentHandler()->copy($contentId, $versionNo);
return $this->persistenceHandler->contentHandler()->copy($contentId, $versionNo, $newOwnerId);
}
/**
@@ -140,11 +140,15 @@ public function loadByRemoteId($remoteId)
/**
* {@inheritdoc}
*/
public function copySubtree($sourceId, $destinationParentId)
public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
{
$this->logger->logCall(__METHOD__, array('source' => $sourceId, 'destination' => $destinationParentId));
$this->logger->logCall(__METHOD__, array(
'source' => $sourceId,
'destination' => $destinationParentId,
'newOwner' => $newOwnerId,
));
return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId);
return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId, $newOwnerId);
}
/**
@@ -684,10 +684,11 @@ public function listVersions($contentId, $status = null, $limit = -1)
*
* @param mixed $contentId
* @param mixed|null $versionNo Copy all versions if left null
* @param int|null $newOwnerId
*
* @return \eZ\Publish\SPI\Persistence\Content
*/
public function copy($contentId, $versionNo = null)
public function copy($contentId, $versionNo = null, $newOwnerId = null)
{
$currentVersionNo = isset($versionNo) ?
$versionNo :
@@ -697,6 +698,9 @@ public function copy($contentId, $versionNo = null)
$createStruct = $this->mapper->createCreateStructFromContent(
$this->load($contentId, $currentVersionNo)
);
if ($newOwnerId) {
$createStruct->ownerId = $newOwnerId;
}
$content = $this->internalCreate($createStruct, $currentVersionNo);
// If version was not passed also copy other versions
@@ -211,10 +211,12 @@ protected function setContentStates(Content $content, array $contentStates)
*
* @param mixed $sourceId
* @param mixed $destinationParentId
* @param int|null $newOwnerId
*
* @return Location the newly created Location.
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function copySubtree($sourceId, $destinationParentId)
public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
{
$children = $this->locationGateway->getSubtreeContent($sourceId);
$destinationParentData = $this->locationGateway->getBasicNodeData($destinationParentId);
@@ -242,7 +244,8 @@ public function copySubtree($sourceId, $destinationParentId)
if (!isset($contentMap[$child['contentobject_id']])) {
$content = $this->contentHandler->copy(
$child['contentobject_id'],
$child['contentobject_version']
$child['contentobject_version'],
$newOwnerId
);
$this->setContentStates($content, $defaultObjectStates);
@@ -1677,7 +1677,8 @@ public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $dest
try {
$spiContent = $this->persistenceHandler->contentHandler()->copy(
$contentInfo->id,
$versionInfo ? $versionInfo->versionNo : null
$versionInfo ? $versionInfo->versionNo : null,
$this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId()
);
$objectStateHandler = $this->persistenceHandler->objectStateHandler();
@@ -168,7 +168,8 @@ public function copySubtree(APILocation $subtree, APILocation $targetParentLocat
try {
$newLocation = $this->persistenceHandler->locationHandler()->copySubtree(
$loadedSubtree->id,
$loadedTargetLocation->id
$loadedTargetLocation->id,
$this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId()
);
$content = $this->repository->getContentService()->loadContent($newLocation->contentId);
@@ -5415,6 +5415,20 @@ public function testCopyContent()
$contentInfoMock = $this->createMock(APIContentInfo::class);
$locationCreateStruct = new LocationCreateStruct();
$location = new Location(['id' => $locationCreateStruct->parentLocationId]);
$user = $this->getStubbedUser(14);
$permissionResolverMock = $this
->getMockBuilder('eZ\\Publish\\API\\Repository\\PermissionResolver')
->disableOriginalConstructor()
->getMock();
$permissionResolverMock
->method('getCurrentUserReference')
->willReturn($user);
$repositoryMock
->method('getPermissionResolver')
->willReturn($permissionResolverMock);
$repositoryMock->expects($this->exactly(3))
->method('getLocationService')
@@ -5530,6 +5544,20 @@ public function testCopyContentWithVersionInfo()
$contentInfoMock = $this->createMock(APIContentInfo::class);
$locationCreateStruct = new LocationCreateStruct();
$location = new Location(['id' => $locationCreateStruct->parentLocationId]);
$user = $this->getStubbedUser(14);
$permissionResolverMock = $this
->getMockBuilder('eZ\\Publish\\API\\Repository\\PermissionResolver')
->disableOriginalConstructor()
->getMock();
$permissionResolverMock
->method('getCurrentUserReference')
->willReturn($user);
$repositoryMock
->method('getPermissionResolver')
->willReturn($permissionResolverMock);
$repositoryMock->expects($this->exactly(3))
->method('getLocationService')
@@ -5642,6 +5670,20 @@ public function testCopyContentWithRollback()
$locationCreateStruct = new LocationCreateStruct();
$location = new Location(['id' => $locationCreateStruct->parentLocationId]);
$locationServiceMock = $this->getLocationServiceMock();
$user = $this->getStubbedUser(14);
$permissionResolverMock = $this
->getMockBuilder('eZ\\Publish\\API\\Repository\\PermissionResolver')
->disableOriginalConstructor()
->getMock();
$permissionResolverMock
->method('getCurrentUserReference')
->willReturn($user);
$repositoryMock
->method('getPermissionResolver')
->willReturn($permissionResolverMock);
$repositoryMock->expects($this->once())
->method('getLocationService')

0 comments on commit c955a4f

Please sign in to comment.