From dff2218bb37618dc2626fbb443b45f4587686231 Mon Sep 17 00:00:00 2001 From: Adam Kasperczak Date: Sun, 12 Jan 2020 11:47:10 +0100 Subject: [PATCH 1/2] delete unnessesary dockblocks from behat pages --- src/Sylius/Behat/Page/Shop/Order/ShowPage.php | 30 ++++--------------- .../Page/Shop/Order/ShowPageInterface.php | 23 +++++--------- .../Behat/Page/Shop/Order/ThankYouPage.php | 23 +++----------- .../Page/Shop/Order/ThankYouPageInterface.php | 26 +++++----------- 4 files changed, 24 insertions(+), 78 deletions(-) diff --git a/src/Sylius/Behat/Page/Shop/Order/ShowPage.php b/src/Sylius/Behat/Page/Shop/Order/ShowPage.php index 14200cb1718..2b9b4169913 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ShowPage.php +++ b/src/Sylius/Behat/Page/Shop/Order/ShowPage.php @@ -18,26 +18,20 @@ class ShowPage extends SymfonyPage implements ShowPageInterface { - /** - * {@inheritdoc} - */ - public function hasPayAction() + public function hasPayAction(): bool { return $this->hasElement('pay_link'); } - /** - * {@inheritdoc} - */ - public function pay() + public function pay(): void { $this->getElement('pay_link')->click(); } /** - * {@inheritdoc} + * @return string[] */ - public function getNotifications() + public function getNotifications(): array { /** @var NodeElement[] $notificationElements */ $notificationElements = $this->getDocument()->findAll('css', '.message > .content > p'); @@ -50,26 +44,17 @@ public function getNotifications() return $notifications; } - /** - * {@inheritdoc} - */ - public function choosePaymentMethod($paymentMethodName) + public function choosePaymentMethod($paymentMethodName): void { $paymentMethodElement = $this->getElement('payment_method', ['%name%' => $paymentMethodName]); $paymentMethodElement->selectOption($paymentMethodElement->getAttribute('value')); } - /** - * {@inheritdoc} - */ public function getRouteName(): string { return 'sylius_shop_order_show'; } - /** - * {@inheritdoc} - */ public function getNumberOfItems(): int { $itemsText = trim($this->getElement('items_text')->getText()); @@ -77,10 +62,7 @@ public function getNumberOfItems(): int return (int) $itemsTextWords[0]; } - - /** - * {@inheritdoc} - */ + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ diff --git a/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php index e5252aa6347..846d09bd804 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php @@ -17,22 +17,13 @@ interface ShowPageInterface extends SymfonyPageInterface { - /** - * @return bool - */ - public function hasPayAction(); - - public function pay(); - - /** - * @param string $paymentMethodName - */ - public function choosePaymentMethod($paymentMethodName); - - /** - * @return string[] - */ - public function getNotifications(); + public function hasPayAction(): bool; + + public function pay(): void; + + public function choosePaymentMethod($paymentMethodName): void; + + public function getNotifications(): array; public function getNumberOfItems(): int; } diff --git a/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php b/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php index a2edd3309d2..049924a07bc 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php +++ b/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php @@ -17,9 +17,6 @@ class ThankYouPage extends SymfonyPage implements ThankYouPageInterface { - /** - * {@inheritdoc} - */ public function goToTheChangePaymentMethodPage(): void { $this->getElement('payment_method_page')->click(); @@ -30,36 +27,24 @@ public function goToOrderDetailsInAccount(): void $this->getElement('order_details_in_account')->click(); } - /** - * {@inheritdoc} - */ - public function hasThankYouMessage() + public function hasThankYouMessage(): bool { $thankYouMessage = $this->getElement('thank_you')->getText(); return false !== strpos($thankYouMessage, 'Thank you!'); } - /** - * {@inheritdoc} - */ - public function getInstructions() + public function getInstructions(): string { return $this->getElement('instructions')->getText(); } - /** - * {@inheritdoc} - */ - public function hasInstructions() + public function hasInstructions(): bool { return null !== $this->getDocument()->find('css', '#sylius-payment-method-instructions'); } - /** - * {@inheritdoc} - */ - public function hasChangePaymentMethodButton() + public function hasChangePaymentMethodButton(): bool { return null !== $this->getDocument()->find('css', '#payment-method-page'); } diff --git a/src/Sylius/Behat/Page/Shop/Order/ThankYouPageInterface.php b/src/Sylius/Behat/Page/Shop/Order/ThankYouPageInterface.php index ac15b7f3aa6..cc0c7958bff 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ThankYouPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Order/ThankYouPageInterface.php @@ -21,25 +21,13 @@ public function goToTheChangePaymentMethodPage(): void; public function goToOrderDetailsInAccount(): void; - /** - * @return bool - */ - public function hasThankYouMessage(); - - /** - * @return string - */ - public function getInstructions(); - - /** - * @return bool - */ - public function hasInstructions(); - - /** - * @return bool - */ - public function hasChangePaymentMethodButton(); + public function hasThankYouMessage(): bool; + + public function getInstructions(): string; + + public function hasInstructions(): bool; + + public function hasChangePaymentMethodButton(): bool; public function hasRegistrationButton(): bool; From 374531b76b0b8b0f2ed4360fdd51aa0d27606112 Mon Sep 17 00:00:00 2001 From: Adam Kasperczak Date: Sun, 12 Jan 2020 13:18:36 +0100 Subject: [PATCH 2/2] Use html attributes in behat pages and views --- src/Sylius/Behat/Page/Shop/Order/ShowPage.php | 21 +++++++------------ .../Page/Shop/Order/ShowPageInterface.php | 2 +- .../Behat/Page/Shop/Order/ThankYouPage.php | 17 ++++++++------- .../Resources/views/Order/show.html.twig | 2 +- .../Resources/views/Order/thankYou.html.twig | 10 ++++----- .../Resources/views/_flashes.html.twig | 2 +- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/Sylius/Behat/Page/Shop/Order/ShowPage.php b/src/Sylius/Behat/Page/Shop/Order/ShowPage.php index 2b9b4169913..c509b7aa1a7 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ShowPage.php +++ b/src/Sylius/Behat/Page/Shop/Order/ShowPage.php @@ -28,13 +28,10 @@ public function pay(): void $this->getElement('pay_link')->click(); } - /** - * @return string[] - */ public function getNotifications(): array { /** @var NodeElement[] $notificationElements */ - $notificationElements = $this->getDocument()->findAll('css', '.message > .content > p'); + $notificationElements = $this->getDocument()->findAll('css', '[data-test-flash-messages]'); $notifications = []; foreach ($notificationElements as $notificationElement) { @@ -44,7 +41,7 @@ public function getNotifications(): array return $notifications; } - public function choosePaymentMethod($paymentMethodName): void + public function choosePaymentMethod(string $paymentMethodName): void { $paymentMethodElement = $this->getElement('payment_method', ['%name%' => $paymentMethodName]); $paymentMethodElement->selectOption($paymentMethodElement->getAttribute('value')); @@ -57,20 +54,16 @@ public function getRouteName(): string public function getNumberOfItems(): int { - $itemsText = trim($this->getElement('items_text')->getText()); - $itemsTextWords = explode(' ', $itemsText); + $paymentItems = $this->getDocument()->findAll('css', '[data-test-payment-item]'); - return (int) $itemsTextWords[0]; + return count($paymentItems); } - + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ - 'instructions' => '#sylius-payment-method-instructions', - 'items_text' => 'div.sub.header div.item:nth-child(3)', - 'pay_link' => '#sylius-pay-link', - 'payment_method' => '.item:contains("%name%") input', - 'thank_you' => '#sylius-thank-you', + 'pay_link' => '[data-test-pay-link]', + 'payment_method' => '[data-test-payment-item]:contains("%name%") [data-test-payment-method-select]', ]); } } diff --git a/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php index 846d09bd804..13d4c8ce5a1 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php @@ -21,7 +21,7 @@ public function hasPayAction(): bool; public function pay(): void; - public function choosePaymentMethod($paymentMethodName): void; + public function choosePaymentMethod(string $paymentMethodName): void; public function getNotifications(): array; diff --git a/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php b/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php index 049924a07bc..20892f7b3a9 100644 --- a/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php +++ b/src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php @@ -41,22 +41,22 @@ public function getInstructions(): string public function hasInstructions(): bool { - return null !== $this->getDocument()->find('css', '#sylius-payment-method-instructions'); + return $this->hasElement('instructions'); } public function hasChangePaymentMethodButton(): bool { - return null !== $this->getDocument()->find('css', '#payment-method-page'); + return $this->hasElement('payment_method_page'); } public function hasRegistrationButton(): bool { - return $this->getDocument()->hasLink('Create an account'); + return $this->hasElement('create_account_button'); } public function createAccount(): void { - $this->getDocument()->clickLink('Create an account'); + $this->getElement('create_account_button')->click(); } public function getRouteName(): string @@ -67,10 +67,11 @@ public function getRouteName(): string protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ - 'instructions' => '#sylius-payment-method-instructions', - 'order_details_in_account' => '#sylius-show-order-in-account', - 'payment_method_page' => '#payment-method-page', - 'thank_you' => '#sylius-thank-you', + 'instructions' => '[data-test-payment-method-instructions]', + 'order_details_in_account' => '[data-test-show-order-in-account]', + 'payment_method_page' => '[data-test-payment-method-page]', + 'thank_you' => '[data-test-thank-you]', + 'create_account_button' => '[data-test-create-an-account]', ]); } } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Order/show.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Order/show.html.twig index e3d2740fb4f..a4f5c4d6527 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Order/show.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Order/show.html.twig @@ -12,7 +12,7 @@ {% include '@SyliusShop/Checkout/SelectPayment/_form.html.twig' %} - diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Order/thankYou.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Order/thankYou.html.twig index 91dfea8beed..6301168cd3a 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Order/thankYou.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Order/thankYou.html.twig @@ -7,7 +7,7 @@

{% set lastPayment = order.payments.last() %} -
+
{{ 'sylius.ui.thank_you'|trans }}
{{ 'sylius.ui.placed_an_order'|trans }}
@@ -17,7 +17,7 @@ {% if lastPayment != false %} {% if lastPayment.method.instructions is not null %} -
+
{{ lastPayment.method.instructions }}
{% endif %} @@ -25,10 +25,10 @@ {% endif %} {% if order.customer.user is not null %} - {{ 'sylius.ui.view_order'|trans }} + {{ 'sylius.ui.view_order'|trans }} {% else %} - {{ 'sylius.ui.change_payment_method'|trans }} - + {{ 'sylius.ui.change_payment_method'|trans }} + {{ 'sylius.ui.create_an_account'|trans }} diff --git a/src/Sylius/Bundle/UiBundle/Resources/views/_flashes.html.twig b/src/Sylius/Bundle/UiBundle/Resources/views/_flashes.html.twig index 909bb35b1fc..db72c78909e 100644 --- a/src/Sylius/Bundle/UiBundle/Resources/views/_flashes.html.twig +++ b/src/Sylius/Bundle/UiBundle/Resources/views/_flashes.html.twig @@ -17,7 +17,7 @@ {% set header = 'sylius.ui.'~type %} {{ header|trans }}
-

+

{% if flash is iterable %} {{ flash.message|trans(flash.parameters, 'flashes') }} {% else %}