[Behat] Use test attributes in PaymentMethod update page

This commit is contained in:
Rafikooo 2024-04-23 10:36:49 +02:00
parent 060bebeb4d
commit 3dc269f189
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Sylius\Behat\Page\Admin\PaymentMethod; namespace Sylius\Behat\Page\Admin\PaymentMethod;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\ChecksCodeImmutability; use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Behaviour\Toggles; use Sylius\Behat\Behaviour\Toggles;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
@ -23,63 +24,96 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
use ChecksCodeImmutability; use ChecksCodeImmutability;
use Toggles; use Toggles;
/**
* @throws ElementNotFoundException
*/
public function setPaypalGatewayUsername(string $username): void public function setPaypalGatewayUsername(string $username): void
{ {
$this->getDocument()->fillField('Username', $username); $this->getDocument()->fillField('Username', $username);
} }
/**
* @throws ElementNotFoundException
*/
public function setPaypalGatewayPassword(string $password): void public function setPaypalGatewayPassword(string $password): void
{ {
$this->getDocument()->fillField('Password', $password); $this->getDocument()->fillField('Password', $password);
} }
/**
* @throws ElementNotFoundException
*/
public function setPaypalGatewaySignature(string $signature): void public function setPaypalGatewaySignature(string $signature): void
{ {
$this->getDocument()->fillField('Signature', $signature); $this->getDocument()->fillField('Signature', $signature);
} }
/**
* @throws ElementNotFoundException
*/
public function nameIt(string $name, string $languageCode): void public function nameIt(string $name, string $languageCode): void
{ {
$this->getDocument()->fillField(sprintf('sylius_payment_method_translations_%s_name', $languageCode), $name); $this->getDocument()->fillField(sprintf('sylius_payment_method_translations_%s_name', $languageCode), $name);
} }
/**
* @throws ElementNotFoundException
*/
public function isPaymentMethodEnabled(): bool public function isPaymentMethodEnabled(): bool
{ {
return (bool) $this->getToggleableElement()->getValue(); return (bool) $this->getToggleableElement()->getValue();
} }
/**
* @throws ElementNotFoundException
*/
public function isFactoryNameFieldDisabled(): bool public function isFactoryNameFieldDisabled(): bool
{ {
return 'disabled' === $this->getElement('factory_name')->getAttribute('disabled'); return 'disabled' === $this->getElement('factory_name')->getAttribute('disabled');
} }
/**
* @throws ElementNotFoundException
*/
public function isAvailableInChannel(string $channelName): bool public function isAvailableInChannel(string $channelName): bool
{ {
return $this->getElement('channel', ['%channel%' => $channelName])->hasAttribute('checked'); return $this->getElement('channel', ['%channel%' => $channelName])->hasAttribute('checked');
} }
/**
* @throws ElementNotFoundException
*/
public function getPaymentMethodInstructions(string $language): string public function getPaymentMethodInstructions(string $language): string
{ {
return $this->getElement('instructions', ['%language%' => $language])->getText(); return $this->getElement('instructions', ['%language%' => $language])->getText();
} }
/**
* @throws ElementNotFoundException
*/
protected function getCodeElement(): NodeElement protected function getCodeElement(): NodeElement
{ {
return $this->getElement('code'); return $this->getElement('code');
} }
/**
* @throws ElementNotFoundException
*/
protected function getToggleableElement(): NodeElement protected function getToggleableElement(): NodeElement
{ {
return $this->getElement('enabled'); return $this->getElement('enabled');
} }
/**
* @return array<string, string>
*/
protected function getDefinedElements(): array protected function getDefinedElements(): array
{ {
return array_merge(parent::getDefinedElements(), [ return array_merge(parent::getDefinedElements(), [
'channel' => '.checkbox:contains("%channel%") input', 'channel' => '[data-test-channels] .form-switch:contains("%channel%") input',
'code' => '#sylius_payment_method_code', 'code' => '[data-test-code]',
'enabled' => '#sylius_payment_method_enabled', 'enabled' => '[data-test-enabled]',
'factory_name' => '#sylius_payment_method_gatewayConfig_factoryName', 'factory_name' => '[data-test-factory-name]',
'instructions' => '#sylius_payment_method_translations_%language%_instructions', 'instructions' => '#sylius_payment_method_translations_%language%_instructions',
'name' => '#sylius_payment_method_translations_en_US_name', 'name' => '#sylius_payment_method_translations_en_US_name',
]); ]);