protected function QuoteTest::selectCountry in Ubercart 8.4
Simulates selection of a delivery country on the checkout page.
Parameters
string $country_id: The ISO 3166 2-character country code to select. Country must be enabled for this to work.
File
- shipping/
uc_quote/ src/ Tests/ QuoteTest.php, line 91
Class
- QuoteTest
- Tests shipping quote functionality.
Namespace
Drupal\uc_quote\TestsCode
protected function selectCountry($country_id) {
$country_name = \Drupal::service('country_manager')
->getCountry($country_id)->name;
$dom = new \DOMDocument();
$dom
->loadHTML($this->content);
$parent = $dom
->getElementById('edit-panes-delivery-delivery-country');
$options = $parent
->getElementsByTagName('option');
for ($i = 0; $i < $options->length; $i++) {
if ($options
->item($i)->textContent == $country_name) {
$options
->item($i)
->setAttribute('selected', 'selected');
}
else {
$options
->item($i)
->removeAttribute('selected');
}
}
$this
->setRawContent($dom
->saveHTML());
return $this
->drupalPostAjaxForm(NULL, [], 'panes[delivery][country]');
}