Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions src/Sylius/Behat/Page/Shop/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +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}
*/
public function getNotifications()
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) {
Expand All @@ -50,45 +41,29 @@ public function getNotifications()
return $notifications;
}

/**
* {@inheritdoc}
*/
public function choosePaymentMethod($paymentMethodName)
public function choosePaymentMethod(string $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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getNumberOfItems(): int
public function getAmountOfItems(): 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);
}

/**
* {@inheritdoc}
*/
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]',
]);
}
}
23 changes: 7 additions & 16 deletions src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(string $paymentMethodName): void;

public function getNotifications(): array;

public function getNumberOfItems(): int;
}
40 changes: 13 additions & 27 deletions src/Sylius/Behat/Page/Shop/Order/ThankYouPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

class ThankYouPage extends SymfonyPage implements ThankYouPageInterface
{
/**
* {@inheritdoc}
*/
public function goToTheChangePaymentMethodPage(): void
{
$this->getElement('payment_method_page')->click();
Expand All @@ -30,48 +27,36 @@ 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');
return $this->hasElement('instructions');
}

/**
* {@inheritdoc}
*/
public function hasChangePaymentMethodButton()
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
Expand All @@ -82,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]',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong order of keys

]);
}
}
26 changes: 7 additions & 19 deletions src/Sylius/Behat/Page/Shop/Order/ThankYouPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

{% include '@SyliusShop/Checkout/SelectPayment/_form.html.twig' %}
<div class="ui hidden divider"></div>
<button type="submit" class="ui large blue icon labeled button" id="sylius-pay-link">
<button type="submit" class="ui large blue icon labeled button" id="sylius-pay-link" {{ sylius_test_html_attribute('pay-link') }}>
<i class="check icon"></i> {{ 'sylius.ui.pay'|trans }}
</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1 class="ui icon header">
{% set lastPayment = order.payments.last() %}
<i class="circular rocket icon"></i>
<div class="content" id="sylius-thank-you">
<div class="content" id="sylius-thank-you" {{ sylius_test_html_attribute('thank-you') }}>
{{ 'sylius.ui.thank_you'|trans }}
<div class="sub header">{{ 'sylius.ui.placed_an_order'|trans }}</div>
</div>
Expand All @@ -17,18 +17,18 @@

{% if lastPayment != false %}
{% if lastPayment.method.instructions is not null %}
<div id="sylius-payment-method-instructions" class="ui segment">
<div id="sylius-payment-method-instructions" class="ui segment" {{ sylius_test_html_attribute('payment-method-instructions') }}>
{{ lastPayment.method.instructions }}
</div>
{% endif %}
<div class="ui hidden divider"></div>
{% endif %}

{% if order.customer.user is not null %}
<a href="{{ path('sylius_shop_account_order_show', {'number': order.number}) }}" id="sylius-show-order-in-account" class="ui large blue button">{{ 'sylius.ui.view_order'|trans }}</a>
<a href="{{ path('sylius_shop_account_order_show', {'number': order.number}) }}" id="sylius-show-order-in-account" class="ui large blue button" {{ sylius_test_html_attribute('show-order-in-account') }}>{{ 'sylius.ui.view_order'|trans }}</a>
{% else %}
<a href="{{ path('sylius_shop_order_show', {'tokenValue': order.tokenValue}) }}" id="payment-method-page" class="ui large blue button">{{ 'sylius.ui.change_payment_method'|trans }}</a>
<a href="{{ path('sylius_shop_register_after_checkout', {'tokenValue': order.tokenValue}) }}" class="ui large green button">
<a href="{{ path('sylius_shop_order_show', {'tokenValue': order.tokenValue}) }}" id="payment-method-page" class="ui large blue button" {{ sylius_test_html_attribute('payment-method-page') }}>{{ 'sylius.ui.change_payment_method'|trans }}</a>
<a href="{{ path('sylius_shop_register_after_checkout', {'tokenValue': order.tokenValue}) }}" class="ui large green button" {{ sylius_test_html_attribute('create-an-account') }}>
<i class="signup icon"></i>
{{ 'sylius.ui.create_an_account'|trans }}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% set header = 'sylius.ui.'~type %}
{{ header|trans }}
</div>
<p>
<p {{ sylius_test_html_attribute('flash-messages') }}>
{% if flash is iterable %}
{{ flash.message|trans(flash.parameters, 'flashes') }}
{% else %}
Expand Down