diff options
Diffstat (limited to 'site/app/tests/test_helper_web.php')
-rw-r--r-- | site/app/tests/test_helper_web.php | 133 |
1 files changed, 4 insertions, 129 deletions
diff --git a/site/app/tests/test_helper_web.php b/site/app/tests/test_helper_web.php index 81ec63f..68cdb34 100644 --- a/site/app/tests/test_helper_web.php +++ b/site/app/tests/test_helper_web.php @@ -18,9 +18,6 @@ class WebTestHelper extends WebTestCase { /** * The default SimpleBrowser tries to parse all responses, even when * they're not HTML. That fails. We need a better browser. - * - * Creates a new default web browser object. - * Will be cleared at the end of the test method. */ function &createBrowser() { $browser =& new BetterBrowser(); @@ -95,49 +92,11 @@ class WebTestHelper extends WebTestCase { } /** - * Check that there is a link like <a href=$href>$text</a>. + * Check that there is a link like <a href=$href>$title</a>. */ - function assertLinkLocation($href, $text) { - phpQuery::newDocument($this->_browser->getContent()); - $q = pq("a[href$={$href}"); - $msg = htmlentities("<a href='{$href}'>{$text}</a> exists"); - $this->assertEqual($q->text(), $text, $msg); - } - - /** - * Check that the element $q has the attributes in the $attrs array. - * $q can be a phpquery object or a selector string. - */ - function assertAttrs($q, $attrs, $msg) { - if (is_string($q)) { - phpQuery::newDocument($this->_browser->getContent()); - $q = pq($q); - } - foreach ($attrs as $attr => $val) { - $this->assertEqual($q->attr($attr), $val, $msg); - } - } - - /* Helper to normalize whitespace in a string. */ - function _norm($x) { - return implode(' ', preg_split('/\s+/', trim($x))); - } - - /* Assert that the strings have the same content, ignoring whitespace. */ - function assertEquiv($a, $b, $msg=null) { - $this->assertEqual($this->_norm($a), $this->_norm($b)); - } - - function delete($url, $parameters = false) { - return $this->_failOnError($this->_browser->delete($url, $parameters)); - } - - function put($url, $parameters = false) { - return $this->_failOnError($this->_browser->put($url, $parameters)); - } - - function postMultipart($url, $parameters = false, $files = false) { - return $this->_failOnError($this->_browser->postMultipart($url, $parameters, $files)); + function assertLinkLocation($href, $title) { + $pattern = '#<a [^>]*href="[^"]*'.$href.'"[^>]*>'.$title.'</a>#'; + $this->assertWantedPattern($pattern, htmlentities($pattern)); } } @@ -156,89 +115,5 @@ class BetterBrowser extends SimpleBrowser { } return $page; } - - /* Define $this->_browser->skipParse to avoid the HTML parsing overhead. */ - function &_fetch($url, $encoding, $depth=0) { - if (isset($this->skipParse)) { - $response = &$this->_user_agent->fetchResponse($url, $encoding); - $page = new SimplePage($response); - return $page; - } else { - return parent::_fetch($url, $encoding, $depth); - } - } - - function delete($url, $parameters = false) { - if (! is_object($url)) { - $url = new SimpleUrl($url); - } - if ($this->getUrl()) { - $url = $url->makeAbsolute($this->getUrl()); - } - return $this->_load($url, new SimpleDeleteEncoding($parameters)); - } - - function put($url, $parameters = false) { - if (! is_object($url)) { - $url = new SimpleUrl($url); - } - if ($this->getUrl()) { - $url = $url->makeAbsolute($this->getUrl()); - } - return $this->_load($url, new SimplePutEncoding($parameters)); - } - - /** - * Multipart POST request. May contain file attachments. - * @param string $url target URL - * @param array $parameters array of POST parameters - * @param array $files further POST parameters of type key => path to file to attach - */ - function postMultipart($url, $parameters = false, $files = false) { - if (! is_object($url)) { - $url = new SimpleUrl($url); - } - if ($this->getUrl()) { - $url = $url->makeAbsolute($this->getUrl()); - } - // prepare multipart encoding - $encoding = new SimpleMultipartEncoding($parameters); - // attach files if needed - if (!empty($files) && is_array($files)) { - foreach($files as $k => &$f) { - if (! file_exists($f)) continue; - $encoding->attach( - $k, - implode('', file($f)), - basename($f)); - } - } - - return $this->_load($url, $encoding); - } -} - -/** - * Bundle of URL parameters for a DELETE request. - */ -class SimpleDeleteEncoding extends SimpleGetEncoding { - function SimpleDeleteEncoding($query = false) { - $this->SimpleGetEncoding($query); - } - function getMethod() { - return 'DELETE'; - } -} - -/** - * Bundle of URL parameters for a PUT request. - */ -class SimplePutEncoding extends SimplePostEncoding { - function SimplePutEncoding($query = false) { - $this->SimplePostEncoding($query); - } - function getMethod() { - return 'PUT'; - } } ?> |