-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3ef7a6f
commit 492324b
Showing
5 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
eZ/Publish/SPI/Specification/Content/ContentContainerSpecification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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\SPI\Specification\Content; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
|
||
final class ContentContainerSpecification implements ContentSpecification | ||
{ | ||
public function isSatisfiedBy(Content $content): bool | ||
{ | ||
return $content->getContentType()->isContainer; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
eZ/Publish/SPI/Specification/Content/ContentSpecification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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\SPI\Specification\Content; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
|
||
interface ContentSpecification | ||
{ | ||
public function isSatisfiedBy(Content $content): bool; | ||
} |
29 changes: 29 additions & 0 deletions
29
eZ/Publish/SPI/Specification/Content/ContentTypeSpecification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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\SPI\Specification\Content; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
|
||
final class ContentTypeSpecification implements ContentSpecification | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $expectedType; | ||
|
||
public function __construct(string $expectedType) | ||
{ | ||
$this->expectedType = $expectedType; | ||
} | ||
|
||
public function isSatisfiedBy(Content $content): bool | ||
{ | ||
return $content->getContentType()->identifier === $this->expectedType; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
eZ/Publish/SPI/Specification/Tests/Content/ContentContainerSpecificationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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\SPI\Specification\Tests\Content; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
use eZ\Publish\API\Repository\Values\ContentType\ContentType; | ||
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 | ||
*/ | ||
final class ContentContainerSpecificationTest extends TestCase | ||
{ | ||
public function testConstructor(): void | ||
{ | ||
$contentTypeSpecification = new ContentContainerSpecification(); | ||
|
||
$this->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], | ||
]; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
eZ/Publish/SPI/Specification/Tests/Content/ContentTypeSpecificationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?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\SPI\Specification\Tests\Content; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
use eZ\Publish\API\Repository\Values\ContentType\ContentType; | ||
use eZ\Publish\SPI\Specification\Content\ContentSpecification; | ||
use eZ\Publish\SPI\Specification\Content\ContentTypeSpecification; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ContentTypeSpecificationTest extends TestCase | ||
{ | ||
private const EXISTING_CONTENT_TYPE_IDENTIFIER = 'article'; | ||
private const NOT_EXISTING_CONTENT_TYPE_IDENTIFIER = 'Some-Not-Existing-CT-Identifier'; | ||
|
||
public function testConstructorWithExistingContentTypeIdentifier(): void | ||
{ | ||
$contentTypeSpecification = new ContentTypeSpecification( | ||
self::EXISTING_CONTENT_TYPE_IDENTIFIER | ||
); | ||
|
||
$this->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], | ||
]; | ||
} | ||
} |