From eae9329b4c11782dd81a71f90935c69d74e4d021 Mon Sep 17 00:00:00 2001
From: Emil <7682404+em411@users.noreply.github.com>
Date: Wed, 28 Jul 2021 12:49:27 +0200
Subject: [PATCH] Add tests for API endpoint (#380)
* Fix API endpoints
* Update API route
* Fix MediaRepository methods
* Add tests for API endpoints
* Fix tests
* Fix for CR
* Fix for CR
* Fix for CR
* Fix for CR
---
features/api/viewing_blocks.feature | 23 ++++
...viewing_frequently_asked_questions.feature | 23 ++++
features/api/viewing_media.feature | 21 ++++
features/api/viewing_pages.feature | 30 +++++
features/api/viewing_sections.feature | 21 ++++
src/Repository/MediaRepository.php | 25 ++--
src/Repository/MediaRepositoryInterface.php | 6 +-
src/Resources/config/api_resources/Block.xml | 4 +-
src/Resources/config/api_resources/Faq.xml | 4 +-
src/Resources/config/api_resources/Media.xml | 2 +-
src/Resources/config/api_resources/Page.xml | 4 +-
.../config/api_resources/Section.xml | 6 +-
.../config/sylius/1.10/packages/security.yaml | 2 +-
.../config/sylius/1.9/packages/security.yaml | 31 ++---
tests/Behat/Context/Api/BlockContext.php | 98 ++++++++++++++++
.../Api/FrequentlyAskedQuestionContext.php | 106 +++++++++++++++++
tests/Behat/Context/Api/MediaContext.php | 78 +++++++++++++
tests/Behat/Context/Api/PageContext.php | 110 ++++++++++++++++++
tests/Behat/Context/Api/SectionContext.php | 77 ++++++++++++
.../Behat/Context/Transform/BlockContext.php | 51 ++++++++
.../FrequentlyAskedQuestionContext.php | 48 ++++++++
.../Behat/Context/Transform/MediaContext.php | 51 ++++++++
tests/Behat/Context/Transform/PageContext.php | 51 ++++++++
.../Context/Transform/SectionContext.php | 51 ++++++++
tests/Behat/Resources/services.yml | 1 +
tests/Behat/Resources/services/api.yml | 35 ++++++
tests/Behat/Resources/services/contexts.yml | 2 +
.../Behat/Resources/services/contexts/api.yml | 32 +++++
.../Resources/services/contexts/transform.yml | 31 +++++
tests/Behat/Resources/suites.yml | 6 +
.../Resources/suites/api/shop_blocks.yml | 15 +++
.../api/shop_frequently_asked_questions.yml | 14 +++
.../Behat/Resources/suites/api/shop_media.yml | 16 +++
.../Behat/Resources/suites/api/shop_pages.yml | 16 +++
.../Resources/suites/api/shop_sections.yml | 14 +++
35 files changed, 1061 insertions(+), 44 deletions(-)
create mode 100644 features/api/viewing_blocks.feature
create mode 100644 features/api/viewing_frequently_asked_questions.feature
create mode 100644 features/api/viewing_media.feature
create mode 100644 features/api/viewing_pages.feature
create mode 100644 features/api/viewing_sections.feature
create mode 100644 tests/Behat/Context/Api/BlockContext.php
create mode 100644 tests/Behat/Context/Api/FrequentlyAskedQuestionContext.php
create mode 100644 tests/Behat/Context/Api/MediaContext.php
create mode 100644 tests/Behat/Context/Api/PageContext.php
create mode 100644 tests/Behat/Context/Api/SectionContext.php
create mode 100644 tests/Behat/Context/Transform/BlockContext.php
create mode 100644 tests/Behat/Context/Transform/FrequentlyAskedQuestionContext.php
create mode 100644 tests/Behat/Context/Transform/MediaContext.php
create mode 100644 tests/Behat/Context/Transform/PageContext.php
create mode 100644 tests/Behat/Context/Transform/SectionContext.php
create mode 100644 tests/Behat/Resources/services/api.yml
create mode 100755 tests/Behat/Resources/services/contexts/api.yml
create mode 100644 tests/Behat/Resources/services/contexts/transform.yml
create mode 100755 tests/Behat/Resources/suites/api/shop_blocks.yml
create mode 100755 tests/Behat/Resources/suites/api/shop_frequently_asked_questions.yml
create mode 100755 tests/Behat/Resources/suites/api/shop_media.yml
create mode 100755 tests/Behat/Resources/suites/api/shop_pages.yml
create mode 100755 tests/Behat/Resources/suites/api/shop_sections.yml
diff --git a/features/api/viewing_blocks.feature b/features/api/viewing_blocks.feature
new file mode 100644
index 000000000..de2888844
--- /dev/null
+++ b/features/api/viewing_blocks.feature
@@ -0,0 +1,23 @@
+@shop_blocks
+Feature: Getting data from cms blocks
+ In order to present dynamic content in my store
+ As an API user
+ I want to be able to display blocks
+
+ Background:
+ Given the store operates on a single channel in "United States"
+ And there is a block in the store
+ And there is a block with "block-1" code and "Hi there!" content
+
+ @api
+ Scenario: Browsing blocks
+ Given I want to browse blocks
+ Then I should see 2 blocks in the list
+ And I should see block with code "block-1"
+
+ @api
+ Scenario: Displaying block
+ Given I view block with code "block-1"
+ Then I should see block name
+ And I should see block content
+
diff --git a/features/api/viewing_frequently_asked_questions.feature b/features/api/viewing_frequently_asked_questions.feature
new file mode 100644
index 000000000..6a7ab7c7c
--- /dev/null
+++ b/features/api/viewing_frequently_asked_questions.feature
@@ -0,0 +1,23 @@
+@shop_frequently_asked_questions
+Feature: Getting data from cms faq
+ In order to present dynamic content in my store
+ As an API user
+ I want to be able to display FAQ
+
+ Background:
+ Given the store operates on a single channel in "United States"
+ And there are 10 FAQs in the store
+ And there is an existing frequently asked question with "faq-1" code
+
+ @api
+ Scenario: Browsing FAQs
+ Given I want to browse FAQs
+ Then I should see 11 questions in the list
+ And I should see the "faq-1" question
+
+ @api
+ Scenario: Displaying question
+ Given I view faq with code "faq-1"
+ Then I should see question with random text
+ And I should see answer with random text
+
diff --git a/features/api/viewing_media.feature b/features/api/viewing_media.feature
new file mode 100644
index 000000000..e0ce722e3
--- /dev/null
+++ b/features/api/viewing_media.feature
@@ -0,0 +1,21 @@
+@shop_media
+Feature: Getting data from cms media
+ In order to present dynamic content in my store
+ As an API user
+ I want to be able to display media files
+
+ Background:
+ Given the store operates on a single channel in "United States"
+ And there is an existing media with "media-1" code
+ And there is an existing "image" media with "image-1" code
+
+ @api
+ Scenario: Browsing media
+ Given I want to browse media
+ Then I should see 2 media in the list
+ And I should see media with code "media-1"
+
+ @api
+ Scenario: Displaying media
+ Given I view media with code "image-1"
+ Then I should see media name
diff --git a/features/api/viewing_pages.feature b/features/api/viewing_pages.feature
new file mode 100644
index 000000000..7eb5c23d3
--- /dev/null
+++ b/features/api/viewing_pages.feature
@@ -0,0 +1,30 @@
+@shop_pages
+Feature: Getting data from cms pages
+ In order to present dynamic content in my store
+ As an API user
+ I want to be able to display custom pages
+
+ Background:
+ Given the store operates on a single channel in "United States"
+ And there are 10 pages in the store
+ And the store has "iPhone 8" and "iPhone X" products
+ And there is a page in the store
+ And this page has these products associated with it
+ And there are existing sections named "Blog" and "General"
+ And this page has these sections associated with it
+ And this page has "About us" name
+ And this page has "about" code
+ And this page also has "about-us" slug
+ And this page also has "We are the best!" content
+
+ @api
+ Scenario: Browsing defined pages
+ Given I want to browse pages
+ Then I should see 11 pages in the list
+ And I should see the "About us" page
+
+ @api
+ Scenario: Viewing a detailed page
+ Given I view page with code "about"
+ Then I should see the page name "About us"
+ And I should see the page content "We are the best!"
diff --git a/features/api/viewing_sections.feature b/features/api/viewing_sections.feature
new file mode 100644
index 000000000..9362fb35b
--- /dev/null
+++ b/features/api/viewing_sections.feature
@@ -0,0 +1,21 @@
+@shop_sections
+Feature: Getting data from cms sections
+ In order to present dynamic content in my store
+ As an API user
+ I want to be able to display sections
+
+ Background:
+ Given the store operates on a single channel in "United States"
+ And there is a section in the store
+ And there is an existing section with "section-1" code
+
+ @api
+ Scenario: Browsing sections
+ Given I want to browse sections
+ Then I should see 2 sections in the list
+ And I should see section with code "section-1"
+
+ @api
+ Scenario: Displaying section
+ Given I view section with code "section-1"
+ Then I should see section name
diff --git a/src/Repository/MediaRepository.php b/src/Repository/MediaRepository.php
index aa1886260..6711e938a 100755
--- a/src/Repository/MediaRepository.php
+++ b/src/Repository/MediaRepository.php
@@ -26,43 +26,48 @@ public function createListQueryBuilder(string $locale): QueryBuilder
;
}
- public function findOneEnabledByCode(string $code, string $channelCode): ?MediaInterface
+ public function findOneEnabledByCode(string $code, string $localeCode): ?MediaInterface
{
return $this->createQueryBuilder('o')
- ->innerJoin('o.channels', 'channel')
- ->where('o.code = :code')
+ ->leftJoin('o.translations', 'translation')
+ ->where('translation.locale = :localeCode')
+ ->andWhere('o.code = :code')
->andWhere('o.enabled = true')
->setParameter('code', $code)
+ ->setParameter('localeCode', $localeCode)
->getQuery()
->getOneOrNullResult()
;
}
- public function findBySectionCode(string $sectionCode, string $channelCode): array
+ public function findBySectionCode(string $sectionCode, ?string $localeCode): array
{
return $this->createQueryBuilder('o')
->innerJoin('o.channels', 'channel')
->innerJoin('o.sections', 'section')
- ->where('channel.code = :channelCode')
+ ->where('translation.locale = :localeCode')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
- ->setParameter('channelCode', $channelCode)
+ ->setParameter('localeCode', $localeCode)
->setParameter('sectionCode', $sectionCode)
->getQuery()
->getResult()
;
}
- public function findByProductCode(string $productCode, string $channelCode): array
+ public function findByProductCode(string $productCode, string $channelCode, ?string $localeCode): array
{
return $this->createQueryBuilder('o')
- ->innerJoin('o.channels', 'channel')
+ ->leftJoin('o.translations', 'translation')
->innerJoin('o.products', 'product')
- ->where('channel.code = :channelCode')
+ ->innerJoin('o.channels', 'channels')
+ ->andWhere('translation.locale = :localeCode')
->andWhere('product.code = :productCode')
->andWhere('o.enabled = true')
- ->setParameter('channelCode', $channelCode)
+ ->andWhere('channels.code = :channelCode')
+ ->setParameter('localeCode', $localeCode)
->setParameter('productCode', $productCode)
+ ->setParameter('channelCode', $channelCode)
->getQuery()
->getResult()
;
diff --git a/src/Repository/MediaRepositoryInterface.php b/src/Repository/MediaRepositoryInterface.php
index 0426f1b51..48ebe6975 100755
--- a/src/Repository/MediaRepositoryInterface.php
+++ b/src/Repository/MediaRepositoryInterface.php
@@ -20,9 +20,9 @@ interface MediaRepositoryInterface extends RepositoryInterface
{
public function createListQueryBuilder(string $locale): QueryBuilder;
- public function findOneEnabledByCode(string $code, string $channelCode): ?MediaInterface;
+ public function findOneEnabledByCode(string $code, string $localeCode): ?MediaInterface;
- public function findBySectionCode(string $sectionCode, string $channelCode): array;
+ public function findBySectionCode(string $sectionCode, ?string $localeCode): array;
- public function findByProductCode(string $productCode, string $channelCode): array;
+ public function findByProductCode(string $productCode, string $channelCode, ?string $localeCode): array;
}
diff --git a/src/Resources/config/api_resources/Block.xml b/src/Resources/config/api_resources/Block.xml
index 784ae70c7..738c929ff 100644
--- a/src/Resources/config/api_resources/Block.xml
+++ b/src/Resources/config/api_resources/Block.xml
@@ -19,7 +19,7 @@
sylius
-
+
GET
/shop/cms-plugin/blocks
@@ -27,7 +27,7 @@
-
+
GET
/shop/cms-plugin/blocks/{id}
diff --git a/src/Resources/config/api_resources/Faq.xml b/src/Resources/config/api_resources/Faq.xml
index beb73876f..2b203f300 100644
--- a/src/Resources/config/api_resources/Faq.xml
+++ b/src/Resources/config/api_resources/Faq.xml
@@ -19,7 +19,7 @@
sylius
-
+
GET
/shop/cms-plugin/faq
@@ -27,7 +27,7 @@
-
+
GET
/shop/cms-plugin/faq/{id}
diff --git a/src/Resources/config/api_resources/Media.xml b/src/Resources/config/api_resources/Media.xml
index 420864258..29d5b47e4 100644
--- a/src/Resources/config/api_resources/Media.xml
+++ b/src/Resources/config/api_resources/Media.xml
@@ -27,7 +27,7 @@
-
+
GET
/shop/cms-plugin/media/{id}
diff --git a/src/Resources/config/api_resources/Page.xml b/src/Resources/config/api_resources/Page.xml
index a469a35ac..04bd60772 100644
--- a/src/Resources/config/api_resources/Page.xml
+++ b/src/Resources/config/api_resources/Page.xml
@@ -19,7 +19,7 @@
sylius
-
+
GET
/shop/cms-plugin/pages
@@ -27,7 +27,7 @@
-
+
GET
/shop/cms-plugin/pages/{id}
diff --git a/src/Resources/config/api_resources/Section.xml b/src/Resources/config/api_resources/Section.xml
index 4e439717e..f2b44066d 100644
--- a/src/Resources/config/api_resources/Section.xml
+++ b/src/Resources/config/api_resources/Section.xml
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
-
+
shop:cms:read
@@ -19,7 +19,7 @@
sylius
-
+
GET
/shop/cms-plugin/sections
@@ -27,7 +27,7 @@
-
+
GET
/shop/cms-plugin/sections/{id}
diff --git a/tests/Application/config/sylius/1.10/packages/security.yaml b/tests/Application/config/sylius/1.10/packages/security.yaml
index ef43c09b1..da80b6a93 100644
--- a/tests/Application/config/sylius/1.10/packages/security.yaml
+++ b/tests/Application/config/sylius/1.10/packages/security.yaml
@@ -1,7 +1,7 @@
parameters:
sylius.security.admin_regex: "^/admin"
sylius.security.shop_regex: "^/(?!admin|new-api|api/.*|api$|media/.*)[^/]++"
- sylius.security.new_api_route: "/new-api"
+ sylius.security.new_api_route: "/api/v2"
sylius.security.new_api_regex: "^%sylius.security.new_api_route%"
security:
diff --git a/tests/Application/config/sylius/1.9/packages/security.yaml b/tests/Application/config/sylius/1.9/packages/security.yaml
index 10628102a..c40d1b9eb 100644
--- a/tests/Application/config/sylius/1.9/packages/security.yaml
+++ b/tests/Application/config/sylius/1.9/packages/security.yaml
@@ -2,7 +2,7 @@ parameters:
sylius.security.admin_regex: "^/%sylius_admin.path_name%"
sylius.security.api_regex: "^/api"
sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++"
- sylius.security.new_api_route: "/new-api"
+ sylius.security.new_api_route: "/api/v2"
sylius.security.new_api_regex: "^%sylius.security.new_api_route%"
sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin"
sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%"
@@ -55,12 +55,12 @@ security:
anonymous: true
new_api_admin_user:
- pattern: "%sylius.security.new_api_route%/admin-user-authentication-token"
- provider: sylius_admin_user_provider
+ pattern: "%sylius.security.new_api_admin_regex%/.*"
+ provider: sylius_api_admin_user_provider
stateless: true
anonymous: true
json_login:
- check_path: "%sylius.security.new_api_route%/admin-user-authentication-token"
+ check_path: "%sylius.security.new_api_route%/admin/authentication-token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
@@ -70,12 +70,12 @@ security:
- lexik_jwt_authentication.jwt_token_authenticator
new_api_shop_user:
- pattern: "%sylius.security.new_api_route%/shop-user-authentication-token"
- provider: sylius_shop_user_provider
+ pattern: "%sylius.security.new_api_shop_regex%/.*"
+ provider: sylius_api_shop_user_provider
stateless: true
anonymous: true
json_login:
- check_path: "%sylius.security.new_api_route%/shop-user-authentication-token"
+ check_path: "%sylius.security.new_api_route%/shop/authentication-token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
@@ -84,15 +84,6 @@ security:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
- new_api:
- pattern: "%sylius.security.new_api_regex%/*"
- provider: sylius_api_chain_provider
- stateless: true
- anonymous: lazy
- guard:
- authenticators:
- - lexik_jwt_authentication.jwt_token_authenticator
-
shop:
switch_user: { role: ROLE_ALLOWED_TO_SWITCH }
context: shop
@@ -128,21 +119,21 @@ security:
security: false
access_control:
- - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
+ - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [ 127.0.0.1, ::1 ] }
- { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS }
- - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
+ - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [ 127.0.0.1, ::1 ] }
- { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS }
- { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS }
- - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS }
- { path: "%sylius.security.shop_regex%/account", role: ROLE_USER }
- { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS }
+ - { path: "%sylius.security.new_api_route%/admin/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY }
+ - { path: "%sylius.security.new_api_route%/shop/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
diff --git a/tests/Behat/Context/Api/BlockContext.php b/tests/Behat/Context/Api/BlockContext.php
new file mode 100644
index 000000000..79212794d
--- /dev/null
+++ b/tests/Behat/Context/Api/BlockContext.php
@@ -0,0 +1,98 @@
+apiClient = $apiClient;
+ $this->responseChecker = $responseChecker;
+ }
+
+ /**
+ * @Given /^I want to browse blocks$/
+ */
+ public function iWantToBrowseBlocks(): void
+ {
+ $this->apiClient->index();
+ }
+
+ /**
+ * @Then /^I should see (\d+) blocks in the list$/
+ */
+ public function iShouldSeeBlocksInTheList(int $count): void
+ {
+ Assert::count($this->responseChecker->getCollection(
+ $this->apiClient->getLastResponse()),
+ $count
+ );
+ }
+
+ /**
+ * @Then I should see block with code :block
+ * @Given I view block with code :block
+ */
+ public function iShouldSeeBlockWithCode(string $code): void
+ {
+ Assert::true(
+ $this->responseChecker->hasItemWithValue(
+ $this->apiClient->index(),
+ "code",
+ $code
+ ),
+ sprintf('There is no blocks with code "%s"', $code)
+ );
+ }
+
+ /**
+ * @Then /^I should see block name$/
+ */
+ public function iShouldSeeBlockName(): void
+ {
+ Assert::false(
+ $this->responseChecker->hasTranslation(
+ $this->apiClient->getLastResponse(),
+ "en_US",
+ "answer",
+ "That shouldn't exist"
+ ), "Block has missing name"
+ );
+ }
+
+ /**
+ * @Then /^I should see block content$/
+ */
+ public function iShouldSeeBlockContent(): void
+ {
+ Assert::true(
+ $this->responseChecker->hasItemWithTranslation(
+ $this->apiClient->getLastResponse(),
+ "en_US",
+ "content",
+ "Hi there!"
+ ), "Block has missing content"
+ );
+ }
+}
diff --git a/tests/Behat/Context/Api/FrequentlyAskedQuestionContext.php b/tests/Behat/Context/Api/FrequentlyAskedQuestionContext.php
new file mode 100644
index 000000000..ae2f6a409
--- /dev/null
+++ b/tests/Behat/Context/Api/FrequentlyAskedQuestionContext.php
@@ -0,0 +1,106 @@
+apiClient = $apiClient;
+ $this->responseChecker = $responseChecker;
+ }
+
+ /**
+ * @Given /^I want to browse FAQs$/
+ */
+ public function iWantToBrowseFAQs(): void
+ {
+ $this->apiClient->index();
+ }
+
+ /**
+ * @Then /^I should see (\d+) question(?:s)? in the list$/
+ */
+ public function iShouldSeeQuestionsInTheList(string $count): void
+ {
+ Assert::count($this->responseChecker->getCollection(
+ $this->apiClient->getLastResponse()),
+ $count
+ );
+ }
+
+ /**
+ * @Given /^I should see the "([^"]*)" question$/
+ */
+ public function iShouldSeeTheQuestion(string $code): void
+ {
+ Assert::true(
+ $this->responseChecker->hasItemWithValue(
+ $this->apiClient->index(),
+ "code",
+ $code
+ ),
+ sprintf('There is no question with code "%s"', $code)
+ );
+ }
+
+ /**
+ * @When I view faq with code :faq
+ */
+ public function iViewFaqWithCode(FrequentlyAskedQuestionInterface $faq): void
+ {
+ $this->apiClient->show((string)$faq->getId());
+ }
+
+ /**
+ * @Then I should see question with random text
+ */
+ public function iShouldSeeQuestionWithRandomText(): void
+ {
+ Assert::false(
+ $this->responseChecker->hasTranslation(
+ $this->apiClient->getLastResponse(),
+ "en_US",
+ "question",
+ "That shouldn't exist"
+ ), "Missing question"
+ );
+ }
+
+ /**
+ * @Given /^I should see answer with random text$/
+ */
+ public function iShouldSeeAnswerWithRandomText(): void
+ {
+ Assert::false(
+ $this->responseChecker->hasTranslation(
+ $this->apiClient->getLastResponse(),
+ "en_US",
+ "answer",
+ "That shouldn't exist"
+ ), "Missing answer"
+ );
+ }
+}
diff --git a/tests/Behat/Context/Api/MediaContext.php b/tests/Behat/Context/Api/MediaContext.php
new file mode 100644
index 000000000..41c936301
--- /dev/null
+++ b/tests/Behat/Context/Api/MediaContext.php
@@ -0,0 +1,78 @@
+apiClient = $apiClient;
+ $this->responseChecker = $responseChecker;
+ }
+
+ /**
+ * @Given /^I want to browse media$/
+ */
+ public function iWantToBrowseMedia(): void
+ {
+ $this->apiClient->index();
+ }
+
+ /**
+ * @Then /^I should see (\d+) media in the list$/
+ */
+ public function iShouldSeeMediaInTheList(int $count): void
+ {
+ Assert::count($this->responseChecker->getCollection(
+ $this->apiClient->getLastResponse()),
+ $count
+ );
+ }
+
+ /**
+ * @Then I should see media with code :media
+ * @Given I view media with code :media
+ */
+ public function iShouldSeeTheMedia(MediaInterface $media): void
+ {
+ $this->apiClient->show((string)$media->getId());
+ }
+
+ /**
+ * @Then /^I should see media name$/
+ */
+ public function iShouldSeeMediaName(): void
+ {
+ Assert::false(
+ $this->responseChecker->hasTranslation(
+ $this->apiClient->getLastResponse(),
+ "en_US",
+ "content",
+ "That shouldn't exist"
+ ), "Missing media"
+ );
+ }
+
+}
diff --git a/tests/Behat/Context/Api/PageContext.php b/tests/Behat/Context/Api/PageContext.php
new file mode 100644
index 000000000..1353dd2ba
--- /dev/null
+++ b/tests/Behat/Context/Api/PageContext.php
@@ -0,0 +1,110 @@
+apiClient = $apiClient;
+ $this->responseChecker = $responseChecker;
+ }
+
+ /**
+ * @When /^I want to browse pages$/
+ */
+ public function iWantToBrowsePages(): void
+ {
+ $this->apiClient->index();
+ }
+
+ /**
+ * @Then /^I should see (\d+) page(?:s)? in the list$/
+ */
+ public function iShouldSeePageInTheList(int $count): void
+ {
+ Assert::count($this->responseChecker->getCollection(
+ $this->apiClient->getLastResponse()),
+ $count,
+ sprintf('There is no page with name "%s"', $count)
+ );
+ }
+
+ /**
+ * @Then /^I should see the "([^"]*)" page$/
+ */
+ public function iShouldSeeThePage(string $page): void
+ {
+ Assert::true(
+ $this->responseChecker->hasItemWithTranslation(
+ $this->apiClient->index(),
+ "en_US",
+ 'name',
+ $page
+ ),
+ sprintf('There is no page with name "%s"', $page)
+ );
+ }
+
+ /**
+ * @When I view page with code :page
+ */
+ public function iOpenPage(PageInterface $page): void
+ {
+ $this->apiClient->show((string)$page->getId());
+ }
+
+ /**
+ * @Then /^I should see the page name "([^"]*)"$/
+ */
+ public function iShouldSeeThePageName(string $name): void
+ {
+ Assert::true(
+ $this->responseChecker->hasItemWithTranslation(
+ $this->apiClient->getLastResponse(),
+ 'en_US',
+ 'name',
+ $name
+ ),
+ sprintf('There is no page with name "%s"', $name)
+ );
+ }
+
+ /**
+ * @Then /^I should see the page content "([^"]*)"$/
+ */
+ public function iShouldSeeThePageContent(string $content): void
+ {
+ Assert::true(
+ $this->responseChecker->hasItemWithTranslation(
+ $this->apiClient->getLastResponse(),
+ 'en_US',
+ 'content',
+ $content
+ ),
+ sprintf('There is no page with content "%s"', $content)
+ );
+ }
+}
diff --git a/tests/Behat/Context/Api/SectionContext.php b/tests/Behat/Context/Api/SectionContext.php
new file mode 100644
index 000000000..eb6b22baa
--- /dev/null
+++ b/tests/Behat/Context/Api/SectionContext.php
@@ -0,0 +1,77 @@
+apiClient = $apiClient;
+ $this->responseChecker = $responseChecker;
+ }
+
+ /**
+ * @Given /^I want to browse sections$/
+ */
+ public function iWantToBrowseSections(): void
+ {
+ $this->apiClient->index();
+ }
+
+ /**
+ * @Then /^I should see (\d+) sections in the list$/
+ */
+ public function iShouldSeeSectionsInTheList(int $count): void
+ {
+ Assert::count($this->responseChecker->getCollection(
+ $this->apiClient->getLastResponse()),
+ $count
+ );
+ }
+
+ /**
+ * @Then I should see section with code :section
+ * @Given I view section with code :section
+ */
+ public function iShouldSeeSectionWithCode(SectionInterface $section): void
+ {
+ $this->apiClient->show((string)$section->getId());
+ }
+
+ /**
+ * @Then /^I should see section name$/
+ */
+ public function iShouldSeeSectionName(): void
+ {
+ Assert::false(
+ $this->responseChecker->hasTranslation(
+ $this->apiClient->getLastResponse(),
+ "en_US",
+ "name",
+ "That shouldn't exist"
+ ), "Section has missing name"
+ );
+ }
+}
diff --git a/tests/Behat/Context/Transform/BlockContext.php b/tests/Behat/Context/Transform/BlockContext.php
new file mode 100644
index 000000000..38c7a7b03
--- /dev/null
+++ b/tests/Behat/Context/Transform/BlockContext.php
@@ -0,0 +1,51 @@
+blockRepository = $blockRepository;
+ $this->locale = $locale;
+ }
+
+ /**
+ * @Transform /^block(?:|s) "([^"]+)"$/
+ * @Transform /^"([^"]+)" block(?:|s)$/
+ * @Transform /^(?:a|an) "([^"]+)"$/
+ * @Transform :block
+ */
+ public function getBlockByCode(string $blockCode): BlockInterface
+ {
+ $block = $this->blockRepository->findEnabledByCode($blockCode, $this->locale);
+
+ Assert::notNull(
+ $block,
+ sprintf('No blocks has been found with code "%s".', $blockCode)
+ );
+
+ return $block;
+ }
+}
diff --git a/tests/Behat/Context/Transform/FrequentlyAskedQuestionContext.php b/tests/Behat/Context/Transform/FrequentlyAskedQuestionContext.php
new file mode 100644
index 000000000..0c745c166
--- /dev/null
+++ b/tests/Behat/Context/Transform/FrequentlyAskedQuestionContext.php
@@ -0,0 +1,48 @@
+frequentlyAskedQuestionRepository = $frequentlyAskedQuestionRepository;
+ }
+
+ /**
+ * @Transform /^faq(?:|s) "([^"]+)"$/
+ * @Transform /^"([^"]+)" faq(?:|s)$/
+ * @Transform /^(?:a|an) "([^"]+)"$/
+ * @Transform :faq
+ */
+ public function getFAQByCode(string $faqCode): FrequentlyAskedQuestionInterface
+ {
+ $faq = $this->frequentlyAskedQuestionRepository->findOneEnabledByCode($faqCode);
+
+ Assert::notNull(
+ $faq,
+ sprintf('No FAQs has been found with code "%s".', $faqCode)
+ );
+
+ return $faq;
+ }
+}
diff --git a/tests/Behat/Context/Transform/MediaContext.php b/tests/Behat/Context/Transform/MediaContext.php
new file mode 100644
index 000000000..f0d89e07e
--- /dev/null
+++ b/tests/Behat/Context/Transform/MediaContext.php
@@ -0,0 +1,51 @@
+mediaRepositoryInterface = $mediaRepositoryInterface;
+ $this->locale = $locale;
+ }
+
+ /**
+ * @Transform /^media(?:|s) "([^"]+)"$/
+ * @Transform /^"([^"]+)" media(?:|s)$/
+ * @Transform /^(?:a|an) "([^"]+)"$/
+ * @Transform :media
+ */
+ public function getMediaByCode(string $mediaCode): MediaInterface
+ {
+ $media = $this->mediaRepositoryInterface->findOneEnabledByCode($mediaCode, $this->locale);
+
+ Assert::notNull(
+ $media,
+ sprintf('No media has been found with code "%s".', $mediaCode)
+ );
+
+ return $media;
+ }
+}
diff --git a/tests/Behat/Context/Transform/PageContext.php b/tests/Behat/Context/Transform/PageContext.php
new file mode 100644
index 000000000..bb34c3868
--- /dev/null
+++ b/tests/Behat/Context/Transform/PageContext.php
@@ -0,0 +1,51 @@
+pageRepository = $pageRepository;
+ $this->locale = $locale;
+ }
+
+ /**
+ * @Transform /^page(?:|s) "([^"]+)"$/
+ * @Transform /^"([^"]+)" page(?:|s)$/
+ * @Transform /^(?:a|an) "([^"]+)"$/
+ * @Transform :page
+ */
+ public function getPageByCode(string $pageCode): PageInterface
+ {
+ $page = $this->pageRepository->findOneEnabledByCode($pageCode, $this->locale);
+
+ Assert::notNull(
+ $page,
+ sprintf('No pages has been found with code "%s".', $pageCode)
+ );
+
+ return $page;
+ }
+}
diff --git a/tests/Behat/Context/Transform/SectionContext.php b/tests/Behat/Context/Transform/SectionContext.php
new file mode 100644
index 000000000..0ade46a9a
--- /dev/null
+++ b/tests/Behat/Context/Transform/SectionContext.php
@@ -0,0 +1,51 @@
+sectionRepository = $sectionRepository;
+ $this->locale = $locale;
+ }
+
+ /**
+ * @Transform /^section(?:|s) "([^"]+)"$/
+ * @Transform /^"([^"]+)" section(?:|s)$/
+ * @Transform /^(?:a|an) "([^"]+)"$/
+ * @Transform :section
+ */
+ public function getSectionByCode(string $sectionCode): SectionInterface
+ {
+ $section = $this->sectionRepository->findOneByCode($sectionCode, $this->locale);
+
+ Assert::notNull(
+ $section,
+ sprintf('No sections has been found with code "%s".', $sectionCode)
+ );
+
+ return $section;
+ }
+}
diff --git a/tests/Behat/Resources/services.yml b/tests/Behat/Resources/services.yml
index 2dca43034..57d86579b 100755
--- a/tests/Behat/Resources/services.yml
+++ b/tests/Behat/Resources/services.yml
@@ -1,6 +1,7 @@
imports:
- { resource: "services/contexts.yml" }
- { resource: "services/pages.yml" }
+ - { resource: "services/api.yml" }
services:
bitbag_sylius_cms_plugin.behat.random_string_generator:
diff --git a/tests/Behat/Resources/services/api.yml b/tests/Behat/Resources/services/api.yml
new file mode 100644
index 000000000..f72343e0a
--- /dev/null
+++ b/tests/Behat/Resources/services/api.yml
@@ -0,0 +1,35 @@
+services:
+ bitbag_sylius_cms_plugin.behat.api_platform_client.shop.block:
+ class: Sylius\Behat\Client\ApiPlatformClient
+ parent: sylius.behat.api_platform_client
+ arguments:
+ - blocks
+ - shop/cms-plugin
+
+ bitbag_sylius_cms_plugin.behat.api_platform_client.shop.frequently_asked_question:
+ class: Sylius\Behat\Client\ApiPlatformClient
+ parent: sylius.behat.api_platform_client
+ arguments:
+ - faq
+ - shop/cms-plugin
+
+ bitbag_sylius_cms_plugin.behat.api_platform_client.shop.media:
+ class: Sylius\Behat\Client\ApiPlatformClient
+ parent: sylius.behat.api_platform_client
+ arguments:
+ - media
+ - shop/cms-plugin
+
+ bitbag_sylius_cms_plugin.behat.api_platform_client.shop.page:
+ class: Sylius\Behat\Client\ApiPlatformClient
+ parent: sylius.behat.api_platform_client
+ arguments:
+ - pages
+ - shop/cms-plugin
+
+ bitbag_sylius_cms_plugin.behat.api_platform_client.shop.section:
+ class: Sylius\Behat\Client\ApiPlatformClient
+ parent: sylius.behat.api_platform_client
+ arguments:
+ - sections
+ - shop/cms-plugin
diff --git a/tests/Behat/Resources/services/contexts.yml b/tests/Behat/Resources/services/contexts.yml
index c6beae021..af12f4fb4 100755
--- a/tests/Behat/Resources/services/contexts.yml
+++ b/tests/Behat/Resources/services/contexts.yml
@@ -1,3 +1,5 @@
imports:
- { resource: contexts/setup.yml }
- { resource: contexts/ui.yml }
+ - { resource: contexts/api.yml }
+ - { resource: contexts/transform.yml }
diff --git a/tests/Behat/Resources/services/contexts/api.yml b/tests/Behat/Resources/services/contexts/api.yml
new file mode 100755
index 000000000..8b0cddf40
--- /dev/null
+++ b/tests/Behat/Resources/services/contexts/api.yml
@@ -0,0 +1,32 @@
+services:
+ _defaults: { public: true }
+
+ bitbag_sylius_cms_plugin.behat.context.api.block:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Api\BlockContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.behat.api_platform_client.shop.block"
+ - "@Sylius\\Behat\\Client\\ResponseCheckerInterface"
+
+ bitbag_sylius_cms_plugin.behat.context.api.frequently_asked_question:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Api\FrequentlyAskedQuestionContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.behat.api_platform_client.shop.frequently_asked_question"
+ - "@Sylius\\Behat\\Client\\ResponseCheckerInterface"
+
+ bitbag_sylius_cms_plugin.behat.context.api.media:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Api\MediaContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.behat.api_platform_client.shop.media"
+ - "@Sylius\\Behat\\Client\\ResponseCheckerInterface"
+
+ bitbag_sylius_cms_plugin.behat.context.api.page:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Api\PageContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.behat.api_platform_client.shop.page"
+ - "@Sylius\\Behat\\Client\\ResponseCheckerInterface"
+
+ bitbag_sylius_cms_plugin.behat.context.api.section:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Api\SectionContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.behat.api_platform_client.shop.section"
+ - "@Sylius\\Behat\\Client\\ResponseCheckerInterface"
diff --git a/tests/Behat/Resources/services/contexts/transform.yml b/tests/Behat/Resources/services/contexts/transform.yml
new file mode 100644
index 000000000..cc60c367d
--- /dev/null
+++ b/tests/Behat/Resources/services/contexts/transform.yml
@@ -0,0 +1,31 @@
+services:
+ _defaults: { public: true }
+
+ bitbag_sylius_cms_plugin.behat.context.transform.block:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Transform\BlockContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.repository.block"
+ - "%locale%"
+
+ bitbag_sylius_cms_plugin.behat.context.transform.frequently_asked_question:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Transform\FrequentlyAskedQuestionContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.repository.frequently_asked_question"
+
+ bitbag_sylius_cms_plugin.behat.context.transform.media:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Transform\MediaContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.repository.media"
+ - "%locale%"
+
+ bitbag_sylius_cms_plugin.behat.context.transform.page:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Transform\PageContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.repository.page"
+ - "%locale%"
+
+ bitbag_sylius_cms_plugin.behat.context.transform.section:
+ class: Tests\BitBag\SyliusCmsPlugin\Behat\Context\Transform\SectionContext
+ arguments:
+ - "@bitbag_sylius_cms_plugin.repository.section"
+ - "%locale%"
diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml
index 6ae52d95b..15e963b60 100755
--- a/tests/Behat/Resources/suites.yml
+++ b/tests/Behat/Resources/suites.yml
@@ -7,3 +7,9 @@ imports:
- suites/ui/shop_blocks.yml
- suites/ui/shop_pages.yml
- suites/ui/shop_frequently_asked_questions.yml
+
+ - suites/api/shop_pages.yml
+ - suites/api/shop_frequently_asked_questions.yml
+ - suites/api/shop_blocks.yml
+ - suites/api/shop_sections.yml
+ - suites/api/shop_media.yml
diff --git a/tests/Behat/Resources/suites/api/shop_blocks.yml b/tests/Behat/Resources/suites/api/shop_blocks.yml
new file mode 100755
index 000000000..a2e38c92b
--- /dev/null
+++ b/tests/Behat/Resources/suites/api/shop_blocks.yml
@@ -0,0 +1,15 @@
+default:
+ suites:
+ api_shop_blocks:
+ contexts:
+ - sylius.behat.context.hook.doctrine_orm
+
+ - sylius.behat.context.setup.channel
+ - sylius.behat.context.setup.admin_security
+ - bitbag_sylius_cms_plugin.behat.context.setup.block
+ - bitbag_sylius_cms_plugin.behat.context.setup.section
+ - bitbag_sylius_cms_plugin.behat.context.transform.block
+
+ - bitbag_sylius_cms_plugin.behat.context.api.block
+ filters:
+ tags: "@shop_blocks && @api"
diff --git a/tests/Behat/Resources/suites/api/shop_frequently_asked_questions.yml b/tests/Behat/Resources/suites/api/shop_frequently_asked_questions.yml
new file mode 100755
index 000000000..cb40e265c
--- /dev/null
+++ b/tests/Behat/Resources/suites/api/shop_frequently_asked_questions.yml
@@ -0,0 +1,14 @@
+default:
+ suites:
+ api_shop_frequently_asked_questions:
+ contexts:
+ - sylius.behat.context.hook.doctrine_orm
+
+ - sylius.behat.context.setup.channel
+ - bitbag_sylius_cms_plugin.behat.context.setup.frequently_asked_question
+
+ - bitbag_sylius_cms_plugin.behat.context.transform.frequently_asked_question
+
+ - bitbag_sylius_cms_plugin.behat.context.api.frequently_asked_question
+ filters:
+ tags: "@shop_frequently_asked_questions && @api"
diff --git a/tests/Behat/Resources/suites/api/shop_media.yml b/tests/Behat/Resources/suites/api/shop_media.yml
new file mode 100755
index 000000000..3488525f5
--- /dev/null
+++ b/tests/Behat/Resources/suites/api/shop_media.yml
@@ -0,0 +1,16 @@
+default:
+ suites:
+ api_shop_media:
+ contexts:
+ - sylius.behat.context.hook.doctrine_orm
+
+ - sylius.behat.context.setup.channel
+ - sylius.behat.context.setup.admin_security
+ - sylius.behat.context.setup.product
+ - bitbag_sylius_cms_plugin.behat.context.setup.media
+ - bitbag_sylius_cms_plugin.behat.context.setup.section
+ - bitbag_sylius_cms_plugin.behat.context.transform.media
+
+ - bitbag_sylius_cms_plugin.behat.context.api.media
+ filters:
+ tags: "@shop_media && @api"
diff --git a/tests/Behat/Resources/suites/api/shop_pages.yml b/tests/Behat/Resources/suites/api/shop_pages.yml
new file mode 100755
index 000000000..05f530d65
--- /dev/null
+++ b/tests/Behat/Resources/suites/api/shop_pages.yml
@@ -0,0 +1,16 @@
+default:
+ suites:
+ api_shop_pages:
+ contexts:
+ - sylius.behat.context.hook.doctrine_orm
+
+ - bitbag_sylius_cms_plugin.behat.context.transform.page
+
+ - sylius.behat.context.setup.channel
+ - sylius.behat.context.setup.product
+ - bitbag_sylius_cms_plugin.behat.context.setup.page
+ - bitbag_sylius_cms_plugin.behat.context.setup.section
+
+ - bitbag_sylius_cms_plugin.behat.context.api.page
+ filters:
+ tags: "@shop_pages && @api"
diff --git a/tests/Behat/Resources/suites/api/shop_sections.yml b/tests/Behat/Resources/suites/api/shop_sections.yml
new file mode 100755
index 000000000..7947e525d
--- /dev/null
+++ b/tests/Behat/Resources/suites/api/shop_sections.yml
@@ -0,0 +1,14 @@
+default:
+ suites:
+ api_shop_sections:
+ contexts:
+ - sylius.behat.context.hook.doctrine_orm
+
+ - sylius.behat.context.setup.channel
+ - sylius.behat.context.setup.admin_security
+ - bitbag_sylius_cms_plugin.behat.context.setup.section
+ - bitbag_sylius_cms_plugin.behat.context.transform.section
+
+ - bitbag_sylius_cms_plugin.behat.context.api.section
+ filters:
+ tags: "@shop_sections && @api"