Skip to content

Commit

Permalink
Rename getContentRichEntity method of DimensionContentInterface to ge…
Browse files Browse the repository at this point in the history
…tResource (#165)
  • Loading branch information
niklasnatter authored Jul 23, 2020
1 parent 44cd550 commit ffd7bb8
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Content/Application/ContentMerger/ContentMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle

$mostSpecificDimensionContent = $dimensionContentCollectionArray[$lastKey];
$mostSpecificDimension = $mostSpecificDimensionContent->getDimension();
$contentRichEntity = $mostSpecificDimensionContent->getContentRichEntity();
$contentRichEntity = $mostSpecificDimensionContent->getResource();

$mergedDimensionContent = $contentRichEntity->createDimensionContent($mostSpecificDimension);
$mergedDimensionContent->markAsMerged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getIgnoredAttributes(object $object): array
'id',
'merged',
'dimension',
'contentRichEntity',
'resource',
];
}

Expand All @@ -37,7 +37,7 @@ public function enhance(object $object, array $normalizedData): array
return $normalizedData;
}

$normalizedData['id'] = $object->getContentRichEntity()->getId();
$normalizedData['id'] = $object->getResource()->getId();
$normalizedData['locale'] = $object->getDimension()->getLocale();
$normalizedData['stage'] = $object->getDimension()->getStage();

Expand Down
2 changes: 1 addition & 1 deletion Content/Domain/Model/DimensionContentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function getResourceKey(): string;

public function getDimension(): DimensionInterface;

public function getContentRichEntity(): ContentRichEntityInterface;
public function getResource(): ContentRichEntityInterface;

public function isMerged(): bool;

Expand Down
4 changes: 2 additions & 2 deletions Content/Domain/Model/RoutableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public function getLocale(): ?string

public function getResourceId()
{
return $this->getContentRichEntity()->getId();
return $this->getResource()->getId();
}

abstract public function getDimension(): DimensionInterface;

abstract public function getContentRichEntity(): ContentRichEntityInterface;
abstract public function getResource(): ContentRichEntityInterface;
}
4 changes: 2 additions & 2 deletions Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getObject($id, $locale)
*/
public function getId($object)
{
return $object->getContentRichEntity()->getId();
return $object->getResource()->getId();
}

/**
Expand Down Expand Up @@ -129,7 +129,7 @@ public function setContext($object, $locale, array $context): DimensionContentIn
public function serialize($object)
{
return json_encode([
'id' => $object->getContentRichEntity()->getId(),
'id' => $object->getResource()->getId(),
'locale' => $object->getDimension()->getLocale(),
]) ?: '[]';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ContentDataItem extends ArrayAccessItem implements ItemInterface, PublishI
public function __construct(DimensionContentInterface $dimensionContent, array $data)
{
parent::__construct(
$dimensionContent->getContentRichEntity()->getId(),
$dimensionContent->getResource()->getId(),
$data,
$dimensionContent
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function (DimensionContentInterface $dimensionContent) {
*/
protected function getIdForItem($dimensionContent)
{
return $dimensionContent->getContentRichEntity()->getId();
return $dimensionContent->getResource()->getId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr
$mediaId = $this->getMediaId($dimensionContent, $data);

return new Teaser(
$dimensionContent->getContentRichEntity()->getId(),
$dimensionContent->getResource()->getId(),
$this->getResourceKey(),
$locale,
$title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getId(): int
return $this->id;
}

public function getContentRichEntity(): ContentRichEntityInterface
public function getResource(): ContentRichEntityInterface
{
return $this->example;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ public static function setUpBeforeClass(): void
parent::setUpBeforeClass();

// Example 1 (both locales, both published)
$example1 = static::createExample(['title' => 'example-1'], 'en')->getContentRichEntity();
$example1 = static::createExample(['title' => 'example-1'], 'en')->getResource();
static::publishExample($example1->getId(), 'en');

static::modifyExample($example1->getId(), ['title' => 'beispiel-1'], 'de');
static::publishExample($example1->getId(), 'de');

// Example 2 (only en, published)
$example2 = static::createExample(['title' => 'example-2'], 'en')->getContentRichEntity();
$example2 = static::createExample(['title' => 'example-2'], 'en')->getResource();
static::publishExample($example2->getId(), 'en');

// Example 3 (both locales, only en published)
$example3 = static::createExample(['title' => 'example-3'], 'en')->getContentRichEntity();
$example3 = static::createExample(['title' => 'example-3'], 'en')->getResource();
static::publishExample($example3->getId(), 'en');

static::modifyExample($example3->getId(), ['title' => 'beispiel-3'], 'de');

// Example 4 (only de, published)
$example4 = static::createExample(['title' => 'beispiel-4'], 'de')->getContentRichEntity();
$example4 = static::createExample(['title' => 'beispiel-4'], 'de')->getResource();
static::publishExample($example4->getId(), 'de');

// Example 5 (only en, not published)
$example5 = static::createExample(['title' => 'example-5'], 'en')->getContentRichEntity();
$example5 = static::createExample(['title' => 'example-5'], 'en')->getResource();
}

public function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function setUpBeforeClass(): void
'title' => 'example without categories without tags',
'excerptCategories' => [],
'excerptTags' => [],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example1->getId(), 'en');
static::modifyExample($example1->getId(), [
'title' => 'example without categories without tags',
Expand All @@ -112,7 +112,7 @@ public static function setUpBeforeClass(): void
static::$categoryFoo->getId(),
],
'excerptTags' => [],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example2->getId(), 'en');
static::modifyExample($example2->getId(), [
'title' => 'example with some categories without tags unpublished',
Expand All @@ -131,7 +131,7 @@ public static function setUpBeforeClass(): void
static::$categoryBaz->getId(),
],
'excerptTags' => [],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example3->getId(), 'en');
static::modifyExample($example3->getId(), [
'title' => 'example with all categories without tags',
Expand All @@ -151,7 +151,7 @@ public static function setUpBeforeClass(): void
'excerptTags' => [
'tagA',
],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example4->getId(), 'en');
static::modifyExample($example4->getId(), [
'title' => 'example without categories with some tags',
Expand All @@ -171,7 +171,7 @@ public static function setUpBeforeClass(): void
'tagB',
'tagC',
],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example5->getId(), 'en');
static::modifyExample($example5->getId(), [
'title' => 'example without categories with all tags',
Expand All @@ -193,7 +193,7 @@ public static function setUpBeforeClass(): void
'excerptTags' => [
'tagB',
],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example6->getId(), 'en');
static::modifyExample($example6->getId(), [
'title' => 'example with some categories with some tags',
Expand All @@ -219,7 +219,7 @@ public static function setUpBeforeClass(): void
'tagB',
'tagC',
],
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example7->getId(), 'en');
static::modifyExample($example7->getId(), [
'title' => 'example with all categories with all tags',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function setUpBeforeClass(): void
'article' => 'example-1-article',
'excerptTitle' => 'example-1-excerpt-title',
'excerptDescription' => 'example-1-excerpt-description',
], 'en')->getContentRichEntity();
], 'en')->getResource();
static::publishExample($example1->getId(), 'en');

static::modifyExample($example1->getId(), [
Expand All @@ -60,27 +60,27 @@ public static function setUpBeforeClass(): void
static::$exampleIds[] = $example1->getId();

// Example 2 (only en, published)
$example2 = static::createExample(['title' => 'example-2'], 'en')->getContentRichEntity();
$example2 = static::createExample(['title' => 'example-2'], 'en')->getResource();
static::publishExample($example2->getId(), 'en');

static::$exampleIds[] = $example2->getId();

// Example 3 (both locales, only en published)
$example3 = static::createExample(['title' => 'example-3'], 'en')->getContentRichEntity();
$example3 = static::createExample(['title' => 'example-3'], 'en')->getResource();
static::publishExample($example3->getId(), 'en');

static::modifyExample($example3->getId(), ['title' => 'beispiel-3'], 'de');

static::$exampleIds[] = $example3->getId();

// Example 4 (only de, published)
$example4 = static::createExample(['title' => 'beispiel-4'], 'de')->getContentRichEntity();
$example4 = static::createExample(['title' => 'beispiel-4'], 'de')->getResource();
static::publishExample($example4->getId(), 'de');

static::$exampleIds[] = $example4->getId();

// Example 5 (only en, not published)
$example5 = static::createExample(['title' => 'example-5'], 'en')->getContentRichEntity();
$example5 = static::createExample(['title' => 'example-5'], 'en')->getResource();

static::$exampleIds[] = $example5->getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public function testMerge(): void

$mostSpecificDimension = $this->prophesize(DimensionInterface::class);

$contentRichEntity = $this->prophesize(ContentRichEntityInterface::class);
$contentRichEntity->createDimensionContent($mostSpecificDimension->reveal())
$resource = $this->prophesize(ContentRichEntityInterface::class);
$resource->createDimensionContent($mostSpecificDimension->reveal())
->willReturn($mergedDimensionContent->reveal());

$dimensionContent3->getDimension()->willReturn($mostSpecificDimension->reveal());
$dimensionContent3->getContentRichEntity()->willReturn($contentRichEntity->reveal());
$dimensionContent3->getResource()->willReturn($resource->reveal());

$merger1->merge($mergedDimensionContent->reveal(), $dimensionContent1->reveal())->shouldBeCalled();
$merger2->merge($mergedDimensionContent->reveal(), $dimensionContent1->reveal())->shouldBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function testResolveSimple(): void
/**
* @var ContentRichEntityInterface
*/
protected $contentRichEntity;
protected $resource;

public function __construct(ContentRichEntityInterface $contentRichEntity, DimensionInterface $dimension)
public function __construct(ContentRichEntityInterface $resource, DimensionInterface $dimension)
{
$this->contentRichEntity = $contentRichEntity;
$this->resource = $resource;
$this->dimension = $dimension;
}

Expand All @@ -79,9 +79,9 @@ public static function getResourceKey(): string
throw new \RuntimeException('Should not be called while executing tests.');
}

public function getContentRichEntity(): ContentRichEntityInterface
public function getResource(): ContentRichEntityInterface
{
return $this->contentRichEntity;
return $this->resource;
}
};

Expand Down Expand Up @@ -113,11 +113,11 @@ public function testResolveFull(): void
/**
* @var ContentRichEntityInterface
*/
protected $contentRichEntity;
protected $resource;

public function __construct(ContentRichEntityInterface $contentRichEntity, DimensionInterface $dimension)
public function __construct(ContentRichEntityInterface $resource, DimensionInterface $dimension)
{
$this->contentRichEntity = $contentRichEntity;
$this->resource = $resource;
$this->dimension = $dimension;
}

Expand All @@ -131,9 +131,9 @@ public static function getTemplateType(): string
throw new \RuntimeException('Should not be called while executing tests.');
}

public function getContentRichEntity(): ContentRichEntityInterface
public function getResource(): ContentRichEntityInterface
{
return $this->contentRichEntity;
return $this->resource;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testIgnoredAttributes(): void
$object = $this->prophesize(DimensionContentInterface::class);

$this->assertSame(
['id', 'merged', 'dimension', 'contentRichEntity'],
['id', 'merged', 'dimension', 'resource'],
$normalizer->getIgnoredAttributes($object->reveal())
);
}
Expand All @@ -68,15 +68,15 @@ public function testEnhance(): void
{
$normalizer = $this->createDimensionContentNormalizerInstance();

$contentRichEntity = $this->prophesize(ContentRichEntityInterface::class);
$contentRichEntity->getId()->willReturn('content-id-123');
$resource = $this->prophesize(ContentRichEntityInterface::class);
$resource->getId()->willReturn('content-id-123');

$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getLocale()->willReturn('en');
$dimension->getStage()->willReturn('live');

$object = $this->prophesize(DimensionContentInterface::class);
$object->getContentRichEntity()->willReturn($contentRichEntity->reveal());
$object->getResource()->willReturn($resource->reveal());
$object->getDimension()->willReturn($dimension->reveal());

$data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function getResourceKey(): string
throw new \RuntimeException('Should not be called while executing tests.');
}

public function getContentRichEntity(): ContentRichEntityInterface
public function getResource(): ContentRichEntityInterface
{
throw new \RuntimeException('Should not be called while executing tests.');
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/Unit/Content/Domain/Model/RoutableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ protected function getRoutableInstance(): RoutableInterface
/**
* @var ContentRichEntityInterface
*/
private $contentRichEntity;
private $resource;

public function __construct(ContentRichEntityInterface $contentRichEntity, DimensionInterface $dimension)
public function __construct(ContentRichEntityInterface $resource, DimensionInterface $dimension)
{
$this->contentRichEntity = $contentRichEntity;
$this->resource = $resource;
$this->dimension = $dimension;
}

Expand All @@ -58,9 +58,9 @@ public function getDimension(): DimensionInterface
return $this->dimension;
}

public function getContentRichEntity(): ContentRichEntityInterface
public function getResource(): ContentRichEntityInterface
{
return $this->contentRichEntity;
return $this->resource;
}
};
}
Expand Down
Loading

0 comments on commit ffd7bb8

Please sign in to comment.