diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-08-22 12:35:55 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-08-22 12:35:55 +0000 |
commit | c15bcc0653bbeff88c44d5d9e6a199ccb35e9c22 (patch) | |
tree | 2c58de5e38920265a377a620f2f12f638ffe4e61 | |
parent | f0b1d9f8d3070c82bc067522f1e63210017c0ac7 (diff) | |
download | brdo-c15bcc0653bbeff88c44d5d9e6a199ccb35e9c22.tar.gz brdo-c15bcc0653bbeff88c44d5d9e6a199ccb35e9c22.tar.bz2 |
- Patch #297869 by boombatower: add xpath method to simpletest and refactor existing tests.
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 62 | ||||
-rw-r--r-- | modules/simpletest/simpletest.test | 2 | ||||
-rw-r--r-- | modules/syslog/syslog.test | 2 | ||||
-rw-r--r-- | modules/system/system.test | 2 |
4 files changed, 41 insertions, 27 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; + } } } } diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test index c66a6dd55..a2e212b57 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 65026b867..a9693d676 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 22fc1fb60..c3950fca8 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++; |