diff --git a/eZ/Publish/SPI/Specification/Content/ContentContainerSpecification.php b/eZ/Publish/SPI/Specification/Content/ContentContainerSpecification.php new file mode 100644 index 0000000000..1f527e8835 --- /dev/null +++ b/eZ/Publish/SPI/Specification/Content/ContentContainerSpecification.php @@ -0,0 +1,19 @@ +getContentType()->isContainer; + } +} diff --git a/eZ/Publish/SPI/Specification/Content/ContentSpecification.php b/eZ/Publish/SPI/Specification/Content/ContentSpecification.php new file mode 100644 index 0000000000..2a510ec65e --- /dev/null +++ b/eZ/Publish/SPI/Specification/Content/ContentSpecification.php @@ -0,0 +1,16 @@ +expectedType = $expectedType; + } + + public function isSatisfiedBy(Content $content): bool + { + return $content->getContentType()->identifier === $this->expectedType; + } +} diff --git a/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php b/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php new file mode 100644 index 0000000000..5cb5b883d0 --- /dev/null +++ b/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php @@ -0,0 +1,63 @@ +assertInstanceOf(ContentSpecification::class, $contentTypeSpecification); + } + + /** + * @covers \eZ\Publish\SPI\Specification\Content\ContentContainerSpecification::isSatisfiedBy + * @dataProvider providerForIsSatisfiedBy + */ + public function testIsSatisfiedBy( + bool $isContainer, + bool $shouldBeSatisfied + ): void { + $contentContainerSpecification = new ContentContainerSpecification(); + + $contentTypeMock = $this->getMockBuilder(ContentType::class) + ->setConstructorArgs( + [['isContainer' => $isContainer]] + ) + ->getMockForAbstractClass(); + + $contentMock = $this->createMock(Content::class); + $contentMock->expects($this->once()) + ->method('getContentType') + ->willReturn($contentTypeMock); + + $this->assertEquals( + $contentContainerSpecification->isSatisfiedBy($contentMock), + $shouldBeSatisfied + ); + } + + public function providerForIsSatisfiedBy(): array + { + return [ + [true, true], + [false, false], + ]; + } +} diff --git a/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php b/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php new file mode 100644 index 0000000000..1b48cf9e2c --- /dev/null +++ b/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php @@ -0,0 +1,77 @@ +assertInstanceOf(ContentSpecification::class, $contentTypeSpecification); + } + + public function testConstructorWithNotExistingContentTypeIdentifier(): void + { + $contentTypeSpecification = new ContentTypeSpecification( + self::NOT_EXISTING_CONTENT_TYPE_IDENTIFIER + ); + + $this->assertInstanceOf(ContentSpecification::class, $contentTypeSpecification); + } + + /** + * @covers \eZ\Publish\SPI\Specification\Content\ContentTypeSpecification::isSatisfiedBy + * @dataProvider providerForIsSatisfiedBy + */ + public function testIsSatisfiedBy( + string $contentTypeSpecificationIdentifier, + string $contentTypeIdentifier, + bool $shouldBeSatisfied + ): void { + $contentTypeSpecification = new ContentTypeSpecification( + $contentTypeSpecificationIdentifier + ); + + $contentTypeMock = $this->getMockBuilder(ContentType::class) + ->setConstructorArgs( + [['identifier' => $contentTypeIdentifier]] + ) + ->getMockForAbstractClass(); + + $contentMock = $this->createMock(Content::class); + $contentMock->expects($this->once()) + ->method('getContentType') + ->willReturn($contentTypeMock); + + $this->assertEquals( + $contentTypeSpecification->isSatisfiedBy($contentMock), + $shouldBeSatisfied + ); + } + + public function providerForIsSatisfiedBy(): array + { + return [ + [self::EXISTING_CONTENT_TYPE_IDENTIFIER, self::EXISTING_CONTENT_TYPE_IDENTIFIER, true], + [self::NOT_EXISTING_CONTENT_TYPE_IDENTIFIER, self::EXISTING_CONTENT_TYPE_IDENTIFIER, false], + ]; + } +}