summaryrefslogtreecommitdiff
path: root/modules/simpletest/drupal_web_test_case.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r--modules/simpletest/drupal_web_test_case.php62
1 files changed, 38 insertions, 24 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 6279d59b4..8422558c3 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;
@@ -1068,6 +1068,24 @@ class DrupalWebTestCase {
}
/**
+ * 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.
*
* @param $element
@@ -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;
+ }
}
}
}