Skip to content

Commit

Permalink
Merge branch '1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Oct 5, 2020
2 parents b2f7571 + 46bd2ea commit 8c8e287
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 32 deletions.
55 changes: 45 additions & 10 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,47 @@ public function testCreateLocation()
];
}

/**
* Test for the createLocation() method.
*
* @covers \eZ\Publish\API\Repository\LocationService::createLocation
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testHideContent
*/
public function testCreateLocationChecksContentVisibility(): void
{
$repository = $this->getRepository();

$contentId = $this->generateId('object', 41);
$parentLocationId = $this->generateId('location', 5);
/* BEGIN: Use Case */
// $contentId is the ID of an existing content object
// $parentLocationId is the ID of an existing location
$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();

// ContentInfo for "How to use eZ Publish"
$contentInfo = $contentService->loadContentInfo($contentId);
$contentService->hideContent($contentInfo);

$locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
$locationCreate->priority = 23;
$locationCreate->hidden = false;
$locationCreate->remoteId = 'sindelfingen';
$locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
$locationCreate->sortOrder = Location::SORT_ORDER_DESC;

$location = $locationService->createLocation(
$contentInfo,
$locationCreate
);
/* END: Use Case */

self::assertInstanceOf(Location::class, $location);

self::assertTrue($location->invisible);
}

/**
* Test for the createLocation() method with utilizing default ContentType sorting options.
*
Expand Down Expand Up @@ -809,28 +850,22 @@ public function testLoadLocations()
*/
public function testLoadLocationsContent(array $locations)
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();

$this->assertCount(1, $locations);
foreach ($locations as $loadedLocation) {
$this->assertInstanceOf(
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location',
$loadedLocation
);
self::assertInstanceOf(Location::class, $loadedLocation);
}

usort(
$locations,
function ($a, $b) {
strcmp($a->id, $b->id);
static function ($a, $b) {
return strcmp($a->id, $b->id);
}
);

$this->assertEquals(
[$this->generateId('location', 5)],
array_map(
function (Location $location) {
static function (Location $location) {
return $location->id;
},
$locations
Expand Down
6 changes: 3 additions & 3 deletions eZ/Publish/API/Repository/Values/Content/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @property-read int $id the id of the location
* @property-read int $priority Position of the Location among its siblings when sorted using priority
* @property-read bool $hidden Indicates that the Location entity is hidden (explicitly or hidden by content).
* @property-read bool $invisible Indicates that the Location is implicitly marked as hidden by a parent location
* @property-read bool $invisible Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by its Content or an ancestor Location
* @property-read bool $explicitlyHidden Indicates that the Location entity has been explicitly marked as hidden.
* @property-read string $remoteId a global unique id of the content object
* @property-read int $parentLocationId the id of the parent location
Expand Down Expand Up @@ -121,8 +121,8 @@ abstract class Location extends ValueObject
protected $hidden;

/**
* Indicates that the Location is implicitly marked as hidden by a parent
* location.
* Indicates that the Location is not visible, being either marked as hidden itself,
* or implicitly hidden by its Content or an ancestor Location.
*
* @var bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,18 @@

namespace eZ\Publish\Core\MVC\Symfony\Component\Tests\Serializer;

use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
use eZ\Publish\Core\MVC\Symfony\Component\Serializer\RegexNormalizer;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Regex as RegexMatcher;
use eZ\Publish\Core\MVC\Symfony\Component\Tests\Serializer\Stubs\RegexMatcher as RegexMatcherStub;
use PHPUnit\Framework\TestCase;

final class RegexNormalizerTest extends TestCase
{
public function testNormalize(): void
{
$normalizer = new RegexNormalizer();

$matcher = new class('/^Foo(.*)/(.*)/', 2) extends RegexMatcher {
public function getName()
{
throw new NotImplementedException(__METHOD__);
}
};
$matcher = new RegexMatcherStub('/^Foo(.*)/(.*)/', 2);

$this->assertEquals(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\Core\MVC\Symfony\Component\Tests\Serializer\Stubs;

use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Regex as BaseRegex;

final class RegexMatcher extends BaseRegex
{
public function getName()
{
throw new NotImplementedException(__METHOD__);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\Core\MVC\Symfony\Component\Tests\Serializer\Stubs;

use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
Expand All @@ -24,7 +22,7 @@ public function deserialize($data, $type, $format, array $context = [])
throw new NotImplementedException(__METHOD__);
}

public function normalize($object, $format = null, array $context = [])
public function normalize($object, string $format = null, array $context = [])
{
if (is_array($object)) {
$result = [];
Expand All @@ -44,7 +42,7 @@ public function normalize($object, $format = null, array $context = [])
return $object;
}

public function supportsNormalization($data, $format = null)
public function supportsNormalization($data, string $format = null)
{
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ protected function buildSPILocationCreateStructs(array $locationCreateStructs):
$mainLocation,
// For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation
null,
null
null,
false
);

// First Location in the list will be created as main Location
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $l
$parentLocation,
$contentInfo->mainLocationId ?? true,
$contentInfo->id,
$contentInfo->currentVersionNo
$contentInfo->currentVersionNo,
$contentInfo->isHidden
);

$this->repository->beginTransaction();
Expand Down
6 changes: 4 additions & 2 deletions eZ/Publish/Core/Repository/Mapper/ContentDomainMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ public function buildLocationDomainObjectsOnSearchResult(SearchResult $result, a
* @param mixed $mainLocation
* @param mixed $contentId
* @param mixed $contentVersionNo
* @param bool $isContentHidden
*
* @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
*/
Expand All @@ -681,7 +682,8 @@ public function buildSPILocationCreateStruct(
APILocation $parentLocation,
$mainLocation,
$contentId,
$contentVersionNo
$contentVersionNo,
bool $isContentHidden
) {
if (!$this->isValidLocationPriority($locationCreateStruct->priority)) {
throw new InvalidArgumentValue('priority', $locationCreateStruct->priority, 'LocationCreateStruct');
Expand Down Expand Up @@ -726,7 +728,7 @@ public function buildSPILocationCreateStruct(
// Otherwise it picks up visibility from parent Location
// Note: There is no need to check for hidden status of parent, as hidden Location
// is always invisible as well
'invisible' => ($locationCreateStruct->hidden === true || $parentLocation->invisible),
'invisible' => ($locationCreateStruct->hidden === true || $parentLocation->invisible || $isContentHidden),
'remoteId' => $remoteId,
'contentId' => $contentId,
'contentVersion' => $contentVersionNo,
Expand Down
9 changes: 6 additions & 3 deletions eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,8 @@ public function testCreateContentWithLocations()
$this->equalTo($parentLocation),
$this->equalTo(true),
$this->equalTo(null),
$this->equalTo(null)
$this->equalTo(null),
$this->equalTo(false)
)->will($this->returnValue($spiLocationCreateStruct));

$domainMapperMock->expects($this->at(2))
Expand All @@ -2669,7 +2670,8 @@ public function testCreateContentWithLocations()
$this->equalTo($parentLocation),
$this->equalTo(false),
$this->equalTo(null),
$this->equalTo(null)
$this->equalTo(null),
$this->equalTo(false)
)->will($this->returnValue($spiLocationCreateStruct));

$spiContentCreateStruct = new SPIContentCreateStruct(
Expand Down Expand Up @@ -2869,7 +2871,8 @@ function ($object) use ($that, $contentCreateStruct) {
$this->equalTo($parentLocation),
$this->equalTo(true),
$this->equalTo(null),
$this->equalTo(null)
$this->equalTo(null),
$this->equalTo(false)
)->will($this->returnValue($spiLocationCreateStruct));

$fieldTypeMock = $this->createMock(SPIFieldType::class);
Expand Down

0 comments on commit 8c8e287

Please sign in to comment.