00001 <?php
00002
00003
00007 class DrupalWebTestCase extends UnitTestCase {
00008 protected $_logged_in = FALSE;
00009 protected $_content;
00010 protected $plain_text;
00011 protected $ch;
00012 protected $elements;
00013 protected $_modules = array();
00014
00015
00016 protected $cookie_file = NULL;
00017
00018
00019 protected $curl_options = array();
00020 protected $db_prefix_original;
00021 protected $original_file_directory;
00022
00028 function __construct($label = NULL) {
00029 if (!$label) {
00030 if (method_exists($this, 'getInfo')) {
00031 $info = $this->getInfo();
00032 $label = $info['name'];
00033 }
00034 }
00035 parent::__construct($label);
00036 }
00037
00046 function drupalCreateNode($settings = array()) {
00047
00048 $defaults = array(
00049 'body' => $this->randomName(32),
00050 'title' => $this->randomName(8),
00051 'comment' => 2,
00052 'changed' => time(),
00053 'format' => FILTER_FORMAT_DEFAULT,
00054 'moderate' => 0,
00055 'promote' => 0,
00056 'revision' => 1,
00057 'log' => '',
00058 'status' => 1,
00059 'sticky' => 0,
00060 'type' => 'page',
00061 'revisions' => NULL,
00062 'taxonomy' => NULL,
00063 );
00064 $defaults['teaser'] = $defaults['body'];
00065
00066 if (isset($defaults['created'])) {
00067 $defaults['date'] = format_date($defaults['created'], 'custom', 'Y-m-d H:i:s O');
00068 }
00069 if (empty($settings['uid'])) {
00070 global $user;
00071 $defaults['uid'] = $user->uid;
00072 }
00073 $node = ($settings + $defaults);
00074 $node = (object)$node;
00075
00076 node_save($node);
00077
00078
00079 db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid);
00080 return $node;
00081 }
00082
00091 function drupalCreateContentType($settings = array()) {
00092
00093 do {
00094 $name = strtolower($this->randomName(3, 'type_'));
00095 } while (node_get_types('type', $name));
00096
00097
00098 $defaults = array(
00099 'type' => $name,
00100 'name' => $name,
00101 'description' => '',
00102 'help' => '',
00103 'min_word_count' => 0,
00104 'title_label' => 'Title',
00105 'body_label' => 'Body',
00106 'has_title' => 1,
00107 'has_body' => 1,
00108 );
00109
00110 $forced = array(
00111 'orig_type' => '',
00112 'old_type' => '',
00113 'module' => 'node',
00114 'custom' => 1,
00115 'modified' => 1,
00116 'locked' => 0,
00117 );
00118 $type = $forced + $settings + $defaults;
00119 $type = (object)$type;
00120
00121 node_type_save($type);
00122 node_types_rebuild();
00123
00124 return $type;
00125 }
00126
00134 function drupalGetTestFiles($type, $size = NULL) {
00135 $files = array();
00136
00137
00138 if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) {
00139
00140 $path = $this->original_file_directory . '/simpletest';
00141 $files = file_scan_directory($path, $type . '\-.*');
00142
00143
00144 if ($size !== NULL) {
00145 foreach ($files as $file) {
00146 $stats = stat($file->filename);
00147 if ($stats['size'] != $size) {
00148 unset($files[$file->filename]);
00149 }
00150 }
00151 }
00152 }
00153 usort($files, array($this, 'drupalCompareFiles'));
00154 return $files;
00155 }
00156
00160 function drupalCompareFiles($file1, $file2) {
00161 if (stat($file1->filename) > stat($file2->filename)) {
00162 return 1;
00163 }
00164 return -1;
00165 }
00166
00174 function randomName($number = 4, $prefix = 'simpletest_') {
00175 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
00176 for ($x = 0; $x < $number; $x++) {
00177 $prefix .= $chars{mt_rand(0, strlen($chars) - 1)};
00178 if ($x == 0) {
00179 $chars .= '0123456789';
00180 }
00181 }
00182 return $prefix;
00183 }
00184
00193 function drupalModuleEnable($name) {
00194 if (module_exists($name)) {
00195 return $this->pass(t('@name module already enabled', array('@name' => $name)), t('Module'));
00196 }
00197 $this->_modules[$name] = $name;
00198 $form_state['values'] = array('status' => $this->_modules, 'op' => t('Save configuration'));
00199 drupal_execute('system_modules', $form_state);
00200
00201
00202 drupal_rebuild_theme_registry();
00203 node_types_rebuild();
00204 menu_rebuild();
00205 cache_clear_all('schema', 'cache');
00206 module_rebuild_cache();
00207
00208 return $this->assertTrue(module_exists($name), t('@name enabled.', array('@name' => $name)), t('Module'));
00209 }
00210
00218 function drupalModuleDisable($name) {
00219 if (!module_exists($name)) {
00220 return $this->pass(t('@name module already disabled', array('@name' => $name)), t('Module'));
00221 }
00222 unset($this->_modules[$key]);
00223 $form_state['values'] = array('status' => $this->_modules, 'op' => t('Save configuration'));
00224 drupal_execute('system_modules', $form_state);
00225
00226
00227 drupal_rebuild_theme_registry();
00228 node_types_rebuild();
00229 menu_rebuild();
00230 cache_clear_all('schema', 'cache');
00231 module_rebuild_cache();
00232
00233 return $this->assertTrue(!module_exists($name), t('@name disabled.', array('@name' => $name)), t('Module'));
00234 }
00235
00244 function drupalCreateUser($permissions = NULL) {
00245
00246 $rid = $this->_drupalCreateRole($permissions);
00247 if (!$rid) {
00248 return FALSE;
00249 }
00250
00251
00252 $edit = array();
00253 $edit['name'] = $this->randomName();
00254 $edit['mail'] = $edit['name'] . '@example.com';
00255 $edit['roles'] = array($rid => $rid);
00256 $edit['pass'] = user_password();
00257 $edit['status'] = 1;
00258
00259 $account = user_save('', $edit);
00260
00261 $this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login'));
00262 if (empty($account->uid)) {
00263 return FALSE;
00264 }
00265
00266
00267 $account->pass_raw = $edit['pass'];
00268 return $account;
00269 }
00270
00277 private function _drupalCreateRole($permissions = NULL) {
00278
00279 if ($permissions === NULL) {
00280 $permissions = array('access comments', 'access content', 'post comments', 'post comments without approval');
00281 }
00282
00283
00284 $role_name = $this->randomName();
00285 db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name);
00286 $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = '%s'", $role_name));
00287 $this->assertTrue($role, t('Created role of name: @role_name, id: @rid', array('@role_name' => $role_name, '@rid' => (isset($role->rid) ? $role->rid : t('-n/a-')))), t('Role'));
00288 if ($role && !empty($role->rid)) {
00289
00290 foreach ($permissions as $permission_string) {
00291 db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", $role->rid, $permission_string);
00292 }
00293 $count = db_result(db_query("SELECT COUNT(*) FROM {role_permission} WHERE rid = %d", $role->rid));
00294 $this->assertTrue($count == count($permissions), t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role'));
00295 return $role->rid;
00296 }
00297 else {
00298 return FALSE;
00299 }
00300 }
00301
00311 function drupalLogin($user = NULL) {
00312 if ($this->_logged_in) {
00313 $this->drupalLogout();
00314 }
00315
00316 if (!isset($user)) {
00317 $user = $this->_drupalCreateRole();
00318 }
00319
00320 $edit = array(
00321 'name' => $user->name,
00322 'pass' => $user->pass_raw
00323 );
00324 $this->drupalPost('user', $edit, t('Log in'));
00325
00326 $pass = $this->assertText($user->name, t('Found name: %name', array('%name' => $user->name)), t('User login'));
00327 $pass = $pass && $this->assertNoText(t('The username %name has been blocked.', array('%name' => $user->name)), t('No blocked message at login page'), t('User login'));
00328 $pass = $pass && $this->assertNoText(t('The name %name is a reserved username.', array('%name' => $user->name)), t('No reserved message at login page'), t('User login'));
00329
00330 $this->_logged_in = $pass;
00331
00332 return $user;
00333 }
00334
00335
00336
00337
00338 function drupalLogout() {
00339
00340 $this->drupalGet('logout');
00341
00342
00343 $this->drupalGet('user');
00344 $pass = $this->assertField('name', t('Username field found.'), t('Logout'));
00345 $pass = $pass && $this->assertField('pass', t('Password field found.'), t('Logout'));
00346
00347 $this->_logged_in = !$pass;
00348 }
00349
00358 function setUp() {
00359 global $db_prefix;
00360
00361
00362 $this->db_prefix_original = $db_prefix;
00363 $clean_url_original = variable_get('clean_url', 0);
00364
00365
00366 $db_prefix = 'simpletest' . mt_rand(1000, 1000000);
00367 include_once './includes/install.inc';
00368 drupal_install_system();
00369
00370
00371 $args = func_get_args();
00372 $modules = array_unique(array_merge(drupal_verify_profile('default', 'en'), $args));
00373 drupal_install_modules($modules);
00374
00375
00376 $this->_modules = drupal_map_assoc($modules);
00377 $this->_modules['system'] = 'system';
00378
00379
00380 $task = 'profile';
00381 default_profile_tasks($task, '');
00382
00383
00384 menu_rebuild();
00385 actions_synchronize();
00386 _drupal_flush_css_js();
00387 $this->refreshVariables();
00388
00389
00390 variable_set('install_profile', 'default');
00391 variable_set('install_task', 'profile-finished');
00392 variable_set('clean_url', $clean_url_original);
00393
00394
00395 $this->original_file_directory = file_directory_path();
00396 variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix);
00397 file_check_directory(file_directory_path(), TRUE);
00398
00399 parent::setUp();
00400 }
00401
00414 function refreshVariables() {
00415 global $conf;
00416 cache_clear_all('variables', 'cache');
00417 $conf = variable_init();
00418 }
00419
00424 function tearDown() {
00425 global $db_prefix;
00426 if (preg_match('/simpletest\d+/', $db_prefix)) {
00427
00428 simpletest_clean_temporary_directory(file_directory_path());
00429 variable_set('file_directory_path', $this->original_file_directory);
00430
00431
00432 $schema = drupal_get_schema(NULL, TRUE);
00433 $ret = array();
00434 foreach ($schema as $name => $table) {
00435 db_drop_table($ret, $name);
00436 }
00437
00438
00439 $db_prefix = $this->db_prefix_original;
00440
00441
00442 $this->_logged_in = FALSE;
00443
00444
00445 $this->curlClose();
00446 }
00447 parent::tearDown();
00448 }
00449
00453 function run(&$reporter) {
00454 $arr = array('class' => get_class($this));
00455 if (method_exists($this, 'getInfo')) {
00456 $arr = array_merge($arr, $this->getInfo());
00457 }
00458 $reporter->test_info_stack[] = $arr;
00459 parent::run($reporter);
00460 array_pop($reporter->test_info_stack);
00461 }
00462
00470 protected function curlConnect() {
00471 global $base_url, $db_prefix;
00472 if (!isset($this->ch)) {
00473 $this->ch = curl_init();
00474 $curl_options = $this->curl_options + array(
00475 CURLOPT_COOKIEJAR => $this->cookie_file,
00476 CURLOPT_URL => $base_url,
00477 CURLOPT_FOLLOWLOCATION => TRUE,
00478 CURLOPT_RETURNTRANSFER => TRUE,
00479 );
00480 if (preg_match('/simpletest\d+/', $db_prefix)) {
00481 $curl_options[CURLOPT_USERAGENT] = $db_prefix;
00482 }
00483 if (!isset($curl_options[CURLOPT_USERPWD]) && ($auth = variable_get('simpletest_httpauth_username', ''))) {
00484 if ($pass = variable_get('simpletest_httpauth_pass', '')) {
00485 $auth .= ':' . $pass;
00486 }
00487 $curl_options[CURLOPT_USERPWD] = $auth;
00488 }
00489 return $this->curlExec($curl_options);
00490 }
00491 }
00492
00499 protected function curlExec($curl_options) {
00500 $this->curlConnect();
00501 $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
00502 curl_setopt_array($this->ch, $this->curl_options + $curl_options);
00503 $this->_content = curl_exec($this->ch);
00504 $this->plain_text = FALSE;
00505 $this->elements = FALSE;
00506 $this->assertTrue($this->_content !== FALSE, t('!method to !url, response is !length bytes.', array('!method' => empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST', '!url' => $url, '!length' => strlen($this->_content))), t('Browser'));
00507 return $this->_content;
00508 }
00509
00513 protected function curlClose() {
00514 if (isset($this->ch)) {
00515 curl_close($this->ch);
00516 unset($this->ch);
00517 }
00518 }
00519
00525 protected function parse() {
00526 if (!$this->elements) {
00527
00528
00529 @$htmlDom = DOMDocument::loadHTML($this->_content);
00530 if ($htmlDom) {
00531 $this->assertTrue(TRUE, t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser'));
00532
00533
00534 $this->elements = simplexml_import_dom($htmlDom);
00535 }
00536 }
00537 if (!$this->elements) {
00538 $this->fail(t('Parsed page successfully.'), t('Browser'));
00539 }
00540 return $this->elements;
00541 }
00542
00550 function drupalGet($path, $options = array()) {
00551 $options['absolute'] = TRUE;
00552
00553
00554
00555
00556 $out = $this->curlExec(array(CURLOPT_URL => url($path, $options), CURLOPT_POST => FALSE, CURLOPT_POSTFIELDS => array()));
00557 $this->refreshVariables();
00558 return $out;
00559 }
00560
00580 function drupalPost($path, $edit, $submit, $tamper = FALSE) {
00581 $submit_matches = FALSE;
00582 if (isset($path)) {
00583 $html = $this->drupalGet($path);
00584 }
00585 if ($this->parse()) {
00586 $edit_save = $edit;
00587
00588 $forms = $this->elements->xpath('//form');
00589 foreach ($forms as $form) {
00590 if ($tamper) {
00591
00592
00593 }
00594 else {
00595
00596 $edit = $edit_save;
00597 $post = array();
00598 $upload = array();
00599 $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form);
00600 $action = isset($form['action']) ? $this->getAbsoluteUrl($form['action']) : $this->getUrl();
00601 }
00602
00603
00604 if (!$edit && $submit_matches) {
00605
00606 if ($upload) {
00607 foreach ($post as &$value) {
00608 if (strlen($value) > 0 && $value[0] == '@') {
00609 $this->fail(t("Can't upload and post a value starting with @"));
00610 return FALSE;
00611 }
00612 }
00613 foreach ($upload as $key => $file) {
00614 $post[$key] = '@' . realpath($file);
00615 }
00616 }
00617 else {
00618 $post_array = $post;
00619 $post = array();
00620 foreach ($post_array as $key => $value) {
00621
00622
00623 $post[] = urlencode($key) . '=' . urlencode($value);
00624 }
00625 $post = implode('&', $post);
00626 }
00627 $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $post, CURLOPT_POST => TRUE));
00628 $this->refreshVariables();
00629 return $out;
00630 }
00631 }
00632
00633 $this->fail(t('Found the requested form at @path', array('@path' => $path)));
00634 $this->assertTrue($submit_matches, t('Found the @submit button', array('@submit' => $submit)));
00635 foreach ($edit as $name => $value) {
00636 $this->fail(t('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
00637 }
00638 }
00639 }
00640
00652 protected function handleForm(&$post, &$edit, &$upload, $submit, $form) {
00653
00654 $elements = $form->xpath('.//input|.//textarea|.//select');
00655 $submit_matches = FALSE;
00656 foreach ($elements as $element) {
00657
00658 $name = (string)$element['name'];
00659
00660
00661 $type = isset($element['type']) ? (string)$element['type'] : $element->getName();
00662 $value = isset($element['value']) ? (string)$element['value'] : '';
00663 $done = FALSE;
00664 if (isset($edit[$name])) {
00665 switch ($type) {
00666 case 'text':
00667 case 'textarea':
00668 case 'password':
00669 $post[$name] = $edit[$name];
00670 unset($edit[$name]);
00671 break;
00672 case 'radio':
00673 if ($edit[$name] == $value) {
00674 $post[$name] = $edit[$name];
00675 unset($edit[$name]);
00676 }
00677 break;
00678 case 'checkbox':
00679
00680
00681
00682 if ($edit[$name] === FALSE) {
00683 unset($edit[$name]);
00684 continue 2;
00685 }
00686 else {
00687 unset($edit[$name]);
00688 $post[$name] = $value;
00689 }
00690 break;
00691 case 'select':
00692 $new_value = $edit[$name];
00693 $index = 0;
00694 $key = preg_replace('/\[\]$/', '', $name);
00695 $options = $this->getAllOptions($element);
00696 foreach ($options as $option) {
00697 if (is_array($new_value)) {
00698 $option_value= (string)$option['value'];
00699 if (in_array($option_value, $new_value)) {
00700 $post[$key . '[' . $index++ . ']'] = $option_value;
00701 $done = TRUE;
00702 unset($edit[$name]);
00703 }
00704 }
00705 elseif ($new_value == $option['value']) {
00706 $post[$name] = $new_value;
00707 unset($edit[$name]);
00708 $done = TRUE;
00709 }
00710 }
00711 break;
00712 case 'file':
00713 $upload[$name] = $edit[$name];
00714 unset($edit[$name]);
00715 break;
00716 }
00717 }
00718 if (!isset($post[$name]) && !$done) {
00719 switch ($type) {
00720 case 'textarea':
00721 $post[$name] = (string)$element;
00722 break;
00723 case 'select':
00724 $single = empty($element['multiple']);
00725 $first = TRUE;
00726 $index = 0;
00727 $key = preg_replace('/\[\]$/', '', $name);
00728 $options = $this->getAllOptions($element);
00729 foreach ($options as $option) {
00730
00731
00732 if ($option['selected'] || ($first && $single)) {
00733 $first = FALSE;
00734 if ($single) {
00735 $post[$name] = (string)$option['value'];
00736 }
00737 else {
00738 $post[$key . '[' . $index++ . ']'] = (string)$option['value'];
00739 }
00740 }
00741 }
00742 break;
00743 case 'file':
00744 break;
00745 case 'submit':
00746 case 'image':
00747 if ($submit == $value) {
00748 $post[$name] = $value;
00749 $submit_matches = TRUE;
00750 }
00751 break;
00752 case 'radio':
00753 case 'checkbox':
00754 if (!isset($element['checked'])) {
00755 break;
00756 }
00757
00758 default:
00759 $post[$name] = $value;
00760 }
00761 }
00762 }
00763 return $submit_matches;
00764 }
00765
00772 private function getAllOptions(SimpleXMLElement $element) {
00773 $options = array();
00774
00775 foreach ($element->option as $option) {
00776 $options[] = $option;
00777 }
00778
00779
00780 if (isset($element->optgroup)) {
00781 $options = array_merge($options, $this->getAllOptions($element->optgroup));
00782 }
00783 return $options;
00784 }
00785
00800 function clickLink($label, $index = 0) {
00801 $url_before = $this->getUrl();
00802 $ret = FALSE;
00803 if ($this->parse()) {
00804 $urls = $this->elements->xpath('//a[text()="' . $label . '"]');
00805 if (isset($urls[$index])) {
00806 $url_target = $this->getAbsoluteUrl($urls[$index]['href']);
00807 $curl_options = array(CURLOPT_URL => $url_target);
00808 $ret = $this->curlExec($curl_options);
00809 }
00810 $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'));
00811 }
00812 return $ret;
00813 }
00814
00824 function getAbsoluteUrl($path) {
00825 $options = array('absolute' => TRUE);
00826 $parts = parse_url($path);
00827
00828 if (empty($parts['host'])) {
00829 $path = $parts['path'];
00830 $base_path = base_path();
00831 $n = strlen($base_path);
00832 if (substr($path, 0, $n) == $base_path) {
00833 $path = substr($path, $n);
00834 }
00835 if (isset($parts['query'])) {
00836 $options['query'] = $parts['query'];
00837 }
00838 $path = url($path, $options);
00839 }
00840 return $path;
00841 }
00842
00848 function getUrl() {
00849 return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL);
00850 }
00851
00855 function drupalGetContent() {
00856 return $this->_content;
00857 }
00858
00867 function assertRaw($raw, $message = "%s", $group = 'Other') {
00868 return $this->assertFalse(strpos($this->_content, $raw) === FALSE, $message, $group);
00869 }
00870
00879 function assertNoRaw($raw, $message = "%s", $group = 'Other') {
00880 return $this->assertTrue(strpos($this->_content, $raw) === FALSE, $message, $group);
00881 }
00882
00892 function assertText($text, $message = '', $group = 'Other') {
00893 return $this->assertTextHelper($text, $message, $group = 'Other', FALSE);
00894 }
00895
00905 function assertNoText($text, $message = '', $group = 'Other') {
00906 return $this->assertTextHelper($text, $message, $group, TRUE);
00907 }
00908
00918 protected function assertTextHelper($text, $message, $group, $not_exists) {
00919 if ($this->plain_text === FALSE) {
00920 $this->plain_text = filter_xss($this->_content, array());
00921 }
00922 if (!$message) {
00923 $message = '"' . $text . '"' . ($not_exists ? ' not found.' : ' found.');
00924 }
00925 return $this->assertTrue($not_exists == (strpos($this->plain_text, $text) === FALSE), $message, $group);
00926 }
00927
00935 function assertPattern($pattern, $message = '%s', $group = 'Other') {
00936 return $this->assertTrue(preg_match($pattern, $this->drupalGetContent()), $message, $group);
00937 }
00938
00946 function assertNoPattern($pattern, $message = '%s', $group = 'Other') {
00947 return $this->assertFalse(preg_match($pattern, $this->drupalGetContent()), $message, $group);
00948 }
00949
00957 function assertTitle($title, $message, $group = 'Other') {
00958 return $this->assertTrue($this->parse() && $this->elements->xpath('//title[text()="' . $title . '"]'), $message, $group);
00959 }
00960
00969 function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
00970 $fields = array();
00971 if ($this->parse()) {
00972 $fields = $this->elements->xpath($xpath);
00973 }
00974
00975
00976 $found = TRUE;
00977 if ($value) {
00978 $found = FALSE;
00979 foreach ($fields as $field) {
00980 if ($field['value'] == $value) {
00981 $found = TRUE;
00982 }
00983 }
00984 }
00985 return $this->assertTrue($fields && $found, $message, $group);
00986 }
00987
00996 function assertNoFieldByXPath($xpath, $value, $message, $group = 'Other') {
00997 $fields = array();
00998 if ($this->parse()) {
00999 $fields = $this->elements->xpath($xpath);
01000 }
01001
01002
01003 $found = TRUE;
01004 if ($value) {
01005 $found = FALSE;
01006 foreach ($fields as $field) {
01007 if ($field['value'] == $value) {
01008 $found = TRUE;
01009 }
01010 }
01011 }
01012 return $this->assertFalse($fields && $found, $message, $group);
01013 }
01014
01023 function assertFieldByName($name, $value = '', $message = '') {
01024 return $this->assertFieldByXPath($this->_constructFieldXpath('name', $name), $value, $message ? $message : t('Found field by name @name', array('@name' => $name)), t('Browser'));
01025 }
01026
01035 function assertNoFieldByName($name, $value = '', $message = '') {
01036 return $this->assertNoFieldByXPath($this->_constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), t('Browser'));
01037 }
01038
01047 function assertFieldById($id, $value = '', $message = '') {
01048 return $this->assertFieldByXPath($this->_constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), t('Browser'));
01049 }
01050
01059 function assertNoFieldById($id, $value = '', $message = '') {
01060 return $this->assertNoFieldByXPath($this->_constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), t('Browser'));
01061 }
01062
01070 function assertField($field, $message = '', $group = 'Other') {
01071 return $this->assertFieldByXPath($this->_constructFieldXpath('name', $field) . '|' . $this->_constructFieldXpath('id', $field), '', $message, $group);
01072 }
01073
01081 function assertNoField($field, $message = '', $group = 'Other') {
01082 return $this->assertNoFieldByXPath($this->_constructFieldXpath('name', $field) . '|' . $this->_constructFieldXpath('id', $field), '', $message, $group);
01083 }
01084
01092 function _constructFieldXpath($attribute, $value) {
01093 return '//textarea[@' . $attribute . '="' . $value . '"]|//input[@' . $attribute . '="' . $value . '"]|//select[@' . $attribute . '="' . $value . '"]';
01094 }
01095
01104 function assertResponse($code, $message = '') {
01105 $curl_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
01106 $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
01107 return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser'));
01108 }
01109 }