From 998d9027bc01ba5d00d182161b06e2ca7caddc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Thu, 9 Apr 2020 13:07:27 +0200 Subject: [PATCH 1/4] EZEE-3085 Added specification ContentTypeSpecification --- .../Content/ContentTypeSpecification.php | 30 +++++++++++++++++++ .../Specification/ContentSpecification.php | 16 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php create mode 100644 eZ/Publish/SPI/Specification/ContentSpecification.php diff --git a/eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php b/eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php new file mode 100644 index 0000000000..0ce8478daa --- /dev/null +++ b/eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php @@ -0,0 +1,30 @@ +expectedType = $expectedType; + } + + public function isSatisfiedBy(Content $content): bool + { + return $content->getContentType()->identifier === $this->expectedType; + } +} diff --git a/eZ/Publish/SPI/Specification/ContentSpecification.php b/eZ/Publish/SPI/Specification/ContentSpecification.php new file mode 100644 index 0000000000..6cebd04127 --- /dev/null +++ b/eZ/Publish/SPI/Specification/ContentSpecification.php @@ -0,0 +1,16 @@ + Date: Fri, 10 Apr 2020 11:39:47 +0200 Subject: [PATCH 2/4] Added ContentContainerSpecification --- .../Content/ContentContainerSpecification.php | 19 +++++++++++++++++++ .../{ => Content}/ContentSpecification.php | 2 +- .../Content/ContentTypeSpecification.php | 5 ++--- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 eZ/Publish/SPI/Specification/Content/ContentContainerSpecification.php rename eZ/Publish/SPI/Specification/{ => Content}/ContentSpecification.php (88%) rename eZ/Publish/{Core => SPI}/Specification/Content/ContentTypeSpecification.php (78%) 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/ContentSpecification.php b/eZ/Publish/SPI/Specification/Content/ContentSpecification.php similarity index 88% rename from eZ/Publish/SPI/Specification/ContentSpecification.php rename to eZ/Publish/SPI/Specification/Content/ContentSpecification.php index 6cebd04127..2a510ec65e 100644 --- a/eZ/Publish/SPI/Specification/ContentSpecification.php +++ b/eZ/Publish/SPI/Specification/Content/ContentSpecification.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace eZ\Publish\SPI\Specification; +namespace eZ\Publish\SPI\Specification\Content; use eZ\Publish\API\Repository\Values\Content\Content; diff --git a/eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php b/eZ/Publish/SPI/Specification/Content/ContentTypeSpecification.php similarity index 78% rename from eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php rename to eZ/Publish/SPI/Specification/Content/ContentTypeSpecification.php index 0ce8478daa..48b0707d03 100644 --- a/eZ/Publish/Core/Specification/Content/ContentTypeSpecification.php +++ b/eZ/Publish/SPI/Specification/Content/ContentTypeSpecification.php @@ -6,12 +6,11 @@ */ declare(strict_types=1); -namespace eZ\Publish\Core\Specification\Content; +namespace eZ\Publish\SPI\Specification\Content; use eZ\Publish\API\Repository\Values\Content\Content; -use eZ\Publish\SPI\Specification\ContentSpecification; -class ContentTypeSpecification implements ContentSpecification +final class ContentTypeSpecification implements ContentSpecification { /** * @var string From 3f73954602dcb518e444984ab47c804684da6b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Fri, 10 Apr 2020 11:40:10 +0200 Subject: [PATCH 3/4] Implemented tests --- .../ContentContainerSpecificationTest.php | 64 +++++++++++++++ .../Content/ContentTypeSpecificationTest.php | 78 +++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php create mode 100644 eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php 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..f400a5ae81 --- /dev/null +++ b/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php @@ -0,0 +1,64 @@ +assertInstanceOf(ContentSpecification::class, $contentTypeSpecification); + } + + /** + * @covers \eZ\Publish\SPI\Specification\Content\ContentContainerSpecification::isSatisfiedBy + * @dataProvider isSatisfiedByProvider + */ + 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 static function isSatisfiedByProvider(): 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..96b72b5efb --- /dev/null +++ b/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php @@ -0,0 +1,78 @@ +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 isSatisfiedByProvider + */ + 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 static function isSatisfiedByProvider(): 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], + ]; + } +} From 434867ef73d9fabfc06a604428dd5cb7f9d94840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Myszka?= Date: Fri, 10 Apr 2020 12:01:43 +0200 Subject: [PATCH 4/4] After CR changes --- .../Content/ContentContainerSpecificationTest.php | 9 ++++----- .../Tests/Content/ContentTypeSpecificationTest.php | 11 +++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php b/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php index f400a5ae81..5cb5b883d0 100644 --- a/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php +++ b/eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php @@ -10,9 +10,9 @@ use eZ\Publish\API\Repository\Values\Content\Content; use eZ\Publish\API\Repository\Values\ContentType\ContentType; -use eZ\Publish\Core\Search\Tests\TestCase; use eZ\Publish\SPI\Specification\Content\ContentContainerSpecification; use eZ\Publish\SPI\Specification\Content\ContentSpecification; +use PHPUnit\Framework\TestCase; /** * @covers \eZ\Publish\SPI\Specification\Content\ContentContainerSpecification @@ -28,13 +28,12 @@ public function testConstructor(): void /** * @covers \eZ\Publish\SPI\Specification\Content\ContentContainerSpecification::isSatisfiedBy - * @dataProvider isSatisfiedByProvider + * @dataProvider providerForIsSatisfiedBy */ public function testIsSatisfiedBy( bool $isContainer, bool $shouldBeSatisfied - ): void - { + ): void { $contentContainerSpecification = new ContentContainerSpecification(); $contentTypeMock = $this->getMockBuilder(ContentType::class) @@ -54,7 +53,7 @@ public function testIsSatisfiedBy( ); } - public static function isSatisfiedByProvider(): array + public function providerForIsSatisfiedBy(): array { return [ [true, true], diff --git a/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php b/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php index 96b72b5efb..1b48cf9e2c 100644 --- a/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php +++ b/eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php @@ -10,9 +10,9 @@ use eZ\Publish\API\Repository\Values\Content\Content; use eZ\Publish\API\Repository\Values\ContentType\ContentType; -use eZ\Publish\Core\Search\Tests\TestCase; use eZ\Publish\SPI\Specification\Content\ContentSpecification; use eZ\Publish\SPI\Specification\Content\ContentTypeSpecification; +use PHPUnit\Framework\TestCase; final class ContentTypeSpecificationTest extends TestCase { @@ -30,7 +30,7 @@ public function testConstructorWithExistingContentTypeIdentifier(): void public function testConstructorWithNotExistingContentTypeIdentifier(): void { - $contentTypeSpecification= new ContentTypeSpecification( + $contentTypeSpecification = new ContentTypeSpecification( self::NOT_EXISTING_CONTENT_TYPE_IDENTIFIER ); @@ -39,14 +39,13 @@ public function testConstructorWithNotExistingContentTypeIdentifier(): void /** * @covers \eZ\Publish\SPI\Specification\Content\ContentTypeSpecification::isSatisfiedBy - * @dataProvider isSatisfiedByProvider + * @dataProvider providerForIsSatisfiedBy */ public function testIsSatisfiedBy( string $contentTypeSpecificationIdentifier, string $contentTypeIdentifier, bool $shouldBeSatisfied - ): void - { + ): void { $contentTypeSpecification = new ContentTypeSpecification( $contentTypeSpecificationIdentifier ); @@ -68,7 +67,7 @@ public function testIsSatisfiedBy( ); } - public static function isSatisfiedByProvider(): array + public function providerForIsSatisfiedBy(): array { return [ [self::EXISTING_CONTENT_TYPE_IDENTIFIER, self::EXISTING_CONTENT_TYPE_IDENTIFIER, true],