You are here

protected function AddressElementTest::setUp in Ubercart 8.4

Overrides BrowserTestBase::setUp

File

uc_store/tests/src/FunctionalJavascript/AddressElementTest.php, line 53

Class

AddressElementTest
Tests Ajax for the uc_address form element country and zone selection.

Namespace

Drupal\Tests\uc_store\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();

  // Need to have some permissions to access the test page.
  $this->adminUser = $this
    ->drupalCreateUser(static::$adminPermissions);
  $this
    ->drupalLogin($this->adminUser);

  // Enable a random selection of 20 countries so we're not always
  // testing with the 1 site default.
  $countries = \Drupal::service('country_manager')
    ->getAvailableList();
  $country_ids = array_rand($countries, 20);
  foreach ($country_ids as $country_id) {

    // Don't use the country UI, we're not testing that here...
    Country::load($country_id)
      ->enable()
      ->save();
  }

  // Last one of the 20 gets to be the store default country.
  $store_settings = \Drupal::configFactory()
    ->getEditable('uc_store.settings');
  $store_settings
    ->set('address.country', $country_id)
    ->save();

  // Create a random address object for use in tests.
  $this->testAddresses[] = $this
    ->createAddress();
}