Skip to content

Commit

Permalink
EZP-29850: As a Developer I want API to assign a Section to a subtree…
Browse files Browse the repository at this point in the history
… (#2521)
  • Loading branch information
adamwojs authored and Łukasz Serwatka committed Jan 28, 2019
1 parent 71ca773 commit 459b291
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Repository/PermissionCriterionResolver.php
Expand Up @@ -21,8 +21,9 @@ interface PermissionCriterionResolver
*
* @param string $module
* @param string $function
* @param array|null $targets
*
* @return bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
*/
public function getPermissionsCriterion($module, $function);
public function getPermissionsCriterion($module, $function, ?array $targets = null);
}
10 changes: 10 additions & 0 deletions Repository/SectionService.php
Expand Up @@ -8,6 +8,7 @@
*/
namespace eZ\Publish\API\Repository;

use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\SectionCreateStruct;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Section;
Expand Down Expand Up @@ -111,6 +112,15 @@ public function isSectionUsed(Section $section);
*/
public function assignSection(ContentInfo $contentInfo, Section $section);

/**
* Assigns the subtree to the given section
* this method overrides the current assigned section.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location
* @param \eZ\Publish\API\Repository\Values\Content\Section $section
*/
public function assignSectionToSubtree(Location $location, Section $section): void;

/**
* Deletes $section from content repository.
*
Expand Down
52 changes: 52 additions & 0 deletions Repository/Tests/SectionServiceTest.php
Expand Up @@ -588,6 +588,58 @@ public function testAssignSection()
);
}

/**
* Test for the assignSectionToSubtree() method.
*
* @see \eZ\Publish\API\Repository\SectionService::assignSectionToSubtree()
* @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
*/
public function testAssignSectionToSubtree()
{
$repository = $this->getRepository();
$sectionService = $repository->getSectionService();

$standardSectionId = $this->generateId('section', 1);
$mediaSectionId = $this->generateId('section', 3);

$beforeStandardCount = $sectionService->countAssignedContents(
$sectionService->loadSection($standardSectionId)
);

$beforeMediaCount = $sectionService->countAssignedContents(
$sectionService->loadSection($mediaSectionId)
);

// RemoteId of the "Media" page of an eZ Publish demo installation
$mediaRemoteId = '75c715a51699d2d309a924eca6a95145';

/* BEGIN: Use Case */
$locationService = $repository->getLocationService();

// Load a location instance
$location = $locationService->loadLocationByRemoteId($mediaRemoteId);

// Load the "Standard" section
$section = $sectionService->loadSection($standardSectionId);

// Assign Section to ContentInfo
$sectionService->assignSectionToSubtree($location, $section);

/* END: Use Case */
$this->assertEquals(
$beforeStandardCount + 4,
$sectionService->countAssignedContents(
$sectionService->loadSection($standardSectionId)
)
);
$this->assertEquals(
$beforeMediaCount - 4,
$sectionService->countAssignedContents(
$sectionService->loadSection($mediaSectionId)
)
);
}

/**
* Test for the countAssignedContents() method.
*
Expand Down

0 comments on commit 459b291

Please sign in to comment.