diff --git a/modules/checkout/src/Plugin/Commerce/CheckoutPane/BillingInformation.php b/modules/checkout/src/Plugin/Commerce/CheckoutPane/BillingInformation.php index d3a4edf..d2fa9c4 100644 --- a/modules/checkout/src/Plugin/Commerce/CheckoutPane/BillingInformation.php +++ b/modules/checkout/src/Plugin/Commerce/CheckoutPane/BillingInformation.php @@ -54,7 +54,6 @@ class BillingInformation extends CheckoutPaneBase implements CheckoutPaneInterfa $this->order->setBillingProfile($pane_form['profile']['#profile']); } - /** * Gets the billing profile. * diff --git a/modules/order/src/Element/ProfileSelect.php b/modules/order/src/Element/ProfileSelect.php index 946a09b..13ffc45 100644 --- a/modules/order/src/Element/ProfileSelect.php +++ b/modules/order/src/Element/ProfileSelect.php @@ -115,8 +115,6 @@ class ProfileSelect extends RenderElement { * The form element being processed. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. - * @param array $complete_form - * The complete form structure. * * @return array * The processed form element. diff --git a/modules/order/tests/src/Functional/OrderAdminTest.php b/modules/order/tests/src/Functional/OrderAdminTest.php index 9476000..104a404 100644 --- a/modules/order/tests/src/Functional/OrderAdminTest.php +++ b/modules/order/tests/src/Functional/OrderAdminTest.php @@ -6,6 +6,7 @@ use Drupal\commerce_order\Adjustment; use Drupal\commerce_order\Entity\Order; use Drupal\commerce_price\Price; use Drupal\profile\Entity\Profile; +use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait; /** * Tests the commerce_order entity forms. @@ -14,28 +15,14 @@ use Drupal\profile\Entity\Profile; */ class OrderAdminTest extends OrderBrowserTestBase { - /** - * The profile to test against. - * - * @var \Drupal\profile\Entity\Profile - */ - protected $billingProfile; + use JavascriptTestTrait; /** * {@inheritdoc} */ - protected function setUp() { - parent::setUp(); - \Drupal::service('module_installer')->install(['profile']); - - $profile_values = [ - 'type' => 'customer', - 'uid' => 1, - 'status' => 1, - ]; - $this->billingProfile = Profile::create($profile_values); - $this->billingProfile->save(); - } + public static $modules = [ + 'profile', + ]; /** * Tests creating/editing an Order. @@ -43,6 +30,9 @@ class OrderAdminTest extends OrderBrowserTestBase { * @group failing */ public function testCreateOrder() { + $assert = $this->assertSession(); + $page = $this->getSession()->getPage(); + // Create an order through the add form. $this->drupalGet('/admin/commerce/orders'); $this->getSession()->getPage()->clickLink('Create a new order'); @@ -55,7 +45,8 @@ class OrderAdminTest extends OrderBrowserTestBase { // Check the integrity of the edit form. $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->fieldExists('billing_profile[0][profile][address][0][address][given_name]'); + $input = $page->find('named', ['id_or_name', 'profile[address][0][address][country_code]']); + $this->assertNotEmpty($input, sprintf('%s was not found', 'country_code')); $this->assertSession()->fieldExists('order_items[form][inline_entity_form][purchased_entity][0][target_id]'); $this->assertSession()->fieldExists('order_items[form][inline_entity_form][quantity][0][value]'); $this->assertSession()->fieldExists('order_items[form][inline_entity_form][unit_price][0][amount][number]'); @@ -91,16 +82,26 @@ class OrderAdminTest extends OrderBrowserTestBase { 'order_items[form][inline_entity_form][entities][0][form][unit_price][0][amount][number]' => '1.11', ]; $this->submitForm($edit, 'Update order item'); - $edit = [ - 'billing_profile[0][profile][address][0][address][given_name]' => 'John', - 'billing_profile[0][profile][address][0][address][family_name]' => 'Smith', - 'billing_profile[0][profile][address][0][address][address_line1]' => '123 street', - 'billing_profile[0][profile][address][0][address][postal_code]' => '94043', - 'billing_profile[0][profile][address][0][address][locality]' => 'Mountain View', - 'billing_profile[0][profile][address][0][address][administrative_area]' => 'CA', - ]; + // There is no adjustment - the order should save successfully. - $this->submitForm($edit, 'Save'); + $input = $page->find('named', ['id_or_name', 'profile[address][0][address][country_code]']); + $this->assertNotEmpty($input, sprintf('%s was not found', 'country_code')); + $input->setValue('US'); + $this->waitForAjaxToFinish(); + $address = [ + 'postal_code' => '53177', + 'locality' => 'Milwaukee', + 'address_line1' => 'Pabst Blue Ribbon Dr', + 'administrative_area' => 'WI', + 'given_name' => 'Frederick', + 'family_name' => 'Pabst', + ]; + foreach ($address as $key => $value) { + $input = $page->find('named', ['id_or_name', "profile[address][0][address][$key]"]); + $this->assertNotEmpty($input, sprintf('%s was not found', $key)); + $input->setValue($value); + } + $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('The order has been successfully saved.'); // Use an adjustment that is not locked by default. diff --git a/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php b/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php index f2f5351..8722252 100644 --- a/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php +++ b/modules/order/tests/src/FunctionalJavascript/ProfileSelectTest.php @@ -212,7 +212,7 @@ class ProfileSelectTest extends CommerceBrowserTestBase { $this->clickLink('Add new profile'); $this->assertNotEmpty($assert->waitForElementVisible('css', '.ui-dialog')); $assert->elementContains('css', 'span.ui-dialog-title', 'Create Customer'); - $input = $page->find('named', ['id_or_name', 'profile[address][0][address][country_code]']); + $input = $page->find('named', ['id_or_name', 'address[0][address][country_code]']); $this->assertNotEmpty($input, sprintf('%s was not found', 'country_code')); $input->setValue($this->address1['country_code']); $this->waitForAjaxToFinish(); @@ -307,13 +307,13 @@ class ProfileSelectTest extends CommerceBrowserTestBase { /** * Click a modal submit button. * + * @param string $text + * The button text. + * * @todo: Switch to using NodeElement::click() on the button or * NodeElement::submit() on the form when #2831506 is fixed. * * @see https://www.drupal.org/node/2831506 - * - * @param string $text - * The button text. */ protected function clickModalSubmit($text) { $this->waitForAjaxToFinish(); diff --git a/modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php b/modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php index 099b70e..75505b5 100644 --- a/modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php +++ b/modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php @@ -34,6 +34,13 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { protected $product; /** + * The profile. + * + * @var \Drupal\profile\Entity\ProfileInterface + */ + protected $profile; + + /** * A non-reusable order payment method. * * @var \Drupal\commerce_payment\Entity\PaymentMethodInterface @@ -148,7 +155,7 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { ]); $gateway->save(); - $profile = $this->createEntity('profile', [ + $this->profile = $this->createEntity('profile', [ 'type' => 'customer', 'address' => [ 'country_code' => 'US', @@ -167,11 +174,11 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { 'payment_gateway' => 'onsite', 'card_type' => 'visa', 'card_number' => '1111', - 'billing_profile' => $profile, + 'billing_profile' => $this->profile, 'reusable' => TRUE, 'expires' => strtotime('2028/03/24'), ]); - $payment_method->setBillingProfile($profile); + $payment_method->setBillingProfile($this->profile); $payment_method->save(); $this->orderPaymentMethod = $this->createEntity('commerce_payment_method', [ @@ -236,7 +243,7 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $this->drupalGet('checkout/1'); $radio_button = $page->findField('Example'); $this->assertNull($radio_button); - $this->assertSession()->fieldExists('payment_information[billing_information][address][0][address][postal_code]'); + $this->assertEquals($page->findField('Select a profile')->getValue(), $this->profile->id()); } /** @@ -289,17 +296,25 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $radio_button->click(); $this->waitForAjaxToFinish(); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); $this->submitForm([ 'payment_information[add_payment_method][payment_details][number]' => '4012888888881881', 'payment_information[add_payment_method][payment_details][expiration][month]' => '02', 'payment_information[add_payment_method][payment_details][expiration][year]' => '2020', 'payment_information[add_payment_method][payment_details][security_code]' => '123', - 'payment_information[add_payment_method][billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[add_payment_method][billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[add_payment_method][billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[add_payment_method][billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[add_payment_method][billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[add_payment_method][billing_information][address][0][address][postal_code]' => '10001', ], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Visa ending in 1881'); @@ -334,17 +349,25 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $radio_button->click(); $this->waitForAjaxToFinish(); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); $this->submitForm([ 'payment_information[add_payment_method][payment_details][number]' => '4111111111111111', 'payment_information[add_payment_method][payment_details][expiration][month]' => '02', 'payment_information[add_payment_method][payment_details][expiration][year]' => '2020', 'payment_information[add_payment_method][payment_details][security_code]' => '123', - 'payment_information[add_payment_method][billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[add_payment_method][billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[add_payment_method][billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[add_payment_method][billing_information][address][0][address][locality]' => 'Somewhere', - 'payment_information[add_payment_method][billing_information][address][0][address][administrative_area]' => 'WI', - 'payment_information[add_payment_method][billing_information][address][0][address][postal_code]' => '53140', ], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Visa ending in 1111'); @@ -372,14 +395,21 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $radio_button->click(); $this->waitForAjaxToFinish(); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); + $this->submitForm([], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Example'); $this->assertSession()->pageTextContains('Johnny Appleseed'); @@ -417,14 +447,21 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $radio_button->click(); $this->waitForAjaxToFinish(); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); + $this->submitForm([], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Example'); $this->assertSession()->pageTextContains('Johnny Appleseed'); @@ -473,14 +510,21 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $this->submitForm([], 'Add to cart'); $this->drupalGet('checkout/1'); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); + $this->submitForm([], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Example'); $this->assertSession()->pageTextContains('Johnny Appleseed'); @@ -517,14 +561,21 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $radio_button->click(); $this->waitForAjaxToFinish(); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'FAIL', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); + $this->submitForm([], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Example'); $this->assertSession()->pageTextContains('Johnny FAIL'); @@ -553,14 +604,21 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { $radio_button->click(); $this->waitForAjaxToFinish(); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); + $this->submitForm([], 'Continue to review'); $this->assertSession()->pageTextContains('Payment information'); $this->assertSession()->pageTextContains('Example'); $this->assertSession()->pageTextContains('Johnny Appleseed'); @@ -595,17 +653,24 @@ class PaymentCheckoutTest extends CommerceBrowserTestBase { ])); $order->save(); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); $this->drupalGet('checkout/1'); $this->assertSession()->pageTextContains('Billing information'); $this->assertSession()->pageTextNotContains('Payment information'); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + $this->submitForm([], 'Continue to review'); $this->assertSession()->pageTextContains('Billing information'); $this->assertSession()->pageTextNotContains('Payment information'); diff --git a/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php b/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php index 8cbf9a3..7376133 100644 --- a/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php +++ b/modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php @@ -34,6 +34,13 @@ class CouponRedemptionPaneTest extends CommerceBrowserTestBase { protected $cartManager; /** + * The profile. + * + * @var \Drupal\profile\Entity\ProfileInterface + */ + protected $profile; + + /** * The promotion. * * @var \Drupal\commerce_promotion\Entity\PromotionInterface @@ -125,7 +132,7 @@ class CouponRedemptionPaneTest extends CommerceBrowserTestBase { ]); $onsite_gateway->save(); - $profile = $this->createEntity('profile', [ + $this->profile = $this->createEntity('profile', [ 'type' => 'customer', 'address' => [ 'country_code' => 'US', @@ -283,24 +290,31 @@ class CouponRedemptionPaneTest extends CommerceBrowserTestBase { * Tests that adding/removing coupons does not submit other panes. */ public function testCheckoutSubmit() { + $page = $this->getSession()->getPage(); // 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->waitForAjaxToFinish(); - $this->submitForm([ - 'payment_information[billing_information][address][0][address][given_name]' => 'Johnny', - 'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed', - 'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive', - 'payment_information[billing_information][address][0][address][locality]' => 'New York City', - 'payment_information[billing_information][address][0][address][administrative_area]' => 'NY', - 'payment_information[billing_information][address][0][address][postal_code]' => '10001', - ], 'Continue to review'); + + $this->assertEquals($page->findField('Select a profile')->getValue(), $this->profile->id()); + $this->submitForm([], 'Continue to review'); // Go back and edit the billing information, but don't submit it. $this->getSession()->getPage()->clickLink('Go back'); - $address_prefix = 'payment_information[billing_information][address][0][address]'; - $this->getSession()->getPage()->fillField($address_prefix . '[given_name]', 'John'); - $this->getSession()->getPage()->fillField($address_prefix . '[family_name]', 'Smith'); + $profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'address' => [ + 'country_code' => 'US', + 'postal_code' => '10001', + 'locality' => 'New York City', + 'address_line1' => '123 New York Drive', + 'administrative_area' => 'NY', + 'given_name' => 'Johnny', + 'family_name' => 'Appleseed', + ], + 'uid' => $this->adminUser->id(), + ]); + $this->getSession()->getPage()->fillField('Select a profile', $profile->id()); // Add a coupon. $coupons = $this->promotion->getCoupons();