public function AddressDefaultWidgetTest::testSubdivisions in Address 8
Tests the presence of subdivision dropdowns where expected.
File
- tests/
src/ FunctionalJavascript/ AddressDefaultWidgetTest.php, line 428
Class
- AddressDefaultWidgetTest
- Tests the default address widget.
Namespace
Drupal\Tests\address\FunctionalJavascriptCode
public function testSubdivisions() {
$field_name = $this->field
->getName();
// Using China since it has predefined subdivisions on all three levels.
$country = 'CN';
$administrative_area = 'Hebei Sheng';
$locality = 'Chengde Shi';
$administrative_areas = $this->subdivisionRepository
->getList([
$country,
]);
$localities = $this->subdivisionRepository
->getList([
$country,
$administrative_area,
]);
$dependent_localities = $this->subdivisionRepository
->getList([
$country,
$administrative_area,
$locality,
]);
// Confirm the presence and format of the administrative area dropdown.
$this
->drupalGet($this->nodeAddUrl);
$this
->getSession()
->getPage()
->fillField($field_name . '[0][address][country_code]', $country);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertOptions($field_name . '[0][address][administrative_area]', array_keys($administrative_areas), 'All administrative areas for country ' . $country . ' are present.');
// Confirm the presence and format of the locality dropdown.
$this
->getSession()
->getPage()
->fillField($field_name . '[0][address][administrative_area]', $administrative_area);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertOptionSelected($field_name . '[0][address][administrative_area]', $administrative_area, 'Selected administrative area ' . $administrative_areas[$administrative_area]);
$this
->assertOptions($field_name . '[0][address][locality]', array_keys($localities), 'All localities for administrative area ' . $administrative_areas[$administrative_area] . ' are present.');
// Confirm the presence and format of the dependent locality dropdown.
$this
->getSession()
->getPage()
->fillField($field_name . '[0][address][locality]', $locality);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertOptionSelected($field_name . '[0][address][locality]', $locality, 'Selected locality ' . $localities[$locality]);
$this
->assertOptions($field_name . '[0][address][dependent_locality]', array_keys($dependent_localities), 'All dependent localities for locality ' . $localities[$locality] . ' are present.');
}