diff --git a/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php b/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php index 19ea630..08dd9da 100644 --- a/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php +++ b/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\commerce_order\FunctionalJavascript; use Drupal\Core\Url; -use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; use Drupal\Tests\commerce\FunctionalJavascript\CommerceJavascriptTestBase; /** @@ -14,21 +13,16 @@ use Drupal\Tests\commerce\FunctionalJavascript\CommerceJavascriptTestBase; class ProfileSelectTest extends CommerceJavascriptTestBase { /** - * {@inheritdoc} - */ - protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; - - /** * Profile address values. * * @var array */ protected $address1 = [ 'country_code' => 'HU', - 'given_name' => 'Gustav', 'family_name' => 'Mahler', - 'address_line1' => 'Teréz körút 7', + 'given_name' => 'Gustav', 'locality' => 'Budapest', + 'address_line1' => 'Teréz körút 7', 'postal_code' => '1067', ]; @@ -42,8 +36,8 @@ class ProfileSelectTest extends CommerceJavascriptTestBase { 'given_name' => 'Johann Sebastian', 'family_name' => 'Bach', 'address_line1' => 'Thomaskirchhof 15', - 'locality' => 'Leipzig', 'postal_code' => '04109', + 'locality' => 'Leipzig', ]; /** @@ -227,7 +221,7 @@ class ProfileSelectTest extends CommerceJavascriptTestBase { $this->assertNotEmpty($input, sprintf('%s was not found', $key)); $input->setValue($value); } - $button = $assert->waitForButton('Save and make default'); + $button = $page->find('css', '.ui-dialog .form-actions button:nth-child(2)'); $button->press(); $this->submitForm([], 'Submit'); @@ -289,7 +283,7 @@ class ProfileSelectTest extends CommerceJavascriptTestBase { $input = $page->find('named', ['id_or_name', 'address[0][address][address_line1]']); $input->setValue('Andrássy út 22'); $assert->assertWaitOnAjaxRequest(); - $button = $assert->waitForButton('Save'); + $button = $page->find('css', '.ui-dialog button.button--primary'); $button->press(); $this->submitForm([], 'Submit'); diff --git a/modules/payment/src/PluginForm/PaymentMethodEditForm.php b/modules/payment/src/PluginForm/PaymentMethodEditForm.php index 8d195b2..f129f1c 100644 --- a/modules/payment/src/PluginForm/PaymentMethodEditForm.php +++ b/modules/payment/src/PluginForm/PaymentMethodEditForm.php @@ -67,7 +67,10 @@ class PaymentMethodEditForm extends PaymentGatewayFormBase implements ContainerI $form['billing_information'] = [ '#parents' => array_merge($form['#parents'], ['billing_information']), '#type' => 'commerce_profile_select', - '#default_value' => $billing_profile, + '#title' => t('Select an address'), + '#profile_type' => 'customer', + '#profile_uid' => $payment_method->getOwnerId(), + '#$profile' => $billing_profile, '#default_country' => $store ? $store->getAddress()->getCountryCode() : NULL, '#available_countries' => $store ? $store->getBillingCountries() : [], '#weight' => 50, diff --git a/modules/payment/tests/src/FunctionalJavascript/PaymentMethodTest.php b/modules/payment/tests/src/FunctionalJavascript/PaymentMethodTest.php index 3da4ca2..8680c09 100644 --- a/modules/payment/tests/src/FunctionalJavascript/PaymentMethodTest.php +++ b/modules/payment/tests/src/FunctionalJavascript/PaymentMethodTest.php @@ -1,16 +1,16 @@ user = $this->drupalCreateUser($permissions); $this->drupalLogin($this->user); @@ -78,9 +80,12 @@ class PaymentMethodTest extends CommerceBrowserTestBase { * Tests creating and updating a payment method. */ public function testPaymentMethodCreationAndUpdate() { + $page = $this->getSession()->getPage(); + $assert = $this->assertSession(); + /** @var \Drupal\commerce_payment_example\Plugin\Commerce\PaymentGateway\OnsiteInterface $plugin */ $this->drupalGet($this->collectionUrl); - $this->getSession()->getPage()->clickLink('Add payment method'); + $page->clickLink('Add payment method'); $this->assertSession()->addressEquals($this->collectionUrl . '/add'); $form_values = [ @@ -96,8 +101,8 @@ class PaymentMethodTest extends CommerceBrowserTestBase { 'payment_method[billing_information][address][0][address][postal_code]' => '10001', ]; $this->submitForm($form_values, 'Save'); - $this->assertSession()->addressEquals($this->collectionUrl); - $this->assertSession()->pageTextContains('Visa ending in 1111 saved to your payment methods.'); + $assert->addressEquals($this->collectionUrl); + $assert->pageTextContains('Visa ending in 1111 saved to your payment methods.'); $payment_method = PaymentMethod::load(1); $billing_profile = $payment_method->getBillingProfile(); @@ -106,20 +111,29 @@ class PaymentMethodTest extends CommerceBrowserTestBase { $this->assertEquals(1, $payment_method->getBillingProfile()->id()); $this->drupalGet($this->collectionUrl . '/' . $payment_method->id() . '/edit'); + + $this->clickLink('Edit profile'); + $this->assertNotEmpty($assert->waitForElementVisible('css', '.ui-dialog')); + $address = [ + 'locality' => 'Greenville', + 'administrative_area' => 'SC', + 'postal_code' => '29615', + ]; + foreach ($address as $key => $value) { + $input = $page->find('named', ['id_or_name', "address[0][address][$key]"]); + $input->setValue($value); + } + $button = $page->find('css', '.ui-dialog button.button--primary'); + $button->press(); + $form_values = [ 'payment_method[payment_details][expiration][month]' => '02', 'payment_method[payment_details][expiration][year]' => '2026', - 'payment_method[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_method[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_method[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_method[billing_information][address][0][address][locality]' => 'Greenville', - 'payment_method[billing_information][address][0][address][administrative_area]' => 'SC', - 'payment_method[billing_information][address][0][address][postal_code]' => '29615', ]; $this->submitForm($form_values, 'Save'); - $this->assertSession()->addressEquals($this->collectionUrl); + $assert->addressEquals($this->collectionUrl); - $this->assertSession()->pageTextContains('2/2026'); + $assert->pageTextContains('2/2026'); \Drupal::entityTypeManager()->getStorage('commerce_payment_method')->resetCache([1]); \Drupal::entityTypeManager()->getStorage('profile')->resetCache([1]); diff --git a/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php b/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php index 0d274c5..5f70b96 100644 --- a/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php +++ b/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php @@ -7,7 +7,6 @@ use Drupal\commerce_order\Entity\OrderItemType; use Drupal\commerce_payment\Entity\PaymentGateway; use Drupal\commerce_price\Price; use Drupal\Core\Url; -use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; use Drupal\Tests\commerce\FunctionalJavascript\CommerceJavascriptTestBase; /** @@ -18,11 +17,6 @@ use Drupal\Tests\commerce\FunctionalJavascript\CommerceJavascriptTestBase; class CouponRedemptionPaneTest extends CommerceJavascriptTestBase { /** - * {@inheritdoc} - */ - protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; - - /** * The cart order to test against. * * @var \Drupal\commerce_order\Entity\OrderInterface @@ -292,10 +286,11 @@ class CouponRedemptionPaneTest extends CommerceJavascriptTestBase { */ public function testCheckoutSubmit() { $page = $this->getSession()->getPage(); + $assert = $this->assertSession(); // Start checkout, and enter billing information. $this->drupalGet(Url::fromRoute('commerce_checkout.form', ['commerce_order' => $this->cart->id()])); - $this->getSession()->getPage()->findField('Example')->check(); - $this->assertSession()->assertWaitOnAjaxRequest(); + $page->findField('edit-payment-information-payment-method-offsite')->setValue('offsite'); + $assert->assertWaitOnAjaxRequest(); $this->assertEquals($page->findField('Select an address')->getValue(), $this->adminProfile->id()); $this->submitForm([], 'Continue to review'); @@ -310,18 +305,17 @@ class CouponRedemptionPaneTest extends CommerceJavascriptTestBase { $page = $this->getSession()->getPage(); $page->fillField('Coupon code', $coupon->getCode()); $page->pressButton('Apply coupon'); - $this->assertSession()->assertWaitOnAjaxRequest(); - $this->assertSession()->pageTextContains($coupon->getCode()); - $this->assertSession()->fieldNotExists('Coupon code'); - $this->assertSession()->buttonNotExists('Apply coupon'); + $assert->assertWaitOnAjaxRequest(); + $assert->pageTextContains($coupon->getCode()); + $assert->fieldNotExists('Coupon code'); + $assert->buttonNotExists('Apply coupon'); // Refresh the page and ensure the billing information hasn't been modified. $this->drupalGet(Url::fromRoute('commerce_checkout.form', ['commerce_order' => $this->cart->id(), 'step' => 'order_information'])); $page = $this->getSession()->getPage(); - $given_name_field = $page->findField('payment_information[billing_information][address][0][address][given_name]'); - $family_name_field = $page->findField('payment_information[billing_information][address][0][address][family_name]'); - $this->assertEquals($given_name_field->getValue(), 'Johnny'); - $this->assertEquals($family_name_field->getValue(), 'Appleseed'); + $profile_field = $page->findField('payment_information[billing_information][profile_selection]'); + $this->assertEquals($profile_field->getValue(), 1); + $assert->pageTextContains('Milwaukee, WI 53177'); } } diff --git a/tests/src/FunctionalJavascript/CommerceJavascriptTestBase.php b/tests/src/FunctionalJavascript/CommerceJavascriptTestBase.php index 7a87c18..4b43c63 100644 --- a/tests/src/FunctionalJavascript/CommerceJavascriptTestBase.php +++ b/tests/src/FunctionalJavascript/CommerceJavascriptTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\commerce\FunctionalJavascript; use Drupal\Component\Render\FormattableMarkup; use Drupal\commerce_store\StoreCreationTrait; +use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\BlockCreationTrait; @@ -16,6 +17,11 @@ abstract class CommerceJavascriptTestBase extends JavascriptTestBase { use StoreCreationTrait; /** + * {@inheritdoc} + */ + protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; + + /** * The store entity. * * @var \Drupal\commerce_store\Entity\Store