Skip to content

Commit

Permalink
Fixed use ->sectionId
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Mar 18, 2024
1 parent a036df4 commit d560b61
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 42 deletions.
8 changes: 5 additions & 3 deletions src/lib/Limitation/SectionLimitationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ public function evaluate(APILimitationValue $value, APIUserReference $currentUse
/*
* We ignore Targets here, they are only interesting in NewState limitation as we on this one is more interested
* the section already assigned to object.
*
* @var $object ContentInfo|ContentCreateStruct
*/
return in_array($object->sectionId, $value->limitationValues);
if ($object instanceof ContentCreateStruct) {
return in_array($object->sectionId, $value->limitationValues);
}

return in_array($object->getSectionId(), $value->limitationValues);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/lib/MVC/Symfony/Matcher/ContentBased/Id/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Section extends MultipleValued
*/
public function matchLocation(APILocation $location)
{
return isset($this->values[$location->getContentInfo()->sectionId]);
return isset($this->values[$location->getContentInfo()->getSectionId()]);
}

/**
Expand All @@ -35,7 +35,7 @@ public function matchLocation(APILocation $location)
*/
public function matchContentInfo(ContentInfo $contentInfo)
{
return isset($this->values[$contentInfo->sectionId]);
return isset($this->values[$contentInfo->getSectionId()]);
}

public function match(View $view)
Expand All @@ -44,7 +44,7 @@ public function match(View $view)
return false;
}

return isset($this->values[$view->getContent()->contentInfo->sectionId]);
return isset($this->values[$view->getContent()->contentInfo->getSectionId()]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function matchLocation(Location $location)
$section = $this->repository->sudo(
static function (Repository $repository) use ($location) {
return $repository->getSectionService()->loadSection(
$location->getContentInfo()->sectionId
$location->getContentInfo()->getSectionId()
);
}
);
Expand All @@ -47,7 +47,7 @@ public function matchContentInfo(ContentInfo $contentInfo)
$section = $this->repository->sudo(
static function (Repository $repository) use ($contentInfo) {
return $repository->getSectionService()->loadSection(
$contentInfo->sectionId
$contentInfo->getSectionId()
);
}
);
Expand All @@ -65,7 +65,7 @@ public function match(View $view)
$section = $this->repository->sudo(
static function (Repository $repository) use ($contentInfo) {
return $repository->getSectionService()->loadSection(
$contentInfo->sectionId
$contentInfo->getSectionId()
);
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public function createContent(APIContentCreateStruct $contentCreateStruct, array
$location = $this->repository->getLocationService()->loadLocation(
$locationCreateStructs[0]->parentLocationId
);
$contentCreateStruct->sectionId = $location->contentInfo->sectionId;
$contentCreateStruct->sectionId = $location->getContentInfo()->getSectionId();
} else {
$contentCreateStruct->sectionId = 1;
}
Expand Down Expand Up @@ -1945,7 +1945,7 @@ public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $dest
'create',
[
'parentLocationId' => $destinationLocationCreateStruct->parentLocationId,
'sectionId' => $contentInfo->sectionId,
'sectionId' => $contentInfo->getSectionId(),
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/Core/Repository/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ public function testCreateContentDraftSetsContentInfo($draft)
$contentInfo->mainLanguageCode,
$contentInfo->ownerId,
$contentInfo->remoteId,
$contentInfo->sectionId,
$contentInfo->getSectionId(),
]
);
}
Expand Down Expand Up @@ -2071,7 +2071,7 @@ public function testUpdateContentMetadataSetsExpectedProperties($content)
],
[
'remoteId' => $contentInfo->remoteId,
'sectionId' => $contentInfo->sectionId,
'sectionId' => $contentInfo->getSectionId(),
'alwaysAvailable' => $contentInfo->alwaysAvailable,
'currentVersionNo' => $contentInfo->currentVersionNo,
'mainLanguageCode' => $contentInfo->mainLanguageCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,10 @@ public function testAssignSection()
$criterion = new Criterion\ContentId($content->id);
$query = new Query(['filter' => $criterion]);
$results = $searchService->findContentInfo($query);
$this->assertEquals($section->id, $results->searchHits[0]->valueObject->sectionId);

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo */
$contentInfo = $results->searchHits[0]->valueObject;
$this->assertEquals($section->id, $contentInfo->getSectionId());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testNewSectionLimitationAllow()

$this->assertSame(
$sectionId,
$contentService->loadContentInfo($contentId)->sectionId
$contentService->loadContentInfo($contentId)->getSectionId()
);
}

Expand Down
61 changes: 34 additions & 27 deletions tests/lib/Repository/Values/Content/ContentInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace Ibexa\Tests\Core\Repository\Values\Content;

use DateTimeImmutable;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use PHPUnit\Framework\TestCase;

Expand All @@ -14,35 +15,41 @@
*/
class ContentInfoTest extends TestCase
{
public function testObjectProperties()
public function testCreateObject(): void
{
$object = new ContentInfo();
$properties = $object->attributes();
self::assertNotContains('internalFields', $properties, 'Internal property found ');
self::assertContains('contentTypeId', $properties, 'Property not found');
self::assertContains('id', $properties, 'Property not found');
self::assertContains('name', $properties, 'Property not found');
self::assertContains('sectionId', $properties, 'Property not found');
self::assertContains('currentVersionNo', $properties, 'Property not found');
self::assertContains('published', $properties, 'Property not found');
self::assertContains('ownerId', $properties, 'Property not found');
self::assertContains('modificationDate', $properties, 'Property not found');
self::assertContains('publishedDate', $properties, 'Property not found');
self::assertContains('alwaysAvailable', $properties, 'Property not found');
self::assertContains('remoteId', $properties, 'Property not found');
self::assertContains('mainLanguageCode', $properties, 'Property not found');
self::assertContains('mainLocationId', $properties, 'Property not found');
$dateTime = new DateTimeImmutable();
$contentInfo = new ContentInfo(
[
'id' => 1,
'contentTypeId' => 2,
'name' => 'foo',
'sectionId' => 1,
'currentVersionNo' => 1,
'status' => 1,
'ownerId' => 10,
'modificationDate' => $dateTime,
'publishedDate' => $dateTime,
'alwaysAvailable' => false,
'remoteId' => '1qaz2wsx',
'mainLanguageCode' => 'eng-GB',
'mainLocationId' => 2,
]
);

// check for duplicates and double check existence of property
$propertiesHash = [];
foreach ($properties as $property) {
if (isset($propertiesHash[$property])) {
self::fail("Property '{$property}' exists several times in properties list");
} elseif (!isset($object->$property)) {
self::fail("Property '{$property}' does not exist on object, even though it was hinted to be there");
}
$propertiesHash[$property] = 1;
}
$dateFormatted = $dateTime->format('c');
self::assertSame($contentInfo->getId(), 1);
self::assertSame($contentInfo->contentTypeId, 2);
self::assertSame($contentInfo->name, 'foo');
self::assertSame($contentInfo->getSectionId(), 1);
self::assertSame($contentInfo->currentVersionNo, 1);
self::assertTrue($contentInfo->isPublished());
self::assertSame($contentInfo->ownerId, 10);
self::assertSame($dateFormatted, $contentInfo->modificationDate->format('c'));
self::assertSame($dateFormatted, $contentInfo->publishedDate->format('c'));
self::assertFalse($contentInfo->alwaysAvailable);
self::assertSame($contentInfo->remoteId, '1qaz2wsx');
self::assertSame($contentInfo->getMainLanguageCode(), 'eng-GB');
self::assertSame($contentInfo->getMainLocationId(), 2);
}
}

Expand Down

0 comments on commit d560b61

Please sign in to comment.