You are here

protected function UbercartQuoteTestCase::selectCountry in Ubercart 7.3

Simulates selection of a delivery country on the checkout page.

Parameters

string $country: The text version of the country name to select, e.g. "Canada" or "United States".

File

shipping/uc_quote/tests/uc_quote.test, line 80
Ubercart Shipping Quote Tests.

Class

UbercartQuoteTestCase
SimpleTests for Ubercart Shipping Quotes.

Code

protected function selectCountry($country = "Canada") {
  $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) {
      $options
        ->item($i)
        ->setAttribute('selected', 'selected');
    }
    else {
      $options
        ->item($i)
        ->removeAttribute('selected');
    }
  }
  $this
    ->drupalSetContent($dom
    ->saveHTML());
  return $this
    ->drupalPostAjax(NULL, array(), 'panes[delivery][delivery_country]');
}