public function AddressDefaultWidgetTest::testClearValues in Address 8
Tests that changing the country clears the expected values.
File
- tests/
src/ FunctionalJavascript/ AddressDefaultWidgetTest.php, line 459
Class
- AddressDefaultWidgetTest
- Tests the default address widget.
Namespace
Drupal\Tests\address\FunctionalJavascriptCode
public function testClearValues() {
$field_name = $this->field
->getName();
// Create an article with all fields filled.
$this
->drupalGet($this->nodeAddUrl);
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName(8);
// Use javascript to fill country_code so other fields can be loaded.
$this
->getSession()
->getPage()
->fillField($field_name . '[0][address][country_code]', 'US');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$edit[$field_name . '[0][address][given_name]'] = 'John';
$edit[$field_name . '[0][address][family_name]'] = 'Smith';
$edit[$field_name . '[0][address][organization]'] = 'Some Organization';
$edit[$field_name . '[0][address][address_line1]'] = '1098 Alta Ave';
$edit[$field_name . '[0][address][address_line2]'] = 'Street 2';
$edit[$field_name . '[0][address][locality]'] = 'Mountain View';
$edit[$field_name . '[0][address][administrative_area]'] = 'CA';
$edit[$field_name . '[0][address][postal_code]'] = '94043';
$this
->submitForm($edit, t('Save'));
$node = $this
->getNodeByTitle($edit['title[0][value]']);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][country_code]', 'US');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][administrative_area]', 'CA');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][locality]', 'Mountain View');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][postal_code]', '94043');
// Now change the country to China, subdivision fields should be cleared.
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->getSession()
->getPage()
->fillField($field_name . '[0][address][country_code]', 'CN');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->submitForm([], t('Save'));
// Check that values are cleared.
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][country_code]', 'CN');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][administrative_area]', '');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][locality]', '');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][dependent_locality]', '');
$this
->assertSession()
->fieldValueEquals($field_name . '[0][address][postal_code]', '');
}