Commit 12893d0b authored by Dries's avatar Dries

- Patch #340283 by boombatower, dmitrig01 et al: abstract the simpletest...

- Patch #340283 by boombatower, dmitrig01 et al: abstract the simpletest broswer in its own class/object.
parent 8a6d8660
This diff is collapsed.
......@@ -14,6 +14,7 @@ files[] = drupal_web_test_case.php
files[] = tests/actions.test
files[] = tests/batch.test
files[] = tests/bootstrap.test
files[] = tests/browser.test
files[] = tests/cache.test
files[] = tests/common.test
files[] = tests/database_test.test
......
<?php
// $Id$
/**
* @file
* Tests for the internal web browser.
*/
/**
* Test general browser functionality.
*/
class BrowserTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('Browser'),
'description' => t('Test general browser functionality.'),
'group' => t('Browser'),
);
}
public function setUp() {
parent::setUp('browser_test');
}
/**
* Test general browser functionality.
*/
public function testBrowserBackend() {
global $db_prefix;
$browser = new Browser();
$browser->setUserAgent(drupal_generate_test_ua($db_prefix));
// Check browser refresh, both meta tag and HTTP header.
$request = $browser->get(url('browser_test/refresh/meta', array('absolute' => TRUE)));
$this->assertEqual($request['content'], 'Refresh successful', 'Meta refresh successful ($request)');
$this->assertEqual($browser->getContent(), 'Refresh successful', 'Meta refresh successful ($browser)');
$request = $browser->get(url('browser_test/refresh/header', array('absolute' => TRUE)));
$this->assertEqual($request['content'], 'Refresh successful', 'Meta refresh successful ($request)');
$this->assertEqual($browser->getContent(), 'Refresh successful', 'Meta refresh successful ($browser)');
}
}
/**
* Test browser backend wrappers.
*/
class BrowserBackendTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('Browser - wrapper backends'),
'description' => t('Test stream and curl backends execution of GET and POST requests.'),
'group' => t('Browser'),
);
}
public function setUp() {
parent::setUp('browser_test');
}
/**
* Test stream and curl backends execution of GET and POST requests.
*/
public function testBrowserBackend() {
global $db_prefix;
foreach (array('stream', 'curl') as $wrapper) {
$browser = new Browser($wrapper == 'stream');
$browser->setUserAgent(drupal_generate_test_ua($db_prefix));
$string = $this->randomName();
$edit = array(
'foo' => $string,
);
// Test GET method.
$request = $browser->get(url('browser_test/print/get', array('absolute' => TRUE, 'query' => $edit)));
$this->assertEqual($string, $request['content'], t('String found during GET request ($request)'), $wrapper);
$this->assertEqual($string, $browser->getContent(), t('String found during GET request ($browser)'), $wrapper);
// Test POST method.
$request = $browser->post(url('browser_test/print/post', array('absolute' => TRUE)), $edit, t('Submit'));
$this->assertEqual($string, $request['content'], t('String found during POST request ($request)'), $wrapper);
$this->assertEqual($string, $browser->getContent(), t('String found during POST request ($browser)'), $wrapper);
}
}
}
/**
* Test browser page manipulation functionality.
*/
class BrowserPageTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('Browser - page'),
'description' => t('Check "BrowserPage" class functionality.'),
'group' => t('Browser'),
);
}
public function setUp() {
parent::setUp('browser_test');
}
/**
* Check "BrowserPage" class functionality.
*/
public function testBrowserPage() {
global $db_prefix;
$browser = new Browser();
$browser->setUserAgent(drupal_generate_test_ua($db_prefix));
$browser->get(url('browser_test/print/post', array('absolute' => TRUE)));
$page = $browser->getPage();
$input = $page->xpath('//input[@name="foo"]');
$input = $input[0];
$this->assertEqual('foo', $input['name'], t('Field "foo" found'));
}
}
; $Id$
name = Browser test
description = Provide various pages for testing the browser.
package = Testing
version = VERSION
core = 7.x
files[] = browser_test.module
hidden = TRUE
<?php
// $Id$
/**
* @file
* Provide various pages for testing the internal browser.
*/
/**
* Implement hook_menu().
*/
function browser_test_menu() {
$items = array();
$items['browser_test/print/get'] = array(
'page callback' => 'browser_test_print_get',
'access arguments' => array('access content'),
);
$items['browser_test/print/post'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('browser_test_print_post_form'),
'access arguments' => array('access content'),
);
$items['browser_test/refresh/meta'] = array(
'page callback' => 'browser_test_refresh_meta',
'access arguments' => array('access content'),
);
$items['browser_test/refresh/header'] = array(
'page callback' => 'browser_test_refresh_header',
'access arguments' => array('access content'),
);
return $items;
}
function browser_test_print_get() {
echo $_GET['foo'];
exit;
}
function browser_test_print_post_form(&$form_state) {
$form = array();
$form['foo'] = array(
'#type' => 'textfield',
);
$form['op'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function browser_test_print_post_form_submit($form, &$form_state) {
echo $form_state['values']['foo'];
exit;
}
function browser_test_refresh_meta() {
if (!isset($_GET['refresh'])) {
$url = url('browser_test/refresh/meta', array('absolute' => TRUE, 'query' => 'refresh=true'));
drupal_add_html_head('<meta http-equiv="Refresh" content="0; URL=' . $url . '">');
return '';
}
echo 'Refresh successful';
exit;
}
function browser_test_refresh_header() {
if (!isset($_GET['refresh'])) {
$url = url('browser_test/refresh/header', array('absolute' => TRUE, 'query' => 'refresh=true'));
drupal_set_header('Location', $url);
return '';
}
echo 'Refresh successful';
exit;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment