diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-08-17 06:08:47 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-08-17 06:08:47 +0000 |
commit | 12893d0bd37976a2cfca7eb0a96f81437d25ed4b (patch) | |
tree | 7c61196709fe29ef85c71ac91f9e7d0a0ab1a8a4 /modules/simpletest/tests/browser.test | |
parent | 8a6d8660cbee1ab28257f4c461a637bb1d6facc3 (diff) | |
download | brdo-12893d0bd37976a2cfca7eb0a96f81437d25ed4b.tar.gz brdo-12893d0bd37976a2cfca7eb0a96f81437d25ed4b.tar.bz2 |
- Patch #340283 by boombatower, dmitrig01 et al: abstract the simpletest broswer in its own class/object.
Diffstat (limited to 'modules/simpletest/tests/browser.test')
-rw-r--r-- | modules/simpletest/tests/browser.test | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/modules/simpletest/tests/browser.test b/modules/simpletest/tests/browser.test new file mode 100644 index 000000000..1f58576ee --- /dev/null +++ b/modules/simpletest/tests/browser.test @@ -0,0 +1,123 @@ +<?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')); + } +} |