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

Documentation generated on Thu, 01 Oct 2009 20:56:22 -0500 by phpDocumentor 1.4.2