You are here

public function CustomerProfileTest::testSingleNew in Commerce Core 8.2

Tests the address book in "single" mode, on a new profile entity.

File

modules/order/tests/src/FunctionalJavascript/CustomerProfileTest.php, line 636

Class

CustomerProfileTest
Tests the customer_profile inline form.

Namespace

Drupal\Tests\commerce_order\FunctionalJavascript

Code

public function testSingleNew() {

  /** @var \Drupal\profile\Entity\ProfileTypeInterface $profile_type */
  $profile_type = ProfileType::load('customer');
  $profile_type
    ->setMultiple(FALSE);
  $profile_type
    ->save();

  // Confirm that without a default profile, an empty form is shown.
  $this
    ->drupalGet('/commerce_order_test/customer_profile_test_form');
  foreach ($this->emptyAddress as $property => $value) {
    $this
      ->assertSession()
      ->fieldValueEquals("profile[address][0][address][{$property}]", $value);
  }
  $this
    ->assertSession()
    ->fieldNotExists('profile[copy_to_address_book]');

  // Confirm that the form can be submitted.
  $this
    ->submitForm([
    'profile[address][0][address][given_name]' => 'John',
    'profile[address][0][address][family_name]' => 'Smith',
    'profile[address][0][address][address_line1]' => 'Cetinjska 13',
    'profile[address][0][address][locality]' => 'Belgrade',
  ], 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('The street is "Cetinjska 13" and the country code is RS. Address book: Yes');

  // Create a default profile for the current user.
  $default_profile = Profile::create([
    'type' => 'customer',
    'uid' => $this->adminUser
      ->id(),
    'address' => $this->frenchAddress,
  ]);
  $default_profile
    ->save();

  // Confirm that the profile is rendered, and no address fields are present.
  $this
    ->drupalGet('/commerce_order_test/customer_profile_test_form');
  $this
    ->assertRenderedAddress($this->frenchAddress);
  $this
    ->submitForm([], 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('The street is "38 Rue du Sentier" and the country code is FR. Address book: No');

  // Confirm that it is possible to edit the profile.
  $this
    ->drupalGet('/commerce_order_test/customer_profile_test_form');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('billing_edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  foreach ($this->frenchAddress as $property => $value) {
    $this
      ->assertSession()
      ->fieldValueEquals("profile[address][0][address][{$property}]", $value);
  }
  $this
    ->assertSession()
    ->fieldNotExists('profile[copy_to_address_book]');
  $this
    ->submitForm([
    'profile[address][0][address][address_line1]' => '37 Rue du Sentier',
  ], 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('The street is "37 Rue du Sentier" and the country code is FR. Address book: Yes');
}