diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 6279d59b4a8..8422558c342 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -876,7 +876,7 @@ class DrupalWebTestCase { if ($this->parse()) { $edit_save = $edit; // Let's iterate over all the forms. - $forms = $this->elements->xpath('//form'); + $forms = $this->xpath('//form'); foreach ($forms as $form) { // We try to set the fields of this form as specified in $edit. $edit = $edit_save; @@ -1067,6 +1067,24 @@ class DrupalWebTestCase { return $submit_matches; } + /** + * Peform an xpath search on the contents of the internal browser. The search + * is relative to the root element (HTML tag normally) of the page. + * + * @param $xpath + * The xpath string to use in the search. + * @return + * The return value of the xpath search. For details on the xpath string + * format and return values see the SimpleXML documentation. + * http://us.php.net/manual/function.simplexml-element-xpath.php + */ + public function xpath($xpath) { + if ($this->parse()) { + return $this->elements->xpath($xpath); + } + return FALSE; + } + /** * Get all option elements, including nested options, in a select. * @@ -1108,15 +1126,13 @@ class DrupalWebTestCase { function clickLink($label, $index = 0) { $url_before = $this->getUrl(); $ret = FALSE; - if ($this->parse()) { - $urls = $this->elements->xpath('//a[text()="' . $label . '"]'); - if (isset($urls[$index])) { - $url_target = $this->getAbsoluteUrl($urls[$index]['href']); - $curl_options = array(CURLOPT_URL => $url_target); - $ret = $this->curlExec($curl_options); - } - $this->assertTrue($ret, t('Clicked link !label (!url_target) from !url_before', array('!label' => $label, '!url_target' => $url_target, '!url_before' => $url_before)), t('Browser')); + $urls = $this->xpath('//a[text()="' . $label . '"]'); + if (isset($urls[$index])) { + $url_target = $this->getAbsoluteUrl($urls[$index]['href']); + $curl_options = array(CURLOPT_URL => $url_target); + $ret = $this->curlExec($curl_options); } + $this->assertTrue($ret, t('Clicked link !label (!url_target) from !url_before', array('!label' => $label, '!url_target' => $url_target, '!url_before' => $url_before)), t('Browser')); return $ret; } @@ -1322,7 +1338,7 @@ class DrupalWebTestCase { * TRUE on pass, FALSE on fail. */ function assertTitle($title, $message, $group = 'Other') { - return $this->_assert($this->parse() && $this->elements->xpath('//title[text()="' . $title . '"]'), $message, $group); + return $this->_assert($this->xpath('//title[text()="' . $title . '"]') !== FALSE, $message, $group); } /** @@ -1340,18 +1356,17 @@ class DrupalWebTestCase { * TRUE on pass, FALSE on fail. */ function assertFieldByXPath($xpath, $value, $message, $group = 'Other') { - $fields = array(); - if ($this->parse()) { - $fields = $this->elements->xpath($xpath); - } + $fields = $this->xpath($xpath); // If value specified then check array for match. $found = TRUE; if ($value) { $found = FALSE; - foreach ($fields as $field) { - if ($field['value'] == $value) { - $found = TRUE; + if ($fields) { + foreach ($fields as $field) { + if ($field['value'] == $value) { + $found = TRUE; + } } } } @@ -1373,18 +1388,17 @@ class DrupalWebTestCase { * TRUE on pass, FALSE on fail. */ function assertNoFieldByXPath($xpath, $value, $message, $group = 'Other') { - $fields = array(); - if ($this->parse()) { - $fields = $this->elements->xpath($xpath); - } + $fields = $this->xpath($xpath); // If value specified then check array for match. $found = TRUE; if ($value) { $found = FALSE; - foreach ($fields as $field) { - if ($field['value'] == $value) { - $found = TRUE; + if ($fields) { + foreach ($fields as $field) { + if ($field['value'] == $value) { + $found = TRUE; + } } } } diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test index c66a6dd55c4..a2e212b5772 100644 --- a/modules/simpletest/simpletest.test +++ b/modules/simpletest/simpletest.test @@ -190,7 +190,7 @@ class SimpleTestTestCase extends DrupalWebTestCase { * @return fieldset containing the results for group this test is in. */ function getResultFieldSet() { - $fieldsets = $this->elements->xpath('//fieldset'); + $fieldsets = $this->xpath('//fieldset'); $info = $this->getInfo(); foreach ($fieldsets as $fieldset) { if ($fieldset->legend == $info['group']) { diff --git a/modules/syslog/syslog.test b/modules/syslog/syslog.test index 65026b867a9..a9693d676e0 100644 --- a/modules/syslog/syslog.test +++ b/modules/syslog/syslog.test @@ -40,7 +40,7 @@ class SyslogTestCase extends DrupalWebTestCase { $this->drupalGet('admin/settings/logging/syslog'); if ($this->parse()) { - $field = $this->elements->xpath('//option[@value="' . $edit['syslog_facility'] . '"]'); // Should be one field. + $field = $this->xpath('//option[@value="' . $edit['syslog_facility'] . '"]'); // Should be one field. $this->assertTrue($field[0]['selected'] == 'selected', t('Facility value saved.')); } } diff --git a/modules/system/system.test b/modules/system/system.test index 22fc1fb6057..c3950fca8b7 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -283,7 +283,7 @@ class AdminOverviewTestCase extends DrupalWebTestCase { if ($this->parse()) { $found = 0; $extra = 0; - $divs = $this->elements->xpath("//div[@class='admin-panel']"); + $divs = $this->xpath("//div[@class='admin-panel']"); foreach ($divs as $panel) { if (in_array(trim($panel->h3), $panels)) { $found++;