From 7db612c956d5ab70157289d7e6c6e06698b4b8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 8 Aug 2018 06:39:18 +0200 Subject: [PATCH] Refactor integration tests to use fixtures generated on the fly --- lib/Core/Site/Settings.php | 20 + phpunit-integration-legacy.xml | 1 + tests/lib/Integration/BaseTest.php | 653 ++----------- .../lib/Integration/FilterServiceBaseTest.php | 103 -- tests/lib/Integration/FilterServiceTest.php | 388 ++++++-- tests/lib/Integration/FindServiceBaseTest.php | 139 --- tests/lib/Integration/FindServiceTest.php | 458 +++++++-- tests/lib/Integration/LoadServiceBaseTest.php | 109 --- tests/lib/Integration/LoadServiceTest.php | 898 ++++++++++++++---- tests/lib/Integration/PrepareFixturesTest.php | 207 ++++ tests/lib/Integration/RelationServiceTest.php | 33 + tests/lib/Integration/SiteTest.php | 7 + 12 files changed, 1764 insertions(+), 1252 deletions(-) delete mode 100644 tests/lib/Integration/FilterServiceBaseTest.php delete mode 100644 tests/lib/Integration/FindServiceBaseTest.php delete mode 100644 tests/lib/Integration/LoadServiceBaseTest.php create mode 100644 tests/lib/Integration/PrepareFixturesTest.php diff --git a/lib/Core/Site/Settings.php b/lib/Core/Site/Settings.php index 691dc97f..ee3ee063 100644 --- a/lib/Core/Site/Settings.php +++ b/lib/Core/Site/Settings.php @@ -35,6 +35,13 @@ public function __construct($prioritizedLanguages, $useAlwaysAvailable, $rootLoc $this->rootLocationId = $rootLocationId; } + /** + * @throws \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException + * + * @param $property + * + * @return bool|int|string|string[] + */ public function __get($property) { switch ($property) { @@ -49,11 +56,24 @@ public function __get($property) throw new PropertyNotFoundException($property, get_class($this)); } + /** + * @throws \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException + * + * @param $property + * @param $value + */ public function __set($property, $value) { throw new PropertyReadOnlyException($property, get_class($this)); } + /** + * @throws \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException + * + * @param $property + * + * @return bool + */ public function __isset($property) { switch ($property) { diff --git a/phpunit-integration-legacy.xml b/phpunit-integration-legacy.xml index 6e43c54b..173307b8 100644 --- a/phpunit-integration-legacy.xml +++ b/phpunit-integration-legacy.xml @@ -12,6 +12,7 @@ + tests/lib/Integration/PrepareFixturesTest.php tests/lib/Integration/SiteTest.php tests/lib/Integration/FilterServiceTest.php tests/lib/Integration/FindServiceTest.php diff --git a/tests/lib/Integration/BaseTest.php b/tests/lib/Integration/BaseTest.php index 3ad77a08..49f4f7e9 100644 --- a/tests/lib/Integration/BaseTest.php +++ b/tests/lib/Integration/BaseTest.php @@ -2,557 +2,98 @@ namespace Netgen\EzPlatformSiteApi\Tests\Integration; -use DateTime; +use ArrayIterator; use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException; use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; +use eZ\Publish\API\Repository\Values\Content\Content as APIContent; +use eZ\Publish\API\Repository\Values\Content\Field as APIField; use eZ\Publish\API\Repository\Values\Content\Location as APILocation; use Netgen\EzPlatformSiteApi\API\Values\Content; +use Netgen\EzPlatformSiteApi\API\Values\ContentInfo as APIContentInfo; +use Netgen\EzPlatformSiteApi\API\Values\Location; +use Netgen\EzPlatformSiteApi\API\Values\Field; +use eZ\Publish\SPI\FieldType\Value; +use eZ\Publish\API\Repository\Values\Content\ContentInfo; +use eZ\Publish\API\Repository\Values\ContentType\ContentType; +use eZ\Publish\API\Repository\Values\User\User; +use eZ\Publish\API\Repository\Values\Content\VersionInfo; +use ReflectionProperty; /** * Base class for API integration tests. */ class BaseTest extends APIBaseTest { - public function getPrimaryLanguageMatchData() + public function getData($languageCode) { - $data = [ - 'name' => 'Contact Us', - 'contentId' => 58, - 'contentRemoteId' => 'f8cc7a4cf8a964a1a0ea6666f5da7d0d', - 'locationId' => 60, - 'locationRemoteId' => '86bf306624668ee9b8b979b0d56f7e0d', - 'parentLocationId' => 2, - 'locationPriority' => -2, + return [ + 'name' => $languageCode, + 'contentId' => 61, + 'contentRemoteId' => 'content-remote-id', + 'locationId' => 63, + 'locationRemoteId' => 'location-remote-id', + 'parentLocationId' => 62, + 'locationPriority' => 1, 'locationHidden' => false, 'locationInvisible' => false, - 'locationPathString' => '/1/2/60/', - 'locationPath' => [1, 2, 60], - 'locationDepth' => 2, - 'locationSortField' => APILocation::SORT_FIELD_PRIORITY, - 'locationSortOrder' => APILocation::SORT_ORDER_ASC, - 'contentTypeIdentifier' => 'feedback_form', - 'contentTypeId' => 20, + 'locationPathString' => '/1/2/62/63/', + 'locationPath' => [1, 2, 62, 63], + 'locationDepth' => 3, + 'locationSortField' => APILocation::SORT_FIELD_NODE_ID, + 'locationSortOrder' => APILocation::SORT_ORDER_DESC, + 'contentTypeIdentifier' => 'test-type', + 'contentTypeId' => 37, 'sectionId' => 1, 'currentVersionNo' => 1, 'published' => true, 'ownerId' => 14, - 'modificationDateTimestamp' => 1332927282, - 'publishedDateTimestamp' => 1332927205, - 'alwaysAvailable' => false, - 'mainLanguageCode' => 'eng-GB', - 'mainLocationId' => 60, - 'contentTypeName' => 'Feedback form', - 'contentTypeDescription' => '', - 'languageCode' => 'eng-GB', - 'fields' => [ - 'description' => [ - 'name' => 'Description', - 'description' => null, - 'fieldTypeIdentifier' => 'ezrichtext', - 'isEmpty' => false, - ], - 'email' => [ - 'name' => 'Email', - 'description' => null, - 'fieldTypeIdentifier' => 'ezemail', - 'isEmpty' => false, - ], - 'message' => [ - 'name' => 'Message', - 'description' => null, - 'fieldTypeIdentifier' => 'eztext', - 'isEmpty' => false, - ], - 'name' => [ - 'name' => 'Name', - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'recipient' => [ - 'name' => 'Recipient', - 'description' => null, - 'fieldTypeIdentifier' => 'ezemail', - 'isEmpty' => false, - ], - 'sender_name' => [ - 'name' => 'Sender name', - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'subject' => [ - 'name' => 'Subject', - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - ], - 'isFound' => true, - ]; - - return [ - 0 => [ - $data, - ], - ]; - } - - public function getSecondaryLanguageMatchData() - { - $data = [ - 'name' => 'Das Titel', - 'contentId' => 54, - 'contentRemoteId' => '8b8b22fe3c6061ed500fbd2b377b885f', - 'locationId' => 56, - 'locationRemoteId' => '772da20ecf88b3035d73cbdfcea0f119', - 'parentLocationId' => 58, - 'locationPriority' => 0, - 'locationHidden' => false, - 'locationInvisible' => false, - 'locationPathString' => '/1/58/56/', - 'locationPath' => [1, 58, 56], - 'locationDepth' => 2, - 'locationSortField' => APILocation::SORT_FIELD_PATH, - 'locationSortOrder' => APILocation::SORT_ORDER_ASC, - 'contentTypeIdentifier' => 'template_look', - 'contentTypeId' => 15, - 'sectionId' => 5, - 'currentVersionNo' => 3, - 'published' => true, - 'ownerId' => 14, 'modificationDateTimestamp' => 100, - 'publishedDateTimestamp' => 1082016652, - 'alwaysAvailable' => false, - 'mainLanguageCode' => 'eng-US', - 'mainLocationId' => 56, - 'contentTypeName' => '', - 'contentTypeDescription' => '', - 'languageCode' => 'ger-DE', - 'fields' => [ - 'email' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - 'footer_script' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'eztext', - 'isEmpty' => true, - ], - 'footer_text' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'eztext', - 'isEmpty' => true, - ], - 'hide_powered_by' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezboolean', - 'isEmpty' => true, - ], - 'image' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezimage', - 'isEmpty' => true, - ], - 'login_label' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => true, - ], - 'logout_label' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => true, - ], - 'meta_data' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - 'my_profile_label' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'register_user_label' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => true, - ], - 'rss_feed' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => true, - ], - 'shopping_basket_label' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => true, - ], - 'site_map_url' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezurl', - 'isEmpty' => true, - ], - 'site_settings_label' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => true, - ], - 'sitestyle' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezpackage', - 'isEmpty' => true, - ], - 'siteurl' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - 'tag_cloud_url' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezurl', - 'isEmpty' => true, - ], - 'title' => [ - 'name' => null, - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - ], - 'isFound' => true, - ]; - - return [ - 0 => [ - $data, - ], - ]; - } - - public function getExplicitVersionAndLanguageMatchData() - { - $data = [ - 'name' => 'eZ Publish Demo Design (without demo content)', - 'contentId' => 54, - 'contentRemoteId' => '8b8b22fe3c6061ed500fbd2b377b885f', - 'locationId' => 56, - 'locationRemoteId' => '772da20ecf88b3035d73cbdfcea0f119', - 'parentLocationId' => 58, - 'locationPriority' => 0, - 'locationHidden' => false, - 'locationInvisible' => false, - 'locationPathString' => '/1/58/56/', - 'locationPath' => [1, 58, 56], - 'locationDepth' => 2, - 'locationSortField' => APILocation::SORT_FIELD_PATH, - 'locationSortOrder' => APILocation::SORT_ORDER_ASC, - 'contentTypeIdentifier' => 'template_look', - 'contentTypeId' => 15, - 'sectionId' => 5, - 'currentVersionNo' => 3, - 'published' => true, - 'ownerId' => 14, - 'modificationDateTimestamp' => 100, - 'publishedDateTimestamp' => 1082016652, - 'alwaysAvailable' => false, - 'mainLanguageCode' => 'eng-US', - 'mainLocationId' => 56, - 'contentTypeName' => 'Template look', - 'contentTypeDescription' => '', - 'languageCode' => 'eng-US', + 'publishedDateTimestamp' => 101, + 'alwaysAvailable' => true, + 'mainLanguageCode' => 'eng-GB', + 'mainLocationId' => 63, + 'contentTypeName' => 'Test type', + 'contentTypeDescription' => 'A test type', + 'languageCode' => $languageCode, 'fields' => [ - 'email' => [ - 'name' => 'Email', - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - 'footer_script' => [ - 'name' => 'Footer Javascript', - 'description' => '', - 'fieldTypeIdentifier' => 'eztext', - 'isEmpty' => true, - ], - 'footer_text' => [ - 'name' => 'Footer text', - 'description' => '', - 'fieldTypeIdentifier' => 'eztext', - 'isEmpty' => false, - ], - 'hide_powered_by' => [ - 'name' => 'Hide "Powered by"', - 'description' => '', - 'fieldTypeIdentifier' => 'ezboolean', - 'isEmpty' => true, - ], - 'image' => [ - 'name' => 'Image', - 'description' => null, - 'fieldTypeIdentifier' => 'ezimage', - 'isEmpty' => false, - ], - 'login_label' => [ - 'name' => 'Login (label)', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'logout_label' => [ - 'name' => 'Logout (label)', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'meta_data' => [ - 'name' => 'Meta data', - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - 'my_profile_label' => [ - 'name' => 'My profile (label)', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'register_user_label' => [ - 'name' => 'Register new user (label)', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'rss_feed' => [ - 'name' => 'RSS feed', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'shopping_basket_label' => [ - 'name' => 'Shopping basket (label)', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'site_map_url' => [ - 'name' => 'Site map URL', - 'description' => '', - 'fieldTypeIdentifier' => 'ezurl', - 'isEmpty' => false, - ], - 'site_settings_label' => [ - 'name' => 'Site settings (label)', - 'description' => '', - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - 'sitestyle' => [ - 'name' => 'Sitestyle', - 'description' => null, - 'fieldTypeIdentifier' => 'ezpackage', - 'isEmpty' => true, - ], - 'siteurl' => [ - 'name' => 'Site URL', - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - 'tag_cloud_url' => [ - 'name' => 'Tag Cloud URL', - 'description' => '', - 'fieldTypeIdentifier' => 'ezurl', - 'isEmpty' => false, - ], 'title' => [ 'name' => 'Title', - 'description' => null, - 'fieldTypeIdentifier' => 'ezinisetting', - 'isEmpty' => true, - ], - ], - 'isFound' => true, - 'loadVersionNo' => 2, - 'loadLanguageCode' => 'eng-US', - ]; - - return [ - 0 => [ - $data, - ], - ]; - } - - public function getAlwaysAvailableLanguageMatchData() - { - $data = [ - 'name' => 'Users', - 'contentId' => 4, - 'contentRemoteId' => 'f5c88a2209584891056f987fd965b0ba', - 'locationId' => 5, - 'locationRemoteId' => '3f6d92f8044aed134f32153517850f5a', - 'parentLocationId' => 1, - 'locationPriority' => 0, - 'locationHidden' => false, - 'locationInvisible' => false, - 'locationPathString' => '/1/5/', - 'locationPath' => [1, 5], - 'locationDepth' => 1, - 'locationSortField' => APILocation::SORT_FIELD_PATH, - 'locationSortOrder' => APILocation::SORT_ORDER_ASC, - 'contentTypeIdentifier' => 'user_group', - 'contentTypeId' => 3, - 'sectionId' => 2, - 'currentVersionNo' => 1, - 'published' => true, - 'ownerId' => 14, - 'modificationDateTimestamp' => 1033917596, - 'publishedDateTimestamp' => 1033917596, - 'alwaysAvailable' => true, - 'mainLanguageCode' => 'eng-US', - 'mainLocationId' => 5, - 'contentTypeName' => 'User group', - 'contentTypeDescription' => '', - 'languageCode' => 'eng-US', - 'fields' => [ - 'description' => [ - 'name' => 'Description', - 'description' => null, + 'description' => 'Title of the test type', 'fieldTypeIdentifier' => 'ezstring', + 'value' => $languageCode, 'isEmpty' => false, ], - 'name' => [ - 'name' => 'Name', - 'description' => null, - 'fieldTypeIdentifier' => 'ezstring', - 'isEmpty' => false, - ], - ], - 'isFound' => true, - ]; - - return [ - 0 => [ - $data, ], ]; } - public function getNoLanguageMatchData() + /** + * @throws \ReflectionException + * @throws \ErrorException + * + * @param string $name + * @param mixed $value + */ + protected function overrideSettings($name, $value) { - $data = [ - 'name' => 'Common INI settings', - 'contentId' => 52, - 'contentRemoteId' => '27437f3547db19cf81a33c92578b2c89', - 'locationId' => 54, - 'locationRemoteId' => 'fa9f3cff9cf90ecfae335718dcbddfe2', - 'parentLocationId' => null, - 'locationPriority' => null, - 'locationHidden' => null, - 'locationInvisible' => null, - 'locationPathString' => null, - 'locationPath' => null, - 'locationDepth' => null, - 'locationSortField' => null, - 'locationSortOrder' => null, - 'contentTypeIdentifier' => null, - 'contentTypeId' => null, - 'sectionId' => null, - 'currentVersionNo' => null, - 'published' => null, - 'ownerId' => null, - 'modificationDateTimestamp' => null, - 'publishedDateTimestamp' => null, - 'alwaysAvailable' => null, - 'mainLanguageCode' => null, - 'mainLocationId' => null, - 'contentTypeName' => null, - 'contentTypeDescription' => null, - 'languageCode' => null, - 'fields' => null, - 'isFound' => false, - ]; + $settings = $this->getSite()->getSettings(); - return [ - 0 => [ - $data, - ], - ]; + $property = new ReflectionProperty(get_class($settings), $name); + $property->setAccessible(true); + $property->setValue($settings, $value); } /** + * @throws \ErrorException + * * @return \Netgen\EzPlatformSiteApi\API\Site */ protected function getSite() { - return $this->getSetupFactory()->getServiceContainer()->get('netgen.ezplatform_site.site'); - } + /** @var \Netgen\EzPlatformSiteApi\API\Site $site */ + $site = $this->getSetupFactory()->getServiceContainer()->get('netgen.ezplatform_site.site'); - protected function doTestLoadContent($data) - { - list(, $contentId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $content = $loadService->loadContent($contentId); - $this->assertContent($content, $data); - } - - protected function doTestLoadContentByRemoteId($data) - { - list(, , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $content = $loadService->loadContentByRemoteId($remoteId); - $this->assertContent($content, $data); - } - - protected function doTestLoadContentInfo($data) - { - list(, $contentId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $contentInfo = $loadService->loadContentInfo($contentId); - $this->assertContentInfo($contentInfo, $data); - } - - protected function doTestLoadContentInfoByRemoteId($data) - { - list(, , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $contentInfo = $loadService->loadContentInfoByRemoteId($remoteId); - $this->assertContentInfo($contentInfo, $data); - } - - protected function doTestLoadLocation($data) - { - list(, , , $locationId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $location = $loadService->loadLocation($locationId); - $this->assertLocation($location, $data); - } - - protected function doTestLoadLocationByRemoteId($data) - { - list(, , , , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $location = $loadService->loadLocationByRemoteId($remoteId); - $this->assertLocation($location, $data); + return $site; } protected function assertContent($content, $data) @@ -560,7 +101,7 @@ protected function assertContent($content, $data) list($name, $contentId, , $locationId) = array_values($data); /** @var \Netgen\EzPlatformSiteApi\API\Values\Content $content */ - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Content', $content); + $this->assertInstanceOf(Content::class, $content); $this->assertSame($contentId, $content->id); $this->assertSame($locationId, $content->mainLocationId); @@ -569,12 +110,19 @@ protected function assertContent($content, $data) $this->assertEquals($data['languageCode'], $content->languageCode); $this->assertContentInfo($content->contentInfo, $data); $this->assertFields($content, $data); - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Content', $content->owner); - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Location', $content->mainLocation); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\User\User', $content->innerOwnerUser); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\Content\Content', $content->innerContent); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\Content\VersionInfo', $content->versionInfo); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\Content\VersionInfo', $content->innerVersionInfo); + $this->assertInstanceOf(Content::class, $content->owner); + $this->assertInstanceOf(Location::class, $content->mainLocation); + $this->assertInstanceOf(Content::class, $content->owner); + $this->assertInstanceOf(User::class, $content->innerOwnerUser); + $this->assertInstanceOf(User::class, $content->innerOwnerUser); + $this->assertInstanceOf(APIContent::class, $content->innerContent); + $this->assertInstanceOf(VersionInfo::class, $content->versionInfo); + $this->assertInstanceOf(VersionInfo::class, $content->innerVersionInfo); + + $locations = $content->getLocations(); + $this->assertInstanceOf(ArrayIterator::class, $locations); + $this->assertCount(1, $locations); + $this->assertInstanceOf(Location::class, reset($locations)); $this->assertTrue(isset($content->id)); $this->assertTrue(isset($content->name)); @@ -595,7 +143,7 @@ protected function assertContentInfo($contentInfo, $data) list($name, $contentId, $contentRemoteId, $locationId) = array_values($data); /** @var \Netgen\EzPlatformSiteApi\API\Values\ContentInfo $contentInfo */ - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\ContentInfo', $contentInfo); + $this->assertInstanceOf(APIContentInfo::class, $contentInfo); $this->assertEquals($contentId, $contentInfo->id); $this->assertEquals($contentRemoteId, $contentInfo->remoteId); @@ -615,10 +163,15 @@ protected function assertContentInfo($contentInfo, $data) $this->assertEquals($data['contentTypeName'], $contentInfo->contentTypeName); $this->assertEquals($data['contentTypeDescription'], $contentInfo->contentTypeDescription); $this->assertEquals($data['languageCode'], $contentInfo->languageCode); - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Content', $contentInfo->content); - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Location', $contentInfo->mainLocation); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\Content\ContentInfo', $contentInfo->innerContentInfo); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\ContentType\ContentType', $contentInfo->innerContentType); + $this->assertInstanceOf(Content::class, $contentInfo->content); + $this->assertInstanceOf(Location::class, $contentInfo->mainLocation); + $this->assertInstanceOf(ContentInfo::class, $contentInfo->innerContentInfo); + $this->assertInstanceOf(ContentType::class, $contentInfo->innerContentType); + + $locations = $contentInfo->getLocations(); + $this->assertInstanceOf(ArrayIterator::class, $locations); + $this->assertCount(1, $locations); + $this->assertInstanceOf(Location::class, reset($locations)); $this->assertTrue(isset($contentInfo->name)); $this->assertTrue(isset($contentInfo->contentTypeIdentifier)); @@ -642,9 +195,9 @@ protected function assertFields(Content $content, $data) $this->assertCount(count($data['fields']), $content->fields); foreach ($content->fields as $identifier => $field) { - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Field', $field); - $this->assertInstanceOf('\eZ\Publish\SPI\FieldType\Value', $field->value); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\Content\Field', $field->innerField); + $this->assertInstanceOf(Field::class, $field); + $this->assertInstanceOf(Value::class, $field->value); + $this->assertInstanceOf(APIField::class, $field->innerField); $fieldById = $content->getFieldById($field->id); $fieldByIdentifier = $content->getField($identifier); @@ -659,16 +212,18 @@ protected function assertFields(Content $content, $data) $this->assertSame($fieldValueById, $fieldValueByIdentifier); $this->assertSame($content, $field->content); + + $this->assertSame($data['fields'][$identifier]['value'], (string)$field->value); } foreach ($data['fields'] as $identifier => $fieldData) { $this->assertField($content, $identifier, $data['languageCode'], $fieldData); } - $content->getField('non_existent_field'); - $content->getFieldById('non_existent_field'); - $content->getFieldValue('non_existent_field'); - $content->getFieldValueById('non_existent_field'); + $this->assertNull($content->getField('non_existent_field')); + $this->assertNull($content->getFieldById('non_existent_field')); + $this->assertNull($content->getFieldValue('non_existent_field')); + $this->assertNull($content->getFieldValueById('non_existent_field')); } protected function assertField(Content $content, $identifier, $languageCode, $data) @@ -703,7 +258,7 @@ protected function assertLocation($location, $data) list(, , , $locationId, $locationRemoteId, $parentLocationId) = array_values($data); /** @var \Netgen\EzPlatformSiteApi\API\Values\Location $location */ - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Location', $location); + $this->assertInstanceOf(Location::class, $location); $this->assertEquals($locationId, $location->id); $this->assertEquals($locationRemoteId, $location->remoteId); @@ -719,7 +274,12 @@ protected function assertLocation($location, $data) $this->assertEquals($data['locationSortOrder'], $location->sortOrder); $this->assertEquals($location->contentInfo->id, $location->contentId); $this->assertContentInfo($location->contentInfo, $data); - $this->assertInstanceOf('\eZ\Publish\API\Repository\Values\Content\Location', $location->innerLocation); + $this->assertInstanceOf(APILocation::class, $location->innerLocation); + $this->assertInstanceOf(Content::class, $location->content); + + if ($location->parentLocationId !== 1) { + $this->assertInstanceOf(Location::class, $location->parent); + } $this->assertTrue(isset($location->contentId)); $this->assertTrue(isset($location->contentInfo)); @@ -732,29 +292,4 @@ protected function assertLocation($location, $data) // Do nothing } } - - protected function createSecondaryTranslationFallback() - { - $templateLookContentTypeId = 15; - $contentTypeService = $this->getRepository()->getContentTypeService(); - $contentType = $contentTypeService->loadContentType($templateLookContentTypeId); - $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType); - $contentTypeUpdateStruct = $contentTypeService->newContentTypeUpdateStruct(); - $contentTypeUpdateStruct->nameSchema = ''; - $contentTypeService->updateContentTypeDraft($contentTypeDraft, $contentTypeUpdateStruct); - $contentTypeService->publishContentTypeDraft($contentTypeDraft); - - $demoDesignContentId = 54; - $contentService = $this->getRepository()->getContentService(); - $contentInfo = $contentService->loadContentInfo($demoDesignContentId); - $draft = $contentService->createContentDraft($contentInfo); - $contentUpdateStruct = $contentService->newContentUpdateStruct(); - $contentUpdateStruct->setField('my_profile_label', 'Das Titel', 'ger-DE'); - $updatedDraft = $contentService->updateContent($draft->versionInfo, $contentUpdateStruct); - $content = $contentService->publishVersion($updatedDraft->versionInfo); - - $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); - $contentMetadataUpdateStruct->modificationDate = new DateTime('@100'); - $contentService->updateContentMetadata($content->contentInfo, $contentMetadataUpdateStruct); - } } diff --git a/tests/lib/Integration/FilterServiceBaseTest.php b/tests/lib/Integration/FilterServiceBaseTest.php deleted file mode 100644 index a1e259ba..00000000 --- a/tests/lib/Integration/FilterServiceBaseTest.php +++ /dev/null @@ -1,103 +0,0 @@ -getSite()->getFilterService(); - $query = new Query( - [ - 'filter' => new Query\Criterion\ContentId($contentId), - ] - ); - - $searchResult = $filterService->filterContent($query); - - $this->assertContentSearchResult($searchResult, $data); - } - - protected function doTestFilterContentInfo($data) - { - list(, $contentId) = array_values($data); - $filterService = $this->getSite()->getFilterService(); - $query = new Query( - [ - 'filter' => new Query\Criterion\ContentId($contentId), - ] - ); - - $searchResult = $filterService->filterContentInfo($query); - - $this->assertContentInfoSearchResult($searchResult, $data); - } - - protected function doTestFilterLocations($data) - { - list(, , , $locationId) = array_values($data); - $filterService = $this->getSite()->getFilterService(); - $query = new LocationQuery( - [ - 'filter' => new Query\Criterion\LocationId($locationId), - ] - ); - - $searchResult = $filterService->filterLocations($query); - - $this->assertLocationSearchResult($searchResult, $data); - } - - protected function assertContentSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertContent($searchResult->searchHits[0]->valueObject, $data); - } - - protected function assertContentInfoSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertContentInfo($searchResult->searchHits[0]->valueObject, $data); - } - - protected function assertLocationSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertLocation($searchResult->searchHits[0]->valueObject, $data); - } -} diff --git a/tests/lib/Integration/FilterServiceTest.php b/tests/lib/Integration/FilterServiceTest.php index 317910ca..b8eed221 100644 --- a/tests/lib/Integration/FilterServiceTest.php +++ b/tests/lib/Integration/FilterServiceTest.php @@ -2,6 +2,11 @@ namespace Netgen\EzPlatformSiteApi\Tests\Integration; +use eZ\Publish\API\Repository\Values\Content\LocationQuery; +use eZ\Publish\API\Repository\Values\Content\Query; +use eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentId; +use eZ\Publish\API\Repository\Values\Content\Search\SearchResult; + /** * Test case for the FilterService. * @@ -10,179 +15,410 @@ * @group integration * @group filter */ -class FilterServiceTest extends FilterServiceBaseTest +class FilterServiceTest extends BaseTest { /** - * Test for the filterContent() method. + * Test for the findContent() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContent() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentMatchPrimaryLanguage($data) + public function testFilterContentMatchPrimaryLanguage() { - $this->doTestFilterContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('eng-GB'); + $searchResult = $filterService->filterContent( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentSearchResult($searchResult, $data); } /** - * Test for the filterContent() method. + * Test for the findContent() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContent() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentMatchSecondaryLanguage($data) + public function testFilterContentMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('ger-DE'); + $searchResult = $filterService->filterContent( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); - $this->doTestFilterContent($data); + $this->assertContentSearchResult($searchResult, $data); } /** - * Test for the filterContent() method. + * Test for the findContent() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContent() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentMatchAlwaysAvailableLanguage($data) + public function testFilterContentMatchAlwaysAvailableLanguage() { - $this->doTestFilterContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('eng-GB'); + $searchResult = $filterService->filterContent( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentSearchResult($searchResult, $data); } /** - * Test for the filterContent() method. + * Test for the findContent() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContent() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentTranslationNotMatched($data) + public function testFilterContentTranslationNotMatched() { - $this->doTestFilterContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $searchResult = $filterService->filterContent( + new Query([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); } /** - * Test for the filterContentInfo() method. + * Test for the findContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentInfoMatchPrimaryLanguage($data) + public function testFilterContentInfoMatchPrimaryLanguage() { - $this->doTestFilterContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('eng-GB'); + $searchResult = $filterService->filterContentInfo( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentInfoSearchResult($searchResult, $data); } /** - * Test for the filterContentInfo() method. + * Test for the findContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentInfoMatchSecondaryLanguage($data) + public function testFilterContentInfoMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); - $this->doTestFilterContentInfo($data); + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('ger-DE'); + $searchResult = $filterService->filterContentInfo( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentInfoSearchResult($searchResult, $data); } /** - * Test for the filterContentInfo() method. + * Test for the findContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentInfoMatchAlwaysAvailableLanguage($data) + public function testFilterContentInfoMatchAlwaysAvailableLanguage() { - $this->doTestFilterContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('eng-GB'); + $searchResult = $filterService->filterContentInfo( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentInfoSearchResult($searchResult, $data); } /** - * Test for the filterContentInfo() method. + * Test for the findContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterContentInfoTranslationNotMatched($data) + public function testFilterContentInfoTranslationNotMatched() { - $this->doTestFilterContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $searchResult = $filterService->filterContentInfo( + new Query([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); } /** - * Test for the filterLocations() method. + * Test for the findLocations() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterLocations() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterLocationsMatchPrimaryLanguage($data) + public function testFilterLocationsMatchPrimaryLanguage() { - $this->doTestFilterLocations($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('eng-GB'); + $searchResult = $filterService->filterLocations( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertLocationSearchResult($searchResult, $data); } /** - * Test for the filterLocations() method. + * Test for the findLocations() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterLocations() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterLocationsMatchSecondaryLanguage($data) + public function testFilterLocationsMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); - $this->doTestFilterLocations($data); + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('ger-DE'); + $searchResult = $filterService->filterLocations( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertLocationSearchResult($searchResult, $data); } /** - * Test for the filterLocations() method. + * Test for the findLocations() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterLocations() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterLocationsMatchAlwaysAvailableLanguage($data) + public function testFilterLocationsMatchAlwaysAvailableLanguage() { - $this->doTestFilterLocations($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $data = $this->getData('eng-GB'); + $searchResult = $filterService->filterLocations( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertLocationSearchResult($searchResult, $data); } /** - * Test for the filterLocations() method. + * Test for the findLocations() method. * - * @see \Netgen\EzPlatformSiteApi\API\FilterService::filterLocations() + * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFilterService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFilterLocationsTranslationNotMatched($data) + public function testFilterLocationsTranslationNotMatched() { - $this->doTestFilterLocations($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $filterService = $this->getSite()->getFilterService(); + + $searchResult = $filterService->filterLocations( + new LocationQuery([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); + } + + protected function assertContentSearchResult(SearchResult $searchResult, $data) + { + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertContent($searchResult->searchHits[0]->valueObject, $data); + } + + protected function assertContentInfoSearchResult(SearchResult $searchResult, $data) + { + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertContentInfo($searchResult->searchHits[0]->valueObject, $data); + } + + protected function assertLocationSearchResult(SearchResult $searchResult, $data) + { + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertLocation($searchResult->searchHits[0]->valueObject, $data); } } diff --git a/tests/lib/Integration/FindServiceBaseTest.php b/tests/lib/Integration/FindServiceBaseTest.php deleted file mode 100644 index e2730c84..00000000 --- a/tests/lib/Integration/FindServiceBaseTest.php +++ /dev/null @@ -1,139 +0,0 @@ -getSite()->getFindService(); - $query = new Query( - [ - 'filter' => new Query\Criterion\ContentId($contentId), - ] - ); - - $searchResult = $findService->findContent($query); - - $this->assertContentSearchResult($searchResult, $data); - } - - protected function doTestFindContentInfo($data) - { - list(, $contentId) = array_values($data); - $findService = $this->getSite()->getFindService(); - $query = new Query( - [ - 'filter' => new Query\Criterion\ContentId($contentId), - ] - ); - - $searchResult = $findService->findContentInfo($query); - - $this->assertContentInfoSearchResult($searchResult, $data); - } - - protected function doTestFindLocations($data) - { - list(, , , $locationId) = array_values($data); - $findService = $this->getSite()->getFindService(); - $query = new LocationQuery( - [ - 'filter' => new Query\Criterion\LocationId($locationId), - ] - ); - - $searchResult = $findService->findLocations($query); - - $this->assertLocationSearchResult($searchResult, $data); - } - - protected function doTestFindNodes($data) - { - list(, , , $locationId) = array_values($data); - $findService = $this->getSite()->getFindService(); - $query = new LocationQuery( - [ - 'filter' => new Query\Criterion\LocationId($locationId), - ] - ); - - $searchResult = $findService->findNodes($query); - - $this->assertNodeSearchResult($searchResult, $data); - } - - protected function assertContentSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertContent($searchResult->searchHits[0]->valueObject, $data); - } - - protected function assertContentInfoSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertContentInfo($searchResult->searchHits[0]->valueObject, $data); - } - - protected function assertLocationSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertLocation($searchResult->searchHits[0]->valueObject, $data); - } - - protected function assertNodeSearchResult(SearchResult $searchResult, $data) - { - if ($data['isFound'] === false) { - $this->assertSame(0, $searchResult->totalCount); - - return; - } - - $languageCode = $data['languageCode']; - - $this->assertSame(1, $searchResult->totalCount); - - /* @var \Netgen\EzPlatformSiteApi\API\Values\Node */ - $node = $searchResult->searchHits[0]->valueObject; - - $this->assertInstanceOf('\Netgen\EzPlatformSiteApi\API\Values\Node', $node); - $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); - $this->assertLocation($node, $data); - $this->assertContent($node->content, $data); - } -} diff --git a/tests/lib/Integration/FindServiceTest.php b/tests/lib/Integration/FindServiceTest.php index 63ee2dc2..266a4b1f 100644 --- a/tests/lib/Integration/FindServiceTest.php +++ b/tests/lib/Integration/FindServiceTest.php @@ -2,6 +2,12 @@ namespace Netgen\EzPlatformSiteApi\Tests\Integration; +use eZ\Publish\API\Repository\Values\Content\LocationQuery; +use eZ\Publish\API\Repository\Values\Content\Query; +use eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentId; +use eZ\Publish\API\Repository\Values\Content\Search\SearchResult; +use Netgen\EzPlatformSiteApi\API\Values\Node; + /** * Test case for the FindService. * @@ -10,237 +16,551 @@ * @group integration * @group find */ -class FindServiceTest extends FindServiceBaseTest +class FindServiceTest extends BaseTest { /** * Test for the findContent() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentMatchPrimaryLanguage($data) + public function testFindContentMatchPrimaryLanguage() { - $this->doTestFindContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findContent( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentSearchResult($searchResult, $data); } /** * Test for the findContent() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentMatchSecondaryLanguage($data) + public function testFindContentMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); - $this->doTestFindContent($data); + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('ger-DE'); + $searchResult = $findService->findContent( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentSearchResult($searchResult, $data); } /** * Test for the findContent() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentMatchAlwaysAvailableLanguage($data) + public function testFindContentMatchAlwaysAvailableLanguage() { - $this->doTestFindContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findContent( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentSearchResult($searchResult, $data); } /** * Test for the findContent() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentTranslationNotMatched($data) + public function testFindContentTranslationNotMatched() { - $this->doTestFindContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $searchResult = $findService->findContent( + new Query([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); } /** * Test for the findContentInfo() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentInfoMatchPrimaryLanguage($data) + public function testFindContentInfoMatchPrimaryLanguage() { - $this->doTestFindContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findContentInfo( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentInfoSearchResult($searchResult, $data); } /** * Test for the findContentInfo() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentInfoMatchSecondaryLanguage($data) + public function testFindContentInfoMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); - $this->doTestFindContentInfo($data); + $data = $this->getData('ger-DE'); + $searchResult = $findService->findContentInfo( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentInfoSearchResult($searchResult, $data); } /** * Test for the findContentInfo() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentInfoMatchAlwaysAvailableLanguage($data) + public function testFindContentInfoMatchAlwaysAvailableLanguage() { - $this->doTestFindContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findContentInfo( + new Query([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertContentInfoSearchResult($searchResult, $data); } /** * Test for the findContentInfo() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findContentInfo() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindContentInfoTranslationNotMatched($data) + public function testFindContentInfoTranslationNotMatched() { - $this->doTestFindContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $searchResult = $findService->findContentInfo( + new Query([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); } /** * Test for the findLocations() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindLocationsMatchPrimaryLanguage($data) + public function testFindLocationsMatchPrimaryLanguage() { - $this->doTestFindLocations($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findLocations( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertLocationSearchResult($searchResult, $data); } /** * Test for the findLocations() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindLocationsMatchSecondaryLanguage($data) + public function testFindLocationsMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('ger-DE'); + $searchResult = $findService->findLocations( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); - $this->doTestFindLocations($data); + $this->assertLocationSearchResult($searchResult, $data); } /** * Test for the findLocations() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindLocationsMatchAlwaysAvailableLanguage($data) + public function testFindLocationsMatchAlwaysAvailableLanguage() { - $this->doTestFindLocations($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findLocations( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertLocationSearchResult($searchResult, $data); } /** * Test for the findLocations() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findLocations() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindLocationsTranslationNotMatched($data) + public function testFindLocationsTranslationNotMatched() { - $this->doTestFindLocations($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $searchResult = $findService->findLocations( + new LocationQuery([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); } /** * Test for the findNodes() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findNodes() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindNodesMatchPrimaryLanguage($data) + public function testFindNodesMatchPrimaryLanguage() { - $this->doTestFindNodes($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findNodes( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertNodeSearchResult($searchResult, $data); } /** * Test for the findNodes() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findNodes() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindNodesMatchSecondaryLanguage($data) + public function testFindNodesMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); - $this->doTestFindNodes($data); + $data = $this->getData('ger-DE'); + $searchResult = $findService->findNodes( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertNodeSearchResult($searchResult, $data); } /** * Test for the findNodes() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findNodes() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindNodesNodesMatchAlwaysAvailableLanguage($data) + public function testFindNodesNodesMatchAlwaysAvailableLanguage() { - $this->doTestFindNodes($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $data = $this->getData('eng-GB'); + $searchResult = $findService->findNodes( + new LocationQuery([ + 'filter' => new ContentId($data['contentId']), + ]) + ); + + $this->assertNodeSearchResult($searchResult, $data); } /** * Test for the findNodes() method. * * @see \Netgen\EzPlatformSiteApi\API\FindService::findNodes() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetFindService - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \ReflectionException + * @throws \ErrorException */ - public function testFindNodesTranslationNotMatched($data) + public function testFindNodesTranslationNotMatched() + { + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $findService = $this->getSite()->getFindService(); + + $searchResult = $findService->findNodes( + new LocationQuery([ + 'filter' => new ContentId(52), + ]) + ); + + $this->assertEquals(0, $searchResult->totalCount); + } + + protected function assertContentSearchResult(SearchResult $searchResult, $data) { - $this->doTestFindNodes($data); + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertContent($searchResult->searchHits[0]->valueObject, $data); + } + + protected function assertContentInfoSearchResult(SearchResult $searchResult, $data) + { + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertContentInfo($searchResult->searchHits[0]->valueObject, $data); + } + + protected function assertLocationSearchResult(SearchResult $searchResult, $data) + { + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertLocation($searchResult->searchHits[0]->valueObject, $data); + } + + protected function assertNodeSearchResult(SearchResult $searchResult, $data) + { + $languageCode = $data['languageCode']; + + $this->assertSame(1, $searchResult->totalCount); + + /* @var \Netgen\EzPlatformSiteApi\API\Values\Node */ + $node = $searchResult->searchHits[0]->valueObject; + + $this->assertInstanceOf(Node::class, $node); + $this->assertSame($languageCode, $searchResult->searchHits[0]->matchedTranslation); + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } } diff --git a/tests/lib/Integration/LoadServiceBaseTest.php b/tests/lib/Integration/LoadServiceBaseTest.php deleted file mode 100644 index 23f0e163..00000000 --- a/tests/lib/Integration/LoadServiceBaseTest.php +++ /dev/null @@ -1,109 +0,0 @@ -getSite()->getLoadService(); - $content = $loadService->loadContent($contentId); - $this->assertContent($content, $data); - } - - protected function doTestLoadContentInLanguage($data) - { - list(, $contentId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $loadService->loadContent($contentId, null, 'klingon'); - } - - protected function doTestLoadContentInExplicitVersionAndLanguage($data) - { - list(, $contentId) = array_values($data); - $versionNo = $data['loadVersionNo']; - $languageCode = $data['loadLanguageCode']; - $loadService = $this->getSite()->getLoadService(); - $content = $loadService->loadContent($contentId, $versionNo, $languageCode); - $this->assertContent($content, $data); - } - - protected function doTestLoadContentByRemoteId($data) - { - list(, , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $content = $loadService->loadContentByRemoteId($remoteId); - $this->assertContent($content, $data); - } - - protected function doTestLoadContentInfo($data) - { - list(, $contentId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $contentInfo = $loadService->loadContentInfo($contentId); - $this->assertContentInfo($contentInfo, $data); - } - - protected function doTestLoadContentInfoInLanguage($data) - { - list(, $contentId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $loadService->loadContentInfo($contentId, null, 'klingon'); - } - - protected function doTestLoadContentInfoInExplicitVersionAndLanguage($data) - { - list(, $contentId) = array_values($data); - $versionNo = $data['loadVersionNo']; - $languageCode = $data['loadLanguageCode']; - $loadService = $this->getSite()->getLoadService(); - $contentInfo = $loadService->loadContentInfo($contentId, $versionNo, $languageCode); - $this->assertContentInfo($contentInfo, $data); - } - - protected function doTestLoadContentInfoByRemoteId($data) - { - list(, , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $contentInfo = $loadService->loadContentInfoByRemoteId($remoteId); - $this->assertContentInfo($contentInfo, $data); - } - - protected function doTestLoadLocation($data) - { - list(, , , $locationId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $location = $loadService->loadLocation($locationId); - $this->assertLocation($location, $data); - } - - protected function doTestLoadLocationByRemoteId($data) - { - list(, , , , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $location = $loadService->loadLocationByRemoteId($remoteId); - $this->assertLocation($location, $data); - } - - protected function doTestLoadNode($data) - { - list(, , , $locationId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $node = $loadService->loadNode($locationId); - $this->assertLocation($node, $data); - $this->assertContent($node->content, $data); - } - - protected function doTestLoadNodeByRemoteId($data) - { - list(, , , , $remoteId) = array_values($data); - $loadService = $this->getSite()->getLoadService(); - $node = $loadService->loadNodeByRemoteId($remoteId); - $this->assertLocation($node, $data); - $this->assertContent($node->content, $data); - } -} diff --git a/tests/lib/Integration/LoadServiceTest.php b/tests/lib/Integration/LoadServiceTest.php index fc1d59ab..5c89ce0b 100644 --- a/tests/lib/Integration/LoadServiceTest.php +++ b/tests/lib/Integration/LoadServiceTest.php @@ -2,6 +2,8 @@ namespace Netgen\EzPlatformSiteApi\Tests\Integration; +use Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException; + /** * Test case for the LoadService. * @@ -10,535 +12,1037 @@ * @group integration * @group load */ -class LoadServiceTest extends LoadServiceBaseTest +class LoadServiceTest extends BaseTest { /** * Test for the loadContent() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentMatchPrimaryLanguage($data) + public function testLoadContentMatchPrimaryLanguage() { - $this->doTestLoadContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContent($data['contentId']); + + $this->assertContent($content, $data); } /** * Test for the loadContent() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentMatchSecondaryLanguage($data) + public function testLoadContentMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadContent($data); + $data = $this->getData('ger-DE'); + $content = $loadService->loadContent($data['contentId']); + + $this->assertContent($content, $data); } /** * Test for the loadContent() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentMatchAlwaysAvailableLanguage($data) + public function testLoadContentMatchAlwaysAvailableLanguage() { - $this->doTestLoadContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContent($data['contentId']); + + $this->assertContent($content, $data); } /** * Test for the loadContent() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getExplicitVersionAndLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInExplicitVersionAndLanguage($data) + public function testLoadContentInExplicitVersionAndLanguage() { - $this->doTestLoadContentInExplicitVersionAndLanguage($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('ger-DE'); + $content = $loadService->loadContent($data['contentId'], 1, 'ger-DE'); + + $this->assertContent($content, $data); } /** * Test for the loadContent() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentThrowsTranslationNotMatchedException($data) + public function testLoadContentThrowsTranslationNotMatchedException() { - $this->doTestLoadContent($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadContent(52); } /** * Test for the loadContent() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInLanguageThrowsTranslationNotMatchedException($data) + public function testLoadContentInLanguageThrowsTranslationNotMatchedException() { - $this->doTestLoadContentInLanguage($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $data = $this->getData('klingon'); + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadContent($data['contentId'], null, 'klingon'); } /** - * Test for the loadContent() method. + * Test for the loadContentByRemoteId() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentByRemoteIdMatchPrimaryLanguage($data) + public function testLoadContentByRemoteIdMatchPrimaryLanguage() { - $this->doTestLoadContentByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContentByRemoteId($data['contentRemoteId']); + + $this->assertContent($content, $data); } /** - * Test for the loadContent() method. + * Test for the loadContentByRemoteId() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentByRemoteIdMatchSecondaryLanguage($data) + public function testLoadContentByRemoteIdMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadContentByRemoteId($data); + $data = $this->getData('ger-DE'); + $content = $loadService->loadContentByRemoteId($data['contentRemoteId']); + + $this->assertContent($content, $data); } /** - * Test for the loadContent() method. + * Test for the loadContentByRemoteId() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentByRemoteIdMatchAlwaysAvailableLanguage($data) + public function testLoadContentByRemoteIdMatchAlwaysAvailableLanguage() { - $this->doTestLoadContentByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContentByRemoteId($data['contentRemoteId']); + + $this->assertContent($content, $data); } /** - * Test for the loadContent() method. + * Test for the loadContentByRemoteId() method. * * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentByRemoteIdThrowsTranslationNotMatchedException($data) + public function testLoadContentByRemoteIdThrowsTranslationNotMatchedException() { - $this->doTestLoadContentByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadContentByRemoteId('27437f3547db19cf81a33c92578b2c89'); } /** * Test for the loadContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoMatchPrimaryLanguage($data) + public function testLoadContentInfoMatchPrimaryLanguage() { - $this->doTestLoadContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContentInfo($data['contentId']); + + $this->assertContentInfo($content, $data); } /** * Test for the loadContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoMatchSecondaryLanguage($data) + public function testLoadContentInfoMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadContentInfo($data); + $data = $this->getData('ger-DE'); + $content = $loadService->loadContentInfo($data['contentId']); + + $this->assertContentInfo($content, $data); } /** * Test for the loadContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoMatchAlwaysAvailableLanguage($data) + public function testLoadContentInfoMatchAlwaysAvailableLanguage() { - $this->doTestLoadContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContentInfo($data['contentId']); + + $this->assertContentInfo($content, $data); } /** * Test for the loadContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getExplicitVersionAndLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoInExplicitVersionAndLanguage($data) + public function testLoadContentInfoInExplicitVersionAndLanguage() { - $this->doTestLoadContentInfoInExplicitVersionAndLanguage($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('ger-DE'); + $content = $loadService->loadContentInfo($data['contentId'], 1, 'ger-DE'); + + $this->assertContentInfo($content, $data); } /** * Test for the loadContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoThrowsTranslationNotMatchedException($data) + public function testLoadContentInfoThrowsTranslationNotMatchedException() { - $this->doTestLoadContentInfo($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadContentInfo(52); } /** * Test for the loadContentInfo() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoMissingLanguageThrowsTranslationNotMatchedException($data) + public function testLoadContentInfoInLanguageThrowsTranslationNotMatchedException() { - $this->doTestLoadContentInfoInLanguage($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $data = $this->getData('klingon'); + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadContentInfo($data['contentId'], null, 'klingon'); } /** - * Test for the loadContentInfo() method. + * Test for the loadContentInfoByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoByRemoteIdMatchPrimaryLanguage($data) + public function testLoadContentInfoByRemoteIdMatchPrimaryLanguage() { - $this->doTestLoadContentInfoByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContentInfoByRemoteId($data['contentRemoteId']); + + $this->assertContentInfo($content, $data); } /** - * Test for the loadContentInfo() method. + * Test for the loadContentInfoByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoByRemoteIdMatchSecondaryLanguage($data) + public function testLoadContentInfoByRemoteIdMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadContentInfoByRemoteId($data); + $data = $this->getData('ger-DE'); + $content = $loadService->loadContentInfoByRemoteId($data['contentRemoteId']); + + $this->assertContentInfo($content, $data); } /** - * Test for the loadContentInfo() method. + * Test for the loadContentInfoByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoByRemoteIdMatchAlwaysAvailableLanguage($data) + public function testLoadContentInfoByRemoteIdMatchAlwaysAvailableLanguage() { - $this->doTestLoadContentByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $content = $loadService->loadContentInfoByRemoteId($data['contentRemoteId']); + + $this->assertContentInfo($content, $data); } /** - * Test for the loadContentInfo() method. + * Test for the loadContentInfoByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContentInfo() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadContentInfoByRemoteIdThrowsTranslationNotMatchedException($data) + public function testLoadContentInfoByRemoteIdThrowsTranslationNotMatchedException() { - $this->doTestLoadContentByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadContentInfoByRemoteId('27437f3547db19cf81a33c92578b2c89'); } /** * Test for the loadLocation() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocation() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationMatchPrimaryLanguage($data) + public function testLoadLocationMatchPrimaryLanguage() { - $this->doTestLoadLocation($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $location = $loadService->loadLocation($data['locationId']); + + $this->assertLocation($location, $data); } /** * Test for the loadLocation() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocation() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationMatchSecondaryLanguage($data) + public function testLoadLocationMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadLocation($data); + $data = $this->getData('ger-DE'); + $location = $loadService->loadLocation($data['locationId']); + + $this->assertLocation($location, $data); } /** * Test for the loadLocation() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocation() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationMatchAlwaysAvailableLanguage($data) + public function testLoadLocationMatchAlwaysAvailableLanguage() { - $this->doTestLoadLocation($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $location = $loadService->loadLocation($data['locationId']); + + $this->assertLocation($location, $data); } /** * Test for the loadLocation() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocation() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationThrowsTranslationNotMatchedException($data) + public function testLoadLocationThrowsTranslationNotMatchedException() { - $this->doTestLoadLocation($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadLocation(54); } /** * Test for the loadLocationByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocationByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationByRemoteIdMatchPrimaryLanguage($data) + public function testLoadLocationByRemoteIdMatchPrimaryLanguage() { - $this->doTestLoadLocationByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $location = $loadService->loadLocationByRemoteId($data['locationRemoteId']); + + $this->assertLocation($location, $data); } /** * Test for the loadLocationByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocationByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationByRemoteIdMatchSecondaryLanguage($data) + public function testLoadLocationByRemoteIdMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadLocationByRemoteId($data); + $data = $this->getData('ger-DE'); + $location = $loadService->loadLocationByRemoteId($data['locationRemoteId']); + + $this->assertLocation($location, $data); } /** * Test for the loadLocationByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocationByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationByRemoteIdMatchAlwaysAvailableLanguage($data) + public function testLoadLocationByRemoteIdMatchAlwaysAvailableLanguage() { - $this->doTestLoadLocationByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $location = $loadService->loadLocationByRemoteId($data['locationRemoteId']); + + $this->assertLocation($location, $data); } /** * Test for the loadLocationByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadLocationByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadLocationByRemoteIdThrowsTranslationNotMatchedException($data) + public function testLoadLocationByRemoteIdThrowsTranslationNotMatchedException() { - $this->doTestLoadLocationByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadLocationByRemoteId('fa9f3cff9cf90ecfae335718dcbddfe2'); } /** * Test for the loadNode() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNode() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeMatchPrimaryLanguage($data) + public function testLoadNodeMatchPrimaryLanguage() { - $this->doTestLoadNode($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $node = $loadService->loadNode($data['locationId']); + + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } /** * Test for the loadNode() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNode() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeMatchSecondaryLanguage($data) + public function testLoadNodeMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); - $this->doTestLoadNode($data); + $data = $this->getData('ger-DE'); + $node = $loadService->loadNode($data['locationId']); + + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } /** * Test for the loadNode() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNode() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeMatchAlwaysAvailableLanguage($data) + public function testLoadNodeMatchAlwaysAvailableLanguage() { - $this->doTestLoadNode($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $node = $loadService->loadNode($data['locationId']); + + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } /** * Test for the loadNode() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNode() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeThrowsTranslationNotMatchedException($data) + public function testLoadNodeThrowsTranslationNotMatchedException() { - $this->doTestLoadNode($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadNode(54); } /** * Test for the loadNodeByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNodeByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getPrimaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeByRemoteIdMatchPrimaryLanguage($data) + public function testLoadNodeByRemoteIdMatchPrimaryLanguage() { - $this->doTestLoadNodeByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $node = $loadService->loadNodeByRemoteId($data['locationRemoteId']); + + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } /** * Test for the loadNodeByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNodeByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getSecondaryLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeByRemoteIdMatchSecondaryLanguage($data) + public function testLoadNodeByRemoteIdMatchSecondaryLanguage() { - $this->createSecondaryTranslationFallback(); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + 'ger-DE', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('ger-DE'); + $node = $loadService->loadNodeByRemoteId($data['locationRemoteId']); - $this->doTestLoadNodeByRemoteId($data); + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } /** * Test for the loadNodeByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNodeByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @dataProvider getAlwaysAvailableLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeByRemoteIdMatchAlwaysAvailableLanguage($data) + public function testLoadNodeByRemoteIdMatchAlwaysAvailableLanguage() { - $this->doTestLoadNodeByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-US', + ] + ); + + $loadService = $this->getSite()->getLoadService(); + + $data = $this->getData('eng-GB'); + $node = $loadService->loadNodeByRemoteId($data['locationRemoteId']); + + $this->assertLocation($node, $data); + $this->assertContent($node->content, $data); } /** * Test for the loadNodeByRemoteId() method. * - * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadNodeByRemoteId() + * @see \Netgen\EzPlatformSiteApi\API\LoadService::loadContent() + * @depends Netgen\EzPlatformSiteApi\Tests\Integration\PrepareFixturesTest::testPrepareTestFixtures * @depends Netgen\EzPlatformSiteApi\Tests\Integration\SiteTest::testGetLoadService - * @expectedException \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException - * @dataProvider getNoLanguageMatchData * - * @param mixed $data + * @throws \Netgen\EzPlatformSiteApi\API\Exceptions\TranslationNotMatchedException + * @throws \ReflectionException + * @throws \ErrorException */ - public function testLoadNodeByRemoteIdThrowsTranslationNotMatchedException($data) + public function testLoadNodeByRemoteIdThrowsTranslationNotMatchedException() { - $this->doTestLoadNodeByRemoteId($data); + $this->overrideSettings( + 'prioritizedLanguages', + [ + 'eng-GB', + 'ger-DE', + ] + ); + + $this->expectException(TranslationNotMatchedException::class); + + $loadService = $this->getSite()->getLoadService(); + + $loadService->loadNodeByRemoteId('fa9f3cff9cf90ecfae335718dcbddfe2'); } } diff --git a/tests/lib/Integration/PrepareFixturesTest.php b/tests/lib/Integration/PrepareFixturesTest.php new file mode 100644 index 00000000..66c0ee8a --- /dev/null +++ b/tests/lib/Integration/PrepareFixturesTest.php @@ -0,0 +1,207 @@ +createContentType(); + $container = $this->createContent( + $contentType, + 2, + 'content-remote-id1', + 'location-remote-id1', + 'eng-GB', + ['eng-GB'], + true + ); + $content = $this->createContent( + $contentType, + $container->contentInfo->mainLocationId, + 'content-remote-id', + 'location-remote-id', + 'eng-GB', + ['eng-GB', 'ger-DE'], + true + ); + $sibling = $this->createContent( + $contentType, + $container->contentInfo->mainLocationId, + 'content-remote-id2', + 'location-remote-id2', + 'eng-GB', + ['eng-GB'], + true + ); + $child = $this->createContent( + $contentType, + $content->contentInfo->mainLocationId, + 'content-remote-id3', + 'location-remote-id3', + 'eng-GB', + ['eng-GB'], + true + ); + + $this->assertInstanceOf(Content::class, $container); + $this->assertInstanceOf(Content::class, $content); + $this->assertInstanceOf(Content::class, $sibling); + $this->assertInstanceOf(Content::class, $child); + + return [ + 'contentId' => $content->id, + 'contentRemoteId' => $content->contentInfo->remoteId, + ]; + } + + /** + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * + * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType + * @param $parentLocationId + * @param string $contentRemoteId + * @param string $locationRemoteId + * @param string $mainLanguageCode + * @param array $languageCodes + * @param bool $alwaysAvailable + * + * @return \eZ\Publish\API\Repository\Values\Content\Content + */ + protected function createContent( + ContentType $contentType, + $parentLocationId, + $contentRemoteId, + $locationRemoteId, + $mainLanguageCode, + array $languageCodes, + $alwaysAvailable = false + ) { + $repository = $this->getRepository(false); + + $contentService = $repository->getContentService(); + $locationService = $repository->getLocationService(); + + $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId); + + $locationCreateStruct->priority = 1; + $locationCreateStruct->hidden = false; + $locationCreateStruct->remoteId = $locationRemoteId; + $locationCreateStruct->sortField = Location::SORT_FIELD_NODE_ID; + $locationCreateStruct->sortOrder = Location::SORT_ORDER_DESC; + + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $mainLanguageCode); + + $contentCreateStruct->remoteId = $contentRemoteId; + $contentCreateStruct->sectionId = 1; + $contentCreateStruct->alwaysAvailable = $alwaysAvailable; + + foreach ($languageCodes as $languageCode) { + $contentCreateStruct->setField('title', $languageCode, $languageCode); + } + + $contentDraft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]); + $content = $contentService->publishVersion($contentDraft->getVersionInfo()); + + $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); + $contentMetadataUpdateStruct->modificationDate = new DateTime('@100'); + $contentMetadataUpdateStruct->publishedDate = new DateTime('@101'); + + $contentService->updateContentMetadata($content->contentInfo, $contentMetadataUpdateStruct); + + return $contentService->loadContent($content->id); + } + + /** + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * + * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType + */ + protected function createContentType() + { + $contentTypeService = $this->getRepository(false)->getContentTypeService(); + + $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct('test-type'); + $typeCreateStruct->mainLanguageCode = 'eng-GB'; + $typeCreateStruct->remoteId = 'test-type'; + $typeCreateStruct->urlAliasSchema = ''; + $typeCreateStruct->nameSchema = '<title>'; + $typeCreateStruct->names = [ + 'eng-GB' => 'Test type', + 'ger-DE' => 'Test type', + ]; + $typeCreateStruct->descriptions = [ + 'eng-GB' => 'A test type', + 'ger-DE' => 'A test type', + ]; + $typeCreateStruct->creatorId = 14; + $typeCreateStruct->creationDate = $this->createDateTime(); + + $fieldCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( + 'title', + 'ezstring' + ); + $fieldCreateStruct->names = [ + 'eng-GB' => 'Title', + 'ger-DE' => 'Title', + ]; + $fieldCreateStruct->descriptions = [ + 'eng-GB' => 'Title of the test type', + 'ger-DE' => 'Title of the test type', + ]; + $fieldCreateStruct->fieldGroup = 'blog-content'; + $fieldCreateStruct->position = 1; + $fieldCreateStruct->isTranslatable = true; + $fieldCreateStruct->isRequired = true; + $fieldCreateStruct->isInfoCollector = false; + $fieldCreateStruct->validatorConfiguration = [ + 'StringLengthValidator' => [ + 'minStringLength' => 0, + 'maxStringLength' => 0, + ], + ]; + $fieldCreateStruct->fieldSettings = []; + $fieldCreateStruct->isSearchable = true; + + $typeCreateStruct->addFieldDefinition($fieldCreateStruct); + + $group = $contentTypeService->loadContentTypeGroupByIdentifier('Content'); + $contentTypeDraft = $contentTypeService->createContentType($typeCreateStruct, [$group]); + $contentTypeService->publishContentTypeDraft($contentTypeDraft); + + return $contentTypeService->loadContentType($contentTypeDraft->id); + } +} diff --git a/tests/lib/Integration/RelationServiceTest.php b/tests/lib/Integration/RelationServiceTest.php index c70d3404..0b9ae1d3 100644 --- a/tests/lib/Integration/RelationServiceTest.php +++ b/tests/lib/Integration/RelationServiceTest.php @@ -15,6 +15,17 @@ */ class RelationServiceTest extends BaseTest { + /** + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * + * @return array + */ protected function prepareTestContent() { $repository = $this->getRepository(); @@ -64,6 +75,17 @@ protected function prepareTestContent() return [$fieldDefinitionIdentifier, $relationContent, $relationId, $relationListContent, $relationIds]; } + /** + * @throws \ErrorException + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue + */ public function testLoadFieldRelation() { list($identifier, $testApiContent, $testRelationId) = $this->prepareTestContent(); @@ -75,6 +97,17 @@ public function testLoadFieldRelation() $this->assertEquals($testRelationId, $content->id); } + /** + * @throws \ErrorException + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue + */ public function testLoadFieldRelations() { list($identifier, , , $testApiContent, $testRelationIds) = $this->prepareTestContent(); diff --git a/tests/lib/Integration/SiteTest.php b/tests/lib/Integration/SiteTest.php index 33ebb680..39b11c73 100644 --- a/tests/lib/Integration/SiteTest.php +++ b/tests/lib/Integration/SiteTest.php @@ -33,6 +33,8 @@ public function testGetSettings() /** * Test for the getFilterService() method. * + * @group filter + * * @see \Netgen\EzPlatformSiteApi\API\Site::getFilterService() */ public function testGetFilterService() @@ -47,6 +49,8 @@ public function testGetFilterService() /** * Test for the getFindService() method. * + * @group find + * * @see \Netgen\EzPlatformSiteApi\API\Site::getFindService() */ public function testGetFindService() @@ -60,6 +64,9 @@ public function testGetFindService() /** * Test for the getLoadService() method. + * + * @group load + * * @see \Netgen\EzPlatformSiteApi\API\Site::getLoadService() */ public function testGetLoadService()