protected function UbercartQuoteTestCase::selectQuote in Ubercart 7.3
Simulates selection of a quote on the checkout page.
Parameters
int $n: The index of the quote to select.
File
- shipping/
uc_quote/ tests/ uc_quote.test, line 103 - Ubercart Shipping Quote Tests.
Class
- UbercartQuoteTestCase
- SimpleTests for Ubercart Shipping Quotes.
Code
protected function selectQuote($n) {
// Get the list of available quotes.
$xpath = '//*[@name="panes[quotes][quotes][quote_option]"]';
$elements = $this
->xpath($xpath);
$vals = array();
foreach ($elements as $element) {
$vals[(string) $element['id']] = (string) $element['value'];
}
// Set the checked attribute of the chosen quote.
$dom = new DOMDocument();
$dom
->loadHTML($this->content);
$i = 0;
$selected = '';
foreach ($vals as $id => $value) {
if ($i == $n) {
$dom
->getElementById($id)
->setAttribute('checked', 'checked');
$selected = $value;
}
else {
$dom
->getElementById($id)
->removeAttribute('checked');
}
$i++;
}
$this
->drupalSetContent($dom
->saveHTML());
// Post the selection via Ajax.
$option = array(
'panes[quotes][quotes][quote_option]' => $selected,
);
return $this
->drupalPostAjax(NULL, array(), $option);
}