Source for file web_tester.php

Documentation is available at web_tester.php

  1. <?php
  2. /**
  3.  *  Base include file for SimpleTest.
  4.  *  @package    SimpleTest
  5.  *  @subpackage WebTester
  6.  *  @version    $Id: web_tester.php 1723 2008-04-08 00:34:10Z lastcraft $
  7.  */
  8.  
  9. /**#@+
  10.  *  include other SimpleTest class files
  11.  */
  12. require_once(dirname(__FILE__'/test_case.php');
  13. require_once(dirname(__FILE__'/browser.php');
  14. require_once(dirname(__FILE__'/page.php');
  15. require_once(dirname(__FILE__'/expectation.php');
  16. /**#@-*/
  17.  
  18.  *    Test for an HTML widget value match.
  19.  *    @package SimpleTest
  20.  *    @subpackage WebTester
  21.  */
  22.     var $_value;
  23.     
  24.     /**
  25.      *    Sets the field value to compare against.
  26.      *    @param mixed $value     Test value to match. Can be an
  27.      *                             expectation for say pattern matching.
  28.      *    @param string $message  Optiona message override. Can use %s as
  29.      *                             a placeholder for the original message.
  30.      *    @access public
  31.      */
  32.     function FieldExpectation($value$message '%s'{
  33.         $this->SimpleExpectation($message);
  34.         if (is_array($value)) {
  35.             sort($value);
  36.         }
  37.         $this->_value = $value;
  38.     }
  39.     
  40.     /**
  41.      *    Tests the expectation. True if it matches
  42.      *    a string value or an array value in any order.
  43.      *    @param mixed $compare        Comparison value. False for
  44.      *                                  an unset field.
  45.      *    @return boolean              True if correct.
  46.      *    @access public
  47.      */
  48.     function test($compare{
  49.         if ($this->_value === false{
  50.             return ($compare === false);
  51.         }
  52.         if ($this->_isSingle($this->_value)) {
  53.             return $this->_testSingle($compare);
  54.         }
  55.         if (is_array($this->_value)) {
  56.             return $this->_testMultiple($compare);
  57.         }
  58.         return false;
  59.     }
  60.     
  61.     /**
  62.      *    Tests for valid field comparisons with a single option.
  63.      *    @param mixed $value       Value to type check.
  64.      *    @return boolean           True if integer, string or float.
  65.      *    @access private
  66.      */
  67.     function _isSingle($value{
  68.         return is_string($value|| is_integer($value|| is_float($value);
  69.     }
  70.     
  71.     /**
  72.      *    String comparison for simple field with a single option.
  73.      *    @param mixed $compare    String to test against.
  74.      *    @returns boolean         True if matching.
  75.      *    @access private
  76.      */
  77.     function _testSingle($compare{
  78.         if (is_array($compare&& count($compare== 1{
  79.             $compare $compare[0];
  80.         }
  81.         if ($this->_isSingle($compare)) {
  82.             return false;
  83.         }
  84.         return ($this->_value == $compare);
  85.     }
  86.     
  87.     /**
  88.      *    List comparison for multivalue field.
  89.      *    @param mixed $compare    List in any order to test against.
  90.      *    @returns boolean         True if matching.
  91.      *    @access private
  92.      */
  93.     function _testMultiple($compare{
  94.         if (is_string($compare)) {
  95.             $compare array($compare);
  96.         }
  97.         if (is_array($compare)) {
  98.             return false;
  99.         }
  100.         sort($compare);
  101.         return ($this->_value === $compare);
  102.     }
  103.     
  104.     /**
  105.      *    Returns a human readable test message.
  106.      *    @param mixed $compare      Comparison value.
  107.      *    @return string             Description of success
  108.      *                                or failure.
  109.      *    @access public
  110.      */
  111.     function testMessage($compare{
  112.         $dumper &$this->_getDumper();
  113.         if (is_array($compare)) {
  114.             sort($compare);
  115.         }
  116.         if ($this->test($compare)) {
  117.             return "Field expectation [" $dumper->describeValue($this->_value"]";
  118.         else {
  119.             return "Field expectation [" $dumper->describeValue($this->_value.
  120.                     "] fails with [" .
  121.                     $dumper->describeValue($compare"] " .
  122.                     $dumper->describeDifference($this->_value$compare);
  123.         }
  124.     }
  125. }
  126.  
  127. /**
  128.  *    Test for a specific HTTP header within a header block.
  129.  *    @package SimpleTest
  130.  *    @subpackage WebTester
  131.  */
  132.     var $_expected_header;
  133.     var $_expected_value;
  134.     
  135.     /**
  136.      *    Sets the field and value to compare against.
  137.      *    @param string $header   Case insenstive trimmed header name.
  138.      *    @param mixed $value     Optional value to compare. If not
  139.      *                             given then any value will match. If
  140.      *                             an expectation object then that will
  141.      *                             be used instead.
  142.      *    @param string $message  Optiona message override. Can use %s as
  143.      *                             a placeholder for the original message.
  144.      */
  145.     function HttpHeaderExpectation($header$value false$message '%s'{
  146.         $this->SimpleExpectation($message);
  147.         $this->_expected_header = $this->_normaliseHeader($header);
  148.         $this->_expected_value = $value;
  149.     }
  150.     
  151.     /**
  152.      *    Accessor for aggregated object.
  153.      *    @return mixed        Expectation set in constructor.
  154.      *    @access protected
  155.      */
  156.     function _getExpectation({
  157.         return $this->_expected_value;
  158.     }
  159.     
  160.     /**
  161.      *    Removes whitespace at ends and case variations.
  162.      *    @param string $header    Name of header.
  163.      *    @param string            Trimmed and lowecased header
  164.      *                              name.
  165.      *    @access private
  166.      */
  167.     function _normaliseHeader($header{
  168.         return strtolower(trim($header));
  169.     }
  170.     
  171.     /**
  172.      *    Tests the expectation. True if it matches
  173.      *    a string value or an array value in any order.
  174.      *    @param mixed $compare   Raw header block to search.
  175.      *    @return boolean         True if header present.
  176.      *    @access public
  177.      */
  178.     function test($compare{
  179.         return is_string($this->_findHeader($compare));
  180.     }
  181.     
  182.     /**
  183.      *    Searches the incoming result. Will extract the matching
  184.      *    line as text.
  185.      *    @param mixed $compare   Raw header block to search.
  186.      *    @return string          Matching header line.
  187.      *    @access protected
  188.      */
  189.     function _findHeader($compare{
  190.         $lines split("\r\n"$compare);
  191.         foreach ($lines as $line{
  192.             if ($this->_testHeaderLine($line)) {
  193.                 return $line;
  194.             }
  195.         }
  196.         return false;
  197.     }
  198.     
  199.     /**
  200.      *    Compares a single header line against the expectation.
  201.      *    @param string $line      A single line to compare.
  202.      *    @return boolean          True if matched.
  203.      *    @access private
  204.      */
  205.     function _testHeaderLine($line{
  206.         if (count($parsed split(':'$line2)) 2{
  207.             return false;
  208.         }
  209.         list($header$value$parsed;
  210.         if ($this->_normaliseHeader($header!= $this->_expected_header{
  211.             return false;
  212.         }
  213.         return $this->_testHeaderValue($value$this->_expected_value);
  214.     }
  215.     
  216.     /**
  217.      *    Tests the value part of the header.
  218.      *    @param string $value        Value to test.
  219.      *    @param mixed $expected      Value to test against.
  220.      *    @return boolean             True if matched.
  221.      *    @access protected
  222.      */
  223.     function _testHeaderValue($value$expected{
  224.         if ($expected === false{
  225.             return true;
  226.         }
  227.         if (SimpleExpectation::isExpectation($expected)) {
  228.             return $expected->test(trim($value));
  229.         }
  230.         return (trim($value== trim($expected));
  231.     }
  232.     
  233.     /**
  234.      *    Returns a human readable test message.
  235.      *    @param mixed $compare      Raw header block to search.
  236.      *    @return string             Description of success
  237.      *                                or failure.
  238.      *    @access public
  239.      */
  240.     function testMessage($compare{
  241.         if (SimpleExpectation::isExpectation($this->_expected_value)) {
  242.             $message $this->_expected_value->overlayMessage($compare$this->_getDumper());
  243.         else {
  244.             $message $this->_expected_header .
  245.                     ($this->_expected_value ? ': ' $this->_expected_value : '');
  246.         }
  247.         if (is_string($line $this->_findHeader($compare))) {
  248.             return "Searching for header [$message] found [$line]";
  249.         else {
  250.             return "Failed to find header [$message]";
  251.         }
  252.     }
  253. }
  254.     
  255. /**
  256.  *    Test for a specific HTTP header within a header block that
  257.  *    should not be found.
  258.  *    @package SimpleTest
  259.  *    @subpackage WebTester
  260.  */
  261.     var $_expected_header;
  262.     var $_expected_value;
  263.     
  264.     /**
  265.      *    Sets the field and value to compare against.
  266.      *    @param string $unwanted   Case insenstive trimmed header name.
  267.      *    @param string $message    Optiona message override. Can use %s as
  268.      *                               a placeholder for the original message.
  269.      */
  270.     function NoHttpHeaderExpectation($unwanted$message '%s'{
  271.         $this->HttpHeaderExpectation($unwantedfalse$message);
  272.     }
  273.     
  274.     /**
  275.      *    Tests that the unwanted header is not found.
  276.      *    @param mixed $compare   Raw header block to search.
  277.      *    @return boolean         True if header present.
  278.      *    @access public
  279.      */
  280.     function test($compare{
  281.         return ($this->_findHeader($compare=== false);
  282.     }
  283.     
  284.     /**
  285.      *    Returns a human readable test message.
  286.      *    @param mixed $compare      Raw header block to search.
  287.      *    @return string             Description of success
  288.      *                                or failure.
  289.      *    @access public
  290.      */
  291.     function testMessage($compare{
  292.         $expectation $this->_getExpectation();
  293.         if (is_string($line $this->_findHeader($compare))) {
  294.             return "Found unwanted header [$expectation] with [$line]";
  295.         else {
  296.             return "Did not find unwanted header [$expectation]";
  297.         }
  298.     }
  299. }
  300.  
  301. /**
  302.  *    Test for a text substring.
  303.  *    @package SimpleTest
  304.  *    @subpackage UnitTester
  305.  */
  306.     var $_substring;
  307.     
  308.     /**
  309.      *    Sets the value to compare against.
  310.      *    @param string $substring  Text to search for.
  311.      *    @param string $message    Customised message on failure.
  312.      *    @access public
  313.      */
  314.     function TextExpectation($substring$message '%s'{
  315.         $this->SimpleExpectation($message);
  316.         $this->_substring = $substring;
  317.     }
  318.     
  319.     /**
  320.      *    Accessor for the substring.
  321.      *    @return string       Text to match.
  322.      *    @access protected
  323.      */
  324.     function _getSubstring({
  325.         return $this->_substring;
  326.     }
  327.     
  328.     /**
  329.      *    Tests the expectation. True if the text contains the
  330.      *    substring.
  331.      *    @param string $compare        Comparison value.
  332.      *    @return boolean               True if correct.
  333.      *    @access public
  334.      */
  335.     function test($compare{
  336.         return (strpos($compare$this->_substring!== false);
  337.     }
  338.     
  339.     /**
  340.      *    Returns a human readable test message.
  341.      *    @param mixed $compare      Comparison value.
  342.      *    @return string             Description of success
  343.      *                                or failure.
  344.      *    @access public
  345.      */
  346.     function testMessage($compare{
  347.         if ($this->test($compare)) {
  348.             return $this->_describeTextMatch($this->_getSubstring()$compare);
  349.         else {
  350.             $dumper &$this->_getDumper();
  351.             return "Text [" $this->_getSubstring(.
  352.                     "] not detected in [" .
  353.                     $dumper->describeValue($compare"]";
  354.         }
  355.     }
  356.     
  357.     /**
  358.      *    Describes a pattern match including the string
  359.      *    found and it's position.
  360.      *    @param string $substring      Text to search for.
  361.      *    @param string $subject        Subject to search.
  362.      *    @access protected
  363.      */
  364.     function _describeTextMatch($substring$subject{
  365.         $position strpos($subject$substring);
  366.         $dumper &$this->_getDumper();
  367.         return "Text [$substring] detected at character [$position] in [.
  368.                 $dumper->describeValue($subject"] in region [" .
  369.                 $dumper->clipString($subject100$position"]";
  370.     }
  371. }
  372.  
  373. /**
  374.  *    Fail if a substring is detected within the
  375.  *    comparison text.
  376.  *    @package SimpleTest
  377.  *    @subpackage UnitTester
  378.  */
  379.     
  380.     /**
  381.      *    Sets the reject pattern
  382.      *    @param string $substring  Text to search for.
  383.      *    @param string $message    Customised message on failure.
  384.      *    @access public
  385.      */
  386.     function NoTextExpectation($substring$message '%s'{
  387.         $this->TextExpectation($substring$message);
  388.     }
  389.     
  390.     /**
  391.      *    Tests the expectation. False if the substring appears
  392.      *    in the text.
  393.      *    @param string $compare        Comparison value.
  394.      *    @return boolean               True if correct.
  395.      *    @access public
  396.      */
  397.     function test($compare{
  398.         return parent::test($compare);
  399.     }
  400.     
  401.     /**
  402.      *    Returns a human readable test message.
  403.      *    @param string $compare      Comparison value.
  404.      *    @return string              Description of success
  405.      *                                 or failure.
  406.      *    @access public
  407.      */
  408.     function testMessage($compare{
  409.         if ($this->test($compare)) {
  410.             $dumper &$this->_getDumper();
  411.             return "Text [" $this->_getSubstring(.
  412.                     "] not detected in [" .
  413.                     $dumper->describeValue($compare"]";
  414.         else {
  415.             return $this->_describeTextMatch($this->_getSubstring()$compare);
  416.         }
  417.     }
  418. }
  419.  
  420. /**
  421.  *    Test case for testing of web pages. Allows
  422.  *    fetching of pages, parsing of HTML and
  423.  *    submitting forms.
  424.  *    @package SimpleTest
  425.  *    @subpackage WebTester
  426.  */
  427. class WebTestCase extends SimpleTestCase {
  428.     var $_browser;
  429.     var $_ignore_errors = false;
  430.     
  431.     /**
  432.      *    Creates an empty test case. Should be subclassed
  433.      *    with test methods for a functional test case.
  434.      *    @param string $label     Name of test case. Will use
  435.      *                              the class name if none specified.
  436.      *    @access public
  437.      */
  438.     function WebTestCase($label false{
  439.         $this->SimpleTestCase($label);
  440.     }
  441.     
  442.     /**
  443.      *    Announces the start of the test.
  444.      *    @param string $method    Test method just started.
  445.      *    @access public
  446.      */
  447.     function before($method{
  448.         parent::before($method);
  449.         $this->setBrowser($this->createBrowser());
  450.     }
  451.  
  452.     /**
  453.      *    Announces the end of the test. Includes private clean up.
  454.      *    @param string $method    Test method just finished.
  455.      *    @access public
  456.      */
  457.     function after($method{
  458.         $this->unsetBrowser();
  459.         parent::after($method);
  460.     }
  461.     
  462.     /**
  463.      *    Gets a current browser reference for setting
  464.      *    special expectations or for detailed
  465.      *    examination of page fetches.
  466.      *    @return SimpleBrowser     Current test browser object.
  467.      *    @access public
  468.      */
  469.     function &getBrowser({
  470.         return $this->_browser;
  471.     }
  472.     
  473.     /**
  474.      *    Gets a current browser reference for setting
  475.      *    special expectations or for detailed
  476.      *    examination of page fetches.
  477.      *    @param SimpleBrowser $browser    New test browser object.
  478.      *    @access public
  479.      */
  480.     function setBrowser(&$browser{
  481.         return $this->_browser = &$browser;
  482.     }
  483.         
  484.     /**
  485.      *    Clears the current browser reference to help the
  486.      *    PHP garbage collector.
  487.      *    @access public
  488.      */
  489.     function unsetBrowser({
  490.         unset($this->_browser);
  491.     }
  492.     
  493.     /**
  494.      *    Creates a new default web browser object.
  495.      *    Will be cleared at the end of the test method.
  496.      *    @return TestBrowser           New browser.
  497.      *    @access public
  498.      */
  499.     function &createBrowser({
  500.         $browser &new SimpleBrowser();
  501.         return $browser;
  502.     }
  503.     
  504.     /**
  505.      *    Gets the last response error.
  506.      *    @return string    Last low level HTTP error.
  507.      *    @access public
  508.      */
  509.     function getTransportError({
  510.         return $this->_browser->getTransportError();
  511.     }
  512.         
  513.     /**
  514.      *    Accessor for the currently selected URL.
  515.      *    @return string        Current location or false if
  516.      *                           no page yet fetched.
  517.      *    @access public
  518.      */
  519.     function getUrl({
  520.         return $this->_browser->getUrl();
  521.     }
  522.     
  523.     /**
  524.      *    Dumps the current request for debugging.
  525.      *    @access public
  526.      */
  527.     function showRequest({
  528.         $this->dump($this->_browser->getRequest());
  529.     }
  530.     
  531.     /**
  532.      *    Dumps the current HTTP headers for debugging.
  533.      *    @access public
  534.      */
  535.     function showHeaders({
  536.         $this->dump($this->_browser->getHeaders());
  537.     }
  538.     
  539.     /**
  540.      *    Dumps the current HTML source for debugging.
  541.      *    @access public
  542.      */
  543.     function showSource({
  544.         $this->dump($this->_browser->getContent());
  545.     }
  546.     
  547.     /**
  548.      *    Dumps the visible text only for debugging.
  549.      *    @access public
  550.      */
  551.     function showText({
  552.         $this->dump(wordwrap($this->_browser->getContentAsText()80));
  553.     }
  554.     
  555.     /**
  556.      *    Simulates the closing and reopening of the browser.
  557.      *    Temporary cookies will be discarded and timed
  558.      *    cookies will be expired if later than the
  559.      *    specified time.
  560.      *    @param string/integer $date Time when session restarted.
  561.      *                                 If ommitted then all persistent
  562.      *                                 cookies are kept. Time is either
  563.      *                                 Cookie format string or timestamp.
  564.      *    @access public
  565.      */
  566.     function restart($date false{
  567.         if ($date === false{
  568.             $date time();
  569.         }
  570.         $this->_browser->restart($date);
  571.     }
  572.     
  573.     /**
  574.      *    Moves cookie expiry times back into the past.
  575.      *    Useful for testing timeouts and expiries.
  576.      *    @param integer $interval    Amount to age in seconds.
  577.      *    @access public
  578.      */
  579.     function ageCookies($interval{
  580.         $this->_browser->ageCookies($interval);
  581.     }
  582.     
  583.     /**
  584.      *    Disables frames support. Frames will not be fetched
  585.      *    and the frameset page will be used instead.
  586.      *    @access public
  587.      */
  588.     function ignoreFrames({
  589.         $this->_browser->ignoreFrames();
  590.     }
  591.     
  592.     /**
  593.      *    Switches off cookie sending and recieving.
  594.      *    @access public
  595.      */
  596.     function ignoreCookies({
  597.         $this->_browser->ignoreCookies();
  598.     }
  599.     
  600.     /**
  601.      *    Skips errors for the next request only. You might
  602.      *    want to confirm that a page is unreachable for
  603.      *    example.
  604.      *    @access public
  605.      */
  606.     function ignoreErrors({
  607.         $this->_ignore_errors = true;
  608.     }
  609.     
  610.     /**
  611.      *    Issues a fail if there is a transport error anywhere
  612.      *    in the current frameset. Only one such error is
  613.      *    reported.
  614.      *    @param string/boolean $result   HTML or failure.
  615.      *    @return string/boolean $result  Passes through result.
  616.      *    @access private
  617.      */
  618.     function _failOnError($result{
  619.         if ($this->_ignore_errors{
  620.             if ($error $this->_browser->getTransportError()) {
  621.                 $this->fail($error);
  622.             }
  623.         }
  624.         $this->_ignore_errors = false;
  625.         return $result;
  626.     }
  627.  
  628.     /**
  629.      *    Adds a header to every fetch.
  630.      *    @param string $header       Header line to add to every
  631.      *                                 request until cleared.
  632.      *    @access public
  633.      */
  634.     function addHeader($header{
  635.         $this->_browser->addHeader($header);
  636.     }
  637.     
  638.     /**
  639.      *    Sets the maximum number of redirects before
  640.      *    the web page is loaded regardless.
  641.      *    @param integer $max        Maximum hops.
  642.      *    @access public
  643.      */
  644.     function setMaximumRedirects($max{
  645.         if ($this->_browser{
  646.             trigger_error(
  647.                     'Can only set maximum redirects in a test method, setUp() or tearDown()');
  648.         }
  649.         $this->_browser->setMaximumRedirects($max);
  650.     }
  651.     
  652.     /**
  653.      *    Sets the socket timeout for opening a connection and
  654.      *    receiving at least one byte of information.
  655.      *    @param integer $timeout      Maximum time in seconds.
  656.      *    @access public
  657.      */
  658.     function setConnectionTimeout($timeout{
  659.         $this->_browser->setConnectionTimeout($timeout);
  660.     }
  661.     
  662.     /**
  663.      *    Sets proxy to use on all requests for when
  664.      *    testing from behind a firewall. Set URL
  665.      *    to false to disable.
  666.      *    @param string $proxy        Proxy URL.
  667.      *    @param string $username     Proxy username for authentication.
  668.      *    @param string $password     Proxy password for authentication.
  669.      *    @access public
  670.      */
  671.     function useProxy($proxy$username false$password false{
  672.         $this->_browser->useProxy($proxy$username$password);
  673.     }
  674.     
  675.     /**
  676.      *    Fetches a page into the page buffer. If
  677.      *    there is no base for the URL then the
  678.      *    current base URL is used. After the fetch
  679.      *    the base URL reflects the new location.
  680.      *    @param string $url          URL to fetch.
  681.      *    @param hash $parameters     Optional additional GET data.
  682.      *    @return boolean/string      Raw page on success.
  683.      *    @access public
  684.      */
  685.     function get($url$parameters false{
  686.         return $this->_failOnError($this->_browser->get($url$parameters));
  687.     }
  688.     
  689.     /**
  690.      *    Fetches a page by POST into the page buffer.
  691.      *    If there is no base for the URL then the
  692.      *    current base URL is used. After the fetch
  693.      *    the base URL reflects the new location.
  694.      *    @param string $url          URL to fetch.
  695.      *    @param hash $parameters     Optional additional GET data.
  696.      *    @return boolean/string      Raw page on success.
  697.      *    @access public
  698.      */
  699.     function post($url$parameters false{
  700.         return $this->_failOnError($this->_browser->post($url$parameters));
  701.     }
  702.     
  703.     /**
  704.      *    Does a HTTP HEAD fetch, fetching only the page
  705.      *    headers. The current base URL is unchanged by this.
  706.      *    @param string $url          URL to fetch.
  707.      *    @param hash $parameters     Optional additional GET data.
  708.      *    @return boolean             True on success.
  709.      *    @access public
  710.      */
  711.     function head($url$parameters false{
  712.         return $this->_failOnError($this->_browser->head($url$parameters));
  713.     }
  714.     
  715.     /**
  716.      *    Equivalent to hitting the retry button on the
  717.      *    browser. Will attempt to repeat the page fetch.
  718.      *    @return boolean     True if fetch succeeded.
  719.      *    @access public
  720.      */
  721.     function retry({
  722.         return $this->_failOnError($this->_browser->retry());
  723.     }
  724.     
  725.     /**
  726.      *    Equivalent to hitting the back button on the
  727.      *    browser.
  728.      *    @return boolean     True if history entry and
  729.      *                         fetch succeeded.
  730.      *    @access public
  731.      */
  732.     function back({
  733.         return $this->_failOnError($this->_browser->back());
  734.     }
  735.     
  736.     /**
  737.      *    Equivalent to hitting the forward button on the
  738.      *    browser.
  739.      *    @return boolean     True if history entry and
  740.      *                         fetch succeeded.
  741.      *    @access public
  742.      */
  743.     function forward({
  744.         return $this->_failOnError($this->_browser->forward());
  745.     }
  746.     
  747.     /**
  748.      *    Retries a request after setting the authentication
  749.      *    for the current realm.
  750.      *    @param string $username    Username for realm.
  751.      *    @param string $password    Password for realm.
  752.      *    @return boolean/string     HTML on successful fetch. Note
  753.      *                                that authentication may still have
  754.      *                                failed.
  755.      *    @access public
  756.      */
  757.     function authenticate($username$password{
  758.         return $this->_failOnError(
  759.                 $this->_browser->authenticate($username$password));
  760.     }
  761.     
  762.     /**
  763.      *    Gets the cookie value for the current browser context.
  764.      *    @param string $name          Name of cookie.
  765.      *    @return string               Value of cookie or false if unset.
  766.      *    @access public
  767.      */
  768.     function getCookie($name{
  769.         return $this->_browser->getCurrentCookieValue($name);
  770.     }
  771.     
  772.     /**
  773.      *    Sets a cookie in the current browser.
  774.      *    @param string $name          Name of cookie.
  775.      *    @param string $value         Cookie value.
  776.      *    @param string $host          Host upon which the cookie is valid.
  777.      *    @param string $path          Cookie path if not host wide.
  778.      *    @param string $expiry        Expiry date.
  779.      *    @access public
  780.      */
  781.     function setCookie($name$value$host false$path '/'$expiry false{
  782.         $this->_browser->setCookie($name$value$host$path$expiry);
  783.     }
  784.     
  785.     /**
  786.      *    Accessor for current frame focus. Will be
  787.      *    false if no frame has focus.
  788.      *    @return integer/string/boolean    Label if any, otherwise
  789.      *                                       the position in the frameset
  790.      *                                       or false if none.
  791.      *    @access public
  792.      */
  793.     function getFrameFocus({
  794.         return $this->_browser->getFrameFocus();
  795.     }
  796.     
  797.     /**
  798.      *    Sets the focus by index. The integer index starts from 1.
  799.      *    @param integer $choice    Chosen frame.
  800.      *    @return boolean           True if frame exists.
  801.      *    @access public
  802.      */
  803.     function setFrameFocusByIndex($choice{
  804.         return $this->_browser->setFrameFocusByIndex($choice);
  805.     }
  806.     
  807.     /**
  808.      *    Sets the focus by name.
  809.      *    @param string $name    Chosen frame.
  810.      *    @return boolean        True if frame exists.
  811.      *    @access public
  812.      */
  813.     function setFrameFocus($name{
  814.         return $this->_browser->setFrameFocus($name);
  815.     }
  816.     
  817.     /**
  818.      *    Clears the frame focus. All frames will be searched
  819.      *    for content.
  820.      *    @access public
  821.      */
  822.     function clearFrameFocus({
  823.         return $this->_browser->clearFrameFocus();
  824.     }
  825.     
  826.     /**
  827.      *    Clicks a visible text item. Will first try buttons,
  828.      *    then links and then images.
  829.      *    @param string $label        Visible text or alt text.
  830.      *    @return string/boolean      Raw page or false.
  831.      *    @access public
  832.      */
  833.     function click($label{
  834.         return $this->_failOnError($this->_browser->click($label));
  835.     }
  836.     
  837.     /**
  838.      *    Checks for a click target.
  839.      *    @param string $label        Visible text or alt text.
  840.      *    @return boolean             True if click target.
  841.      *    @access public
  842.      */    
  843.     function assertClickable($label$message '%s'{
  844.         return $this->assertTrue(
  845.                 $this->_browser->isClickable($label),
  846.                 sprintf($message"Click target [$label] should exist"));
  847.     }
  848.     
  849.     /**
  850.      *    Clicks the submit button by label. The owning
  851.      *    form will be submitted by this.
  852.      *    @param string $label    Button label. An unlabeled
  853.      *                             button can be triggered by 'Submit'.
  854.      *    @param hash $additional Additional form values.
  855.      *    @return boolean/string  Page on success, else false.
  856.      *    @access public
  857.      */
  858.     function clickSubmit($label 'Submit'$additional false{
  859.         return $this->_failOnError(
  860.                 $this->_browser->clickSubmit($label$additional));
  861.     }
  862.     
  863.     /**
  864.      *    Clicks the submit button by name attribute. The owning
  865.      *    form will be submitted by this.
  866.      *    @param string $name     Name attribute of button.
  867.      *    @param hash $additional Additional form values.
  868.      *    @return boolean/string  Page on success.
  869.      *    @access public
  870.      */
  871.     function clickSubmitByName($name$additional false{
  872.         return $this->_failOnError(
  873.                 $this->_browser->clickSubmitByName($name$additional));
  874.     }
  875.     
  876.     /**
  877.      *    Clicks the submit button by ID attribute. The owning
  878.      *    form will be submitted by this.
  879.      *    @param string $id       ID attribute of button.
  880.      *    @param hash $additional Additional form values.
  881.      *    @return boolean/string  Page on success.
  882.      *    @access public
  883.      */
  884.     function clickSubmitById($id$additional false{
  885.         return $this->_failOnError(
  886.                 $this->_browser->clickSubmitById($id$additional));
  887.     }
  888.     
  889.     /**
  890.      *    Checks for a valid button label.
  891.      *    @param string $label        Visible text.
  892.      *    @return boolean             True if click target.
  893.      *    @access public
  894.      */    
  895.     function assertSubmit($label$message '%s'{
  896.         return $this->assertTrue(
  897.                 $this->_browser->isSubmit($label),
  898.                 sprintf($message"Submit button [$label] should exist"));
  899.     }
  900.     
  901.     /**
  902.      *    Clicks the submit image by some kind of label. Usually
  903.      *    the alt tag or the nearest equivalent. The owning
  904.      *    form will be submitted by this. Clicking outside of
  905.      *    the boundary of the coordinates will result in
  906.      *    a failure.
  907.      *    @param string $label    Alt attribute of button.
  908.      *    @param integer $x       X-coordinate of imaginary click.
  909.      *    @param integer $y       Y-coordinate of imaginary click.
  910.      *    @param hash $additional Additional form values.
  911.      *    @return boolean/string  Page on success.
  912.      *    @access public
  913.      */
  914.     function clickImage($label$x 1$y 1$additional false{
  915.         return $this->_failOnError(
  916.                 $this->_browser->clickImage($label$x$y$additional));
  917.     }
  918.     
  919.     /**
  920.      *    Clicks the submit image by the name. Usually
  921.      *    the alt tag or the nearest equivalent. The owning
  922.      *    form will be submitted by this. Clicking outside of
  923.      *    the boundary of the coordinates will result in
  924.      *    a failure.
  925.      *    @param string $name     Name attribute of button.
  926.      *    @param integer $x       X-coordinate of imaginary click.
  927.      *    @param integer $y       Y-coordinate of imaginary click.
  928.      *    @param hash $additional Additional form values.
  929.      *    @return boolean/string  Page on success.
  930.      *    @access public
  931.      */
  932.     function clickImageByName($name$x 1$y 1$additional false{
  933.         return $this->_failOnError(
  934.                 $this->_browser->clickImageByName($name$x$y$additional));
  935.     }
  936.     
  937.     /**
  938.      *    Clicks the submit image by ID attribute. The owning
  939.      *    form will be submitted by this. Clicking outside of
  940.      *    the boundary of the coordinates will result in
  941.      *    a failure.
  942.      *    @param integer/string $id   ID attribute of button.
  943.      *    @param integer $x           X-coordinate of imaginary click.
  944.      *    @param integer $y           Y-coordinate of imaginary click.
  945.      *    @param hash $additional     Additional form values.
  946.      *    @return boolean/string      Page on success.
  947.      *    @access public
  948.      */
  949.     function clickImageById($id$x 1$y 1$additional false{
  950.         return $this->_failOnError(
  951.                 $this->_browser->clickImageById($id$x$y$additional));
  952.     }
  953.     
  954.     /**
  955.      *    Checks for a valid image with atht alt text or title.
  956.      *    @param string $label        Visible text.
  957.      *    @return boolean             True if click target.
  958.      *    @access public
  959.      */    
  960.     function assertImage($label$message '%s'{
  961.         return $this->assertTrue(
  962.                 $this->_browser->isImage($label),
  963.                 sprintf($message"Image with text [$label] should exist"));
  964.     }
  965.     
  966.     /**
  967.      *    Submits a form by the ID.
  968.      *    @param string $id       Form ID. No button information
  969.      *                             is submitted this way.
  970.      *    @return boolean/string  Page on success.
  971.      *    @access public
  972.      */
  973.     function submitFormById($id{
  974.         return $this->_failOnError($this->_browser->submitFormById($id));
  975.     }
  976.     
  977.     /**
  978.      *    Follows a link by name. Will click the first link
  979.      *    found with this link text by default, or a later
  980.      *    one if an index is given. Match is case insensitive
  981.      *    with normalised space.
  982.      *    @param string $label     Text between the anchor tags.
  983.      *    @param integer $index    Link position counting from zero.
  984.      *    @return boolean/string   Page on success.
  985.      *    @access public
  986.      */
  987.     function clickLink($label$index 0{
  988.         return $this->_failOnError($this->_browser->clickLink($label$index));
  989.     }
  990.     
  991.     /**
  992.      *    Follows a link by id attribute.
  993.      *    @param string $id        ID attribute value.
  994.      *    @return boolean/string   Page on success.
  995.      *    @access public
  996.      */
  997.     function clickLinkById($id{
  998.         return $this->_failOnError($this->_browser->clickLinkById($id));
  999.     }
  1000.     
  1001.     /**
  1002.      *    Tests for the presence of a link label. Match is
  1003.      *    case insensitive with normalised space.
  1004.      *    @param string $label     Text between the anchor tags.
  1005.      *    @param mixed $expected   Expected URL or expectation object.
  1006.      *    @param string $message   Message to display. Default
  1007.      *                              can be embedded with %s.
  1008.      *    @return boolean          True if link present.
  1009.      *    @access public
  1010.      */
  1011.     function assertLink($label$expected true$message '%s'{
  1012.         $url $this->_browser->getLink($label);
  1013.         if ($expected === true || ($expected !== true && $url === false)) {
  1014.             return $this->assertTrue($url !== falsesprintf($message"Link [$label] should exist"));
  1015.         }
  1016.         if (SimpleExpectation::isExpectation($expected)) {
  1017.             $expected new IdenticalExpectation($expected);
  1018.         }
  1019.         return $this->assert($expected$url->asString()sprintf($message"Link [$label] should match"));
  1020.     }
  1021.  
  1022.     /**
  1023.      *    Tests for the non-presence of a link label. Match is
  1024.      *    case insensitive with normalised space.
  1025.      *    @param string/integer $label    Text between the anchor tags
  1026.      *                                     or ID attribute.
  1027.      *    @param string $message          Message to display. Default
  1028.      *                                     can be embedded with %s.
  1029.      *    @return boolean                 True if link missing.
  1030.      *    @access public
  1031.      */
  1032.     function assertNoLink($label$message '%s'{
  1033.         return $this->assertTrue(
  1034.                 $this->_browser->getLink($label=== false,
  1035.                 sprintf($message"Link [$label] should not exist"));
  1036.     }
  1037.     
  1038.     /**
  1039.      *    Tests for the presence of a link id attribute.
  1040.      *    @param string $id        Id attribute value.
  1041.      *    @param mixed $expected   Expected URL or expectation object.
  1042.      *    @param string $message   Message to display. Default
  1043.      *                              can be embedded with %s.
  1044.      *    @return boolean          True if link present.
  1045.      *    @access public
  1046.      */
  1047.     function assertLinkById($id$expected true$message '%s'{
  1048.         $url $this->_browser->getLinkById($id);
  1049.         if ($expected === true{
  1050.             return $this->assertTrue($url !== falsesprintf($message"Link ID [$id] should exist"));
  1051.         }
  1052.         if (SimpleExpectation::isExpectation($expected)) {
  1053.             $expected new IdenticalExpectation($expected);
  1054.         }
  1055.         return $this->assert($expected$url->asString()sprintf($message"Link ID [$id] should match"));
  1056.     }
  1057.  
  1058.     /**
  1059.      *    Tests for the non-presence of a link label. Match is
  1060.      *    case insensitive with normalised space.
  1061.      *    @param string $id        Id attribute value.
  1062.      *    @param string $message   Message to display. Default
  1063.      *                              can be embedded with %s.
  1064.      *    @return boolean          True if link missing.
  1065.      *    @access public
  1066.      */
  1067.     function assertNoLinkById($id$message '%s'{
  1068.         return $this->assertTrue(
  1069.                 $this->_browser->getLinkById($id=== false,
  1070.                 sprintf($message"Link ID [$id] should not exist"));
  1071.     }
  1072.     
  1073.     /**
  1074.      *    Sets all form fields with that label, or name if there
  1075.      *    is no label attached.
  1076.      *    @param string $name    Name of field in forms.
  1077.      *    @param string $value   New value of field.
  1078.      *    @return boolean        True if field exists, otherwise false.
  1079.      *    @access public
  1080.      */
  1081.     function setField($label$value$position=false{
  1082.         return $this->_browser->setField($label$value$position);
  1083.     }
  1084.     
  1085.     /**
  1086.      *    Sets all form fields with that name.
  1087.      *    @param string $name    Name of field in forms.
  1088.      *    @param string $value   New value of field.
  1089.      *    @return boolean        True if field exists, otherwise false.
  1090.      *    @access public
  1091.      */
  1092.     function setFieldByName($name$value$position=false{
  1093.         return $this->_browser->setFieldByName($name$value$position);
  1094.     }
  1095.         
  1096.     /**
  1097.      *    Sets all form fields with that id.
  1098.      *    @param string/integer $id   Id of field in forms.
  1099.      *    @param string $value        New value of field.
  1100.      *    @return boolean             True if field exists, otherwise false.
  1101.      *    @access public
  1102.      */
  1103.     function setFieldById($id$value{
  1104.         return $this->_browser->setFieldById($id$value);
  1105.     }
  1106.     
  1107.     /**
  1108.      *    Confirms that the form element is currently set
  1109.      *    to the expected value. A missing form will always
  1110.      *    fail. If no value is given then only the existence
  1111.      *    of the field is checked.
  1112.      *    @param string $name       Name of field in forms.
  1113.      *    @param mixed $expected    Expected string/array value or
  1114.      *                               false for unset fields.
  1115.      *    @param string $message    Message to display. Default
  1116.      *                               can be embedded with %s.
  1117.      *    @return boolean           True if pass.
  1118.      *    @access public
  1119.      */
  1120.     function assertField($label$expected true$message '%s'{
  1121.         $value $this->_browser->getField($label);
  1122.         return $this->_assertFieldValue($label$value$expected$message);
  1123.     }
  1124.     
  1125.     /**
  1126.      *    Confirms that the form element is currently set
  1127.      *    to the expected value. A missing form element will always
  1128.      *    fail. If no value is given then only the existence
  1129.      *    of the field is checked.
  1130.      *    @param string $name       Name of field in forms.
  1131.      *    @param mixed $expected    Expected string/array value or
  1132.      *                               false for unset fields.
  1133.      *    @param string $message    Message to display. Default
  1134.      *                               can be embedded with %s.
  1135.      *    @return boolean           True if pass.
  1136.      *    @access public
  1137.      */
  1138.     function assertFieldByName($name$expected true$message '%s'{
  1139.         $value $this->_browser->getFieldByName($name);
  1140.         return $this->_assertFieldValue($name$value$expected$message);
  1141.     }
  1142.         
  1143.     /**
  1144.      *    Confirms that the form element is currently set
  1145.      *    to the expected value. A missing form will always
  1146.      *    fail. If no ID is given then only the existence
  1147.      *    of the field is checked.
  1148.      *    @param string/integer $id  Name of field in forms.
  1149.      *    @param mixed $expected     Expected string/array value or
  1150.      *                                false for unset fields.
  1151.      *    @param string $message     Message to display. Default
  1152.      *                                can be embedded with %s.
  1153.      *    @return boolean            True if pass.
  1154.      *    @access public
  1155.      */
  1156.     function assertFieldById($id$expected true$message '%s'{
  1157.         $value $this->_browser->getFieldById($id);
  1158.         return $this->_assertFieldValue($id$value$expected$message);
  1159.     }
  1160.     
  1161.     /**
  1162.      *    Tests the field value against the expectation.
  1163.      *    @param string $identifier      Name, ID or label.
  1164.      *    @param mixed $value            Current field value.
  1165.      *    @param mixed $expected         Expected value to match.
  1166.      *    @param string $message         Failure message.
  1167.      *    @return boolean                True if pass
  1168.      *    @access protected
  1169.      */
  1170.     function _assertFieldValue($identifier$value$expected$message{
  1171.         if ($expected === true{
  1172.             return $this->assertTrue(
  1173.                     isset($value),
  1174.                     sprintf($message"Field [$identifier] should exist"));
  1175.         }
  1176.         if (SimpleExpectation::isExpectation($expected)) {
  1177.             $identifier str_replace('%''%%'$identifier);
  1178.             $expected new FieldExpectation(
  1179.                     $expected,
  1180.                     "Field [$identifier] should match with [%s]");
  1181.         }
  1182.         return $this->assert($expected$value$message);
  1183.     }
  1184.     
  1185.     /**
  1186.      *    Checks the response code against a list
  1187.      *    of possible values.
  1188.      *    @param array $responses    Possible responses for a pass.
  1189.      *    @param string $message     Message to display. Default
  1190.      *                                can be embedded with %s.
  1191.      *    @return boolean            True if pass.
  1192.      *    @access public
  1193.      */
  1194.     function assertResponse($responses$message '%s'{
  1195.         $responses (is_array($responses$responses array($responses));
  1196.         $code $this->_browser->getResponseCode();
  1197.         $message sprintf($message"Expecting response in [" .
  1198.                 implode(", "$responses"] got [$code]");
  1199.         return $this->assertTrue(in_array($code$responses)$message);
  1200.     }
  1201.     
  1202.     /**
  1203.      *    Checks the mime type against a list
  1204.      *    of possible values.
  1205.      *    @param array $types      Possible mime types for a pass.
  1206.      *    @param string $message   Message to display.
  1207.      *    @return boolean          True if pass.
  1208.      *    @access public
  1209.      */
  1210.     function assertMime($types$message '%s'{
  1211.         $types (is_array($types$types array($types));
  1212.         $type $this->_browser->getMimeType();
  1213.         $message sprintf($message"Expecting mime type in [" .
  1214.                 implode(", "$types"] got [$type]");
  1215.         return $this->assertTrue(in_array($type$types)$message);
  1216.     }
  1217.     
  1218.     /**
  1219.      *    Attempt to match the authentication type within
  1220.      *    the security realm we are currently matching.
  1221.      *    @param string $authentication   Usually basic.
  1222.      *    @param string $message          Message to display.
  1223.      *    @return boolean                 True if pass.
  1224.      *    @access public
  1225.      */
  1226.     function assertAuthentication($authentication false$message '%s'{
  1227.         if ($authentication{
  1228.             $message sprintf($message"Expected any authentication type, got [" .
  1229.                     $this->_browser->getAuthentication("]");
  1230.             return $this->assertTrue(
  1231.                     $this->_browser->getAuthentication(),
  1232.                     $message);
  1233.         else {
  1234.             $message sprintf($message"Expected authentication [$authentication] got [.
  1235.                     $this->_browser->getAuthentication("]");
  1236.             return $this->assertTrue(
  1237.                     strtolower($this->_browser->getAuthentication()) == strtolower($authentication),
  1238.                     $message);
  1239.         }
  1240.     }
  1241.     
  1242.     /**
  1243.      *    Checks that no authentication is necessary to view
  1244.      *    the desired page.
  1245.      *    @param string $message     Message to display.
  1246.      *    @return boolean            True if pass.
  1247.      *    @access public
  1248.      */
  1249.     function assertNoAuthentication($message '%s'{
  1250.         $message sprintf($message"Expected no authentication type, got [" .
  1251.                 $this->_browser->getAuthentication("]");
  1252.         return $this->assertFalse($this->_browser->getAuthentication()$message);
  1253.     }
  1254.     
  1255.     /**
  1256.      *    Attempts to match the current security realm.
  1257.      *    @param string $realm     Name of security realm.
  1258.      *    @param string $message   Message to display.
  1259.      *    @return boolean          True if pass.
  1260.      *    @access public
  1261.      */
  1262.     function assertRealm($realm$message '%s'{
  1263.         if (SimpleExpectation::isExpectation($realm)) {
  1264.             $realm new EqualExpectation($realm);
  1265.         }
  1266.         return $this->assert(
  1267.                 $realm,
  1268.                 $this->_browser->getRealm(),
  1269.                 "Expected realm -> $message");
  1270.     }
  1271.     
  1272.     /**
  1273.      *    Checks each header line for the required value. If no
  1274.      *    value is given then only an existence check is made.
  1275.      *    @param string $header    Case insensitive header name.
  1276.      *    @param mixed $value      Case sensitive trimmed string to
  1277.      *                              match against. An expectation object
  1278.      *                              can be used for pattern matching.
  1279.      *    @return boolean          True if pass.
  1280.      *    @access public
  1281.      */
  1282.     function assertHeader($header$value false$message '%s'{
  1283.         return $this->assert(
  1284.                 new HttpHeaderExpectation($header$value),
  1285.                 $this->_browser->getHeaders(),
  1286.                 $message);
  1287.     }
  1288.         
  1289.     /**
  1290.      *    @deprecated
  1291.      */
  1292.     function assertHeaderPattern($header$pattern$message '%s'{
  1293.         return $this->assert(
  1294.                 new HttpHeaderExpectation($headernew PatternExpectation($pattern)),
  1295.                 $this->_browser->getHeaders(),
  1296.                 $message);
  1297.     }
  1298.  
  1299.     /**
  1300.      *    Confirms that the header type has not been received.
  1301.      *    Only the landing page is checked. If you want to check
  1302.      *    redirect pages, then you should limit redirects so
  1303.      *    as to capture the page you want.
  1304.      *    @param string $header    Case insensitive header name.
  1305.      *    @return boolean          True if pass.
  1306.      *    @access public
  1307.      */
  1308.     function assertNoHeader($header$message '%s'{
  1309.         return $this->assert(
  1310.                 new NoHttpHeaderExpectation($header),
  1311.                 $this->_browser->getHeaders(),
  1312.                 $message);
  1313.     }
  1314.         
  1315.     /**
  1316.      *    @deprecated
  1317.      */
  1318.     function assertNoUnwantedHeader($header$message '%s'{
  1319.         return $this->assertNoHeader($header$message);
  1320.     }
  1321.     
  1322.     /**
  1323.      *    Tests the text between the title tags.
  1324.      *    @param string/SimpleExpectation $title    Expected title.
  1325.      *    @param string $message                    Message to display.
  1326.      *    @return boolean                           True if pass.
  1327.      *    @access public
  1328.      */
  1329.     function assertTitle($title false$message '%s'{
  1330.         if (SimpleExpectation::isExpectation($title)) {
  1331.             $title new EqualExpectation($title);
  1332.         }
  1333.         return $this->assert($title$this->_browser->getTitle()$message);
  1334.     }
  1335.     
  1336.     /**
  1337.      *    Will trigger a pass if the text is found in the plain
  1338.      *    text form of the page.
  1339.      *    @param string $text       Text to look for.
  1340.      *    @param string $message    Message to display.
  1341.      *    @return boolean           True if pass.
  1342.      *    @access public
  1343.      */
  1344.     function assertText($text$message '%s'{
  1345.         return $this->assert(
  1346.                 new TextExpectation($text),
  1347.                 $this->_browser->getContentAsText(),
  1348.                 $message);
  1349.     }
  1350.     
  1351.     /**
  1352.      *    @deprecated
  1353.      */
  1354.     function assertWantedText($text$message '%s'{
  1355.         return $this->assertText($text$message);
  1356.     }
  1357.     
  1358.     /**
  1359.      *    Will trigger a pass if the text is not found in the plain
  1360.      *    text form of the page.
  1361.      *    @param string $text       Text to look for.
  1362.      *    @param string $message    Message to display.
  1363.      *    @return boolean           True if pass.
  1364.      *    @access public
  1365.      */
  1366.     function assertNoText($text$message '%s'{
  1367.         return $this->assert(
  1368.                 new NoTextExpectation($text),
  1369.                 $this->_browser->getContentAsText(),
  1370.                 $message);
  1371.     }
  1372.     
  1373.     /**
  1374.      *    @deprecated
  1375.      */
  1376.     function assertNoUnwantedText($text$message '%s'{
  1377.         return $this->assertNoText($text$message);
  1378.     }
  1379.     
  1380.     /**
  1381.      *    Will trigger a pass if the Perl regex pattern
  1382.      *    is found in the raw content.
  1383.      *    @param string $pattern    Perl regex to look for including
  1384.      *                               the regex delimiters.
  1385.      *    @param string $message    Message to display.
  1386.      *    @return boolean           True if pass.
  1387.      *    @access public
  1388.      */
  1389.     function assertPattern($pattern$message '%s'{
  1390.         return $this->assert(
  1391.                 new PatternExpectation($pattern),
  1392.                 $this->_browser->getContent(),
  1393.                 $message);
  1394.     }
  1395.     
  1396.     /**
  1397.      *    @deprecated
  1398.      */
  1399.     function assertWantedPattern($pattern$message '%s'{
  1400.         return $this->assertPattern($pattern$message);
  1401.     }
  1402.     
  1403.     /**
  1404.      *    Will trigger a pass if the perl regex pattern
  1405.      *    is not present in raw content.
  1406.      *    @param string $pattern    Perl regex to look for including
  1407.      *                               the regex delimiters.
  1408.      *    @param string $message    Message to display.
  1409.      *    @return boolean           True if pass.
  1410.      *    @access public
  1411.      */
  1412.     function assertNoPattern($pattern$message '%s'{
  1413.         return $this->assert(
  1414.                 new NoPatternExpectation($pattern),
  1415.                 $this->_browser->getContent(),
  1416.                 $message);
  1417.     }
  1418.     
  1419.     /**
  1420.      *    @deprecated
  1421.      */
  1422.     function assertNoUnwantedPattern($pattern$message '%s'{
  1423.         return $this->assertNoPattern($pattern$message);
  1424.     }
  1425.     
  1426.     /**
  1427.      *    Checks that a cookie is set for the current page
  1428.      *    and optionally checks the value.
  1429.      *    @param string $name        Name of cookie to test.
  1430.      *    @param string $expected    Expected value as a string or
  1431.      *                                false if any value will do.
  1432.      *    @param string $message     Message to display.
  1433.      *    @return boolean            True if pass.
  1434.      *    @access public
  1435.      */
  1436.     function assertCookie($name$expected false$message '%s'{
  1437.         $value $this->getCookie($name);
  1438.         if ($expected{
  1439.             return $this->assertTrue(
  1440.                     $value,
  1441.                     sprintf($message"Expecting cookie [$name]"));
  1442.         }
  1443.         if (SimpleExpectation::isExpectation($expected)) {
  1444.             $expected new EqualExpectation($expected);
  1445.         }
  1446.         return $this->assert($expected$value"Expecting cookie [$name] -> $message");
  1447.     }
  1448.     
  1449.     /**
  1450.      *    Checks that no cookie is present or that it has
  1451.      *    been successfully cleared.
  1452.      *    @param string $name        Name of cookie to test.
  1453.      *    @param string $message     Message to display.
  1454.      *    @return boolean            True if pass.
  1455.      *    @access public
  1456.      */
  1457.     function assertNoCookie($name$message '%s'{
  1458.         return $this->assertTrue(
  1459.                 $this->getCookie($name=== false,
  1460.                 sprintf($message"Not expecting cookie [$name]"));
  1461.     }
  1462.  
  1463.     /**
  1464.      *    Called from within the test methods to register
  1465.      *    passes and failures.
  1466.      *    @param boolean $result    Pass on true.
  1467.      *    @param string $message    Message to display describing
  1468.      *                               the test state.
  1469.      *    @return boolean           True on pass
  1470.      *    @access public
  1471.      */
  1472.     function assertTrue($result$message false{
  1473.         return $this->assert(new TrueExpectation()$result$message);
  1474.     }
  1475.  
  1476.     /**
  1477.      *    Will be true on false and vice versa. False
  1478.      *    is the PHP definition of false, so that null,
  1479.      *    empty strings, zero and an empty array all count
  1480.      *    as false.
  1481.      *    @param boolean $result    Pass on false.
  1482.      *    @param string $message    Message to display.
  1483.      *    @return boolean           True on pass
  1484.      *    @access public
  1485.      */
  1486.     function assertFalse($result$message '%s'{
  1487.         return $this->assert(new FalseExpectation()$result$message);
  1488.     }
  1489.     
  1490.     /**
  1491.      *    Will trigger a pass if the two parameters have
  1492.      *    the same value only. Otherwise a fail. This
  1493.      *    is for testing hand extracted text, etc.
  1494.      *    @param mixed $first          Value to compare.
  1495.      *    @param mixed $second         Value to compare.
  1496.      *    @param string $message       Message to display.
  1497.      *    @return boolean              True on pass
  1498.      *    @access public
  1499.      */
  1500.     function assertEqual($first$second$message '%s'{
  1501.         return $this->assert(
  1502.                 new EqualExpectation($first),
  1503.                 $second,
  1504.                 $message);
  1505.     }
  1506.     
  1507.     /**
  1508.      *    Will trigger a pass if the two parameters have
  1509.      *    a different value. Otherwise a fail. This
  1510.      *    is for testing hand extracted text, etc.
  1511.      *    @param mixed $first           Value to compare.
  1512.      *    @param mixed $second          Value to compare.
  1513.      *    @param string $message        Message to display.
  1514.      *    @return boolean               True on pass
  1515.      *    @access public
  1516.      */
  1517.     function assertNotEqual($first$second$message '%s'{
  1518.         return $this->assert(
  1519.                 new NotEqualExpectation($first),
  1520.                 $second,
  1521.                 $message);
  1522.     }
  1523.  
  1524.     /**
  1525.      *    Uses a stack trace to find the line of an assertion.
  1526.      *    @return string           Line number of first assert*
  1527.      *                              method embedded in format string.
  1528.      *    @access public
  1529.      */
  1530.     function getAssertionLine({
  1531.         $trace new SimpleStackTrace(array('assert''click''pass''fail'));
  1532.         return $trace->traceMethod();
  1533.     }
  1534. }
  1535. ?>

Documentation generated on Sun, 04 May 2008 09:22:28 -0500 by phpDocumentor 1.3.0