3 * Base include file for SimpleTest.
5 * @subpackage WebTester
6 * @version $Id: web_tester.php,v 1.77 2004/08/04 23:48:51 lastcraft Exp $
10 * include other SimpleTest class files
12 require_once(dirname(__FILE__
) . '/simple_test.php');
13 require_once(dirname(__FILE__
) . '/browser.php');
14 require_once(dirname(__FILE__
) . '/page.php');
15 require_once(dirname(__FILE__
) . '/expectation.php');
19 * Test for an HTML widget value match.
21 * @subpackage WebTester
23 class FieldExpectation
extends SimpleExpectation
{
27 * Sets the field value to compare against.
28 * @param mixed $value Test value to match.
31 function FieldExpectation($value) {
32 $this->SimpleExpectation();
33 if (is_array($value)) {
36 $this->_value
= $value;
40 * Tests the expectation. True if it matches
41 * a string value or an array value in any order.
42 * @param mixed $compare Comparison value. False for
44 * @return boolean True if correct.
47 function test($compare) {
48 if ($this->_value
=== false
) {
49 return ($compare === false
);
51 if ($this->_isSingle($this->_value
)) {
52 return $this->_testSingle($compare);
54 if (is_array($this->_value
)) {
55 return $this->_testMultiple($compare);
61 * Tests for valid field comparisons.
62 * @param mixed $value Value to type check.
63 * @return boolean True if integer, string or float.
66 function _isSingle($value) {
67 return is_string($value) ||
is_integer($value) ||
is_float($value);
71 * String comparison for simple field.
72 * @param mixed $compare String to test against.
73 * @returns boolean True if matching.
76 function _testSingle($compare) {
77 if (is_array($compare) && count($compare) == 1) {
78 $compare = $compare[0];
80 if (! $this->_isSingle($compare)) {
83 return ($this->_value
== $compare);
87 * List comparison for multivalue field.
88 * @param mixed $compare List in any order to test against.
89 * @returns boolean True if matching.
92 function _testMultiple($compare) {
93 if (is_string($compare)) {
94 $compare = array($compare);
96 if (! is_array($compare)) {
100 return ($this->_value
=== $compare);
104 * Returns a human readable test message.
105 * @param mixed $compare Comparison value.
106 * @return string Description of success
110 function testMessage($compare) {
111 $dumper = &$this->_getDumper();
112 if (is_array($compare)) {
115 if ($this->test($compare)) {
116 return "Field expectation [" . $dumper->describeValue($this->_value
) . "]";
118 return "Field expectation [" . $dumper->describeValue($this->_value
) .
120 $this->_dumper
->describeValue($compare) . "] " .
121 $this->_dumper
->describeDifference($this->_value
, $compare);
127 * Test for a specific HTTP header within a header block.
128 * @package SimpleTest
129 * @subpackage WebTester
131 class HttpHeaderExpectation
extends SimpleExpectation
{
132 var $_expected_header;
133 var $_expected_value;
136 * Sets the field and value to compare against.
137 * @param string $header Case insenstive trimmed header name.
138 * @param string $value Optional value to compare. If not
139 * given then any value will match.
141 function HttpHeaderExpectation($header, $value = false
) {
142 $this->_expected_header
= $this->_normaliseHeader($header);
143 $this->_expected_value
= $value;
147 * Accessor for subclases.
148 * @return mixed Expectation set in constructor.
151 function _getExpectation() {
152 return $this->_expected_value
;
156 * Removes whitespace at ends and case variations.
157 * @param string $header Name of header.
158 * @param string Trimmed and lowecased header
162 function _normaliseHeader($header) {
163 return strtolower(trim($header));
167 * Tests the expectation. True if it matches
168 * a string value or an array value in any order.
169 * @param mixed $compare Raw header block to search.
170 * @return boolean True if header present.
173 function test($compare) {
174 return is_string($this->_findHeader($compare));
178 * Searches the incoming result. Will extract the matching
180 * @param mixed $compare Raw header block to search.
181 * @return string Matching header line.
184 function _findHeader($compare) {
185 $lines = explode("\r\n", $compare);
186 foreach ($lines as $line) {
187 if ($this->_testHeaderLine($line)) {
195 * Compares a single header line against the expectation.
196 * @param string $line A single line to compare.
197 * @return boolean True if matched.
200 function _testHeaderLine($line) {
201 if (count($parsed = explode(':', $line)) < 2) {
204 list($header, $value) = $parsed;
205 if ($this->_normaliseHeader($header) != $this->_expected_header
) {
208 return $this->_testHeaderValue($value, $this->_expected_value
);
212 * Tests the value part of the header.
213 * @param string $value Value to test.
214 * @param mixed $expected Value to test against.
215 * @return boolean True if matched.
218 function _testHeaderValue($value, $expected) {
219 if ($expected === false
) {
222 return (trim($value) == trim($expected));
226 * Returns a human readable test message.
227 * @param mixed $compare Raw header block to search.
228 * @return string Description of success
232 function testMessage($compare) {
233 $expectation = $this->_expected_header
;
234 if ($this->_expected_value
) {
235 $expectation .= ': ' . $this->_expected_header
;
237 if (is_string($line = $this->_findHeader($compare))) {
238 return "Searching for header [$expectation] found [$line]";
240 return "Failed to find header [$expectation]";
246 * Test for a specific HTTP header within a header block that
247 * should not be found.
248 * @package SimpleTest
249 * @subpackage WebTester
251 class HttpUnwantedHeaderExpectation
extends HttpHeaderExpectation
{
252 var $_expected_header;
253 var $_expected_value;
256 * Sets the field and value to compare against.
257 * @param string $unwanted Case insenstive trimmed header name.
259 function HttpUnwantedHeaderExpectation($unwanted) {
260 $this->HttpHeaderExpectation($unwanted);
264 * Tests that the unwanted header is not found.
265 * @param mixed $compare Raw header block to search.
266 * @return boolean True if header present.
269 function test($compare) {
270 return ($this->_findHeader($compare) === false
);
274 * Returns a human readable test message.
275 * @param mixed $compare Raw header block to search.
276 * @return string Description of success
280 function testMessage($compare) {
281 $expectation = $this->_getExpectation();
282 if (is_string($line = $this->_findHeader($compare))) {
283 return "Found unwanted header [$expectation] with [$line]";
285 return "Did not find unwanted header [$expectation]";
291 * Test for a specific HTTP header within a header block.
292 * @package SimpleTest
293 * @subpackage WebTester
295 class HttpHeaderPatternExpectation
extends HttpHeaderExpectation
{
298 * Sets the field and value to compare against.
299 * @param string $header Case insenstive header name.
300 * @param string $pattern Pattern to compare value against.
303 function HttpHeaderPatternExpectation($header, $pattern) {
304 $this->HttpHeaderExpectation($header, $pattern);
308 * Tests the value part of the header.
309 * @param string $value Value to test.
310 * @param mixed $pattern Pattern to test against.
311 * @return boolean True if matched.
314 function _testHeaderValue($value, $expected) {
315 return (boolean
)preg_match($expected, trim($value));
320 * Test case for testing of web pages. Allows
321 * fetching of pages, parsing of HTML and
323 * @package SimpleTest
324 * @subpackage WebTester
326 class WebTestCase
extends SimpleTestCase
{
330 * Creates an empty test case. Should be subclassed
331 * with test methods for a functional test case.
332 * @param string $label Name of test case. Will use
333 * the class name if none specified.
336 function WebTestCase($label = false
) {
337 $this->SimpleTestCase($label);
341 * Gets the last response error.
342 * @return string Last low level HTTP error.
345 function getTransportError() {
346 return $this->_browser
->getTransportError();
350 * Accessor for the currently selected URL.
351 * @return string Current location or false if
352 * no page yet fetched.
356 $this->_browser
->getUrl();
360 * Dumps the current request for debugging.
363 function showRequest() {
364 $this->dump($this->_browser
->getRequest());
368 * Dumps the current HTTP headers for debugging.
371 function showHeaders() {
372 $this->dump($this->_browser
->getHeaders());
376 * Dumps the current HTML source for debugging.
379 function showSource() {
380 $this->dump($this->_browser
->getContent());
384 * Simulates the closing and reopening of the browser.
385 * Temporary cookies will be discarded and timed
386 * cookies will be expired if later than the
388 * @param string/integer $date Time when session restarted.
389 * If ommitted then all persistent
390 * cookies are kept. Time is either
391 * Cookie format string or timestamp.
394 function restartSession($date = false
) {
395 if ($date === false
) {
398 $this->_browser
->restartSession($date);
402 * Moves cookie expiry times back into the past.
403 * Useful for testing timeouts and expiries.
404 * @param integer $interval Amount to age in seconds.
407 function ageCookies($interval) {
408 $this->_browser
->ageCookies($interval);
412 * Gets a current browser reference for setting
413 * special expectations or for detailed
414 * examination of page fetches.
415 * @param SimpleBrowser $browser Test browser object.
418 function &getBrowser() {
419 return $this->_browser
;
423 * Creates a new default web browser object.
424 * Will be cleared at the end of the test method.
425 * @return TestBrowser New browser.
428 function &createBrowser() {
429 return new SimpleBrowser();
433 * Sets up a browser for the start of each
438 $this->_browser
= &$this->createBrowser();
443 * Disables frames support. Frames will not be fetched
444 * and the frameset page will be used instead.
447 function ignoreFrames() {
448 $this->_browser
->ignoreFrames();
452 * Sets a cookie in the current browser.
453 * @param string $name Name of cookie.
454 * @param string $value Cookie value.
455 * @param string $host Host upon which the cookie is valid.
456 * @param string $path Cookie path if not host wide.
457 * @param string $expiry Expiry date.
460 function setCookie($name, $value, $host = false
, $path = "/", $expiry = false
) {
461 $this->_browser
->setCookie($name, $value, $host, $path, $expiry);
465 * Adds a header to every fetch.
466 * @param string $header Header line to add to every
467 * request until cleared.
470 function addHeader($header) {
471 $this->_browser
->addHeader($header);
475 * Sets the maximum number of redirects before
476 * the web page is loaded regardless.
477 * @param integer $max Maximum hops.
480 function setMaximumRedirects($max) {
481 if (! $this->_browser
) {
483 'Can only set maximum redirects in a test method, setUp() or tearDown()');
485 $this->_browser
->setMaximumRedirects($max);
489 * Sets the socket timeout for opening a connection and
490 * receiving at least one byte of information.
491 * @param integer $timeout Maximum time in seconds.
494 function setConnectionTimeout($timeout) {
495 $this->_browser
->setConnectionTimeout($timeout);
499 * Sets proxy to use on all requests for when
500 * testing from behind a firewall. Set URL
501 * to false to disable.
502 * @param string $proxy Proxy URL.
503 * @param string $username Proxy username for authentication.
504 * @param string $password Proxy password for authentication.
507 function useProxy($proxy, $username = false
, $password = false
) {
508 $this->_browser
->useProxy($proxy, $username, $password);
512 * Fetches a page into the page buffer. If
513 * there is no base for the URL then the
514 * current base URL is used. After the fetch
515 * the base URL reflects the new location.
516 * @param string $url URL to fetch.
517 * @param hash $parameters Optional additional GET data.
518 * @return boolean True on success.
521 function get($url, $parameters = false
) {
522 $content = $this->_browser
->get($url, $parameters);
523 if ($content === false
) {
530 * Fetches a page by POST into the page buffer.
531 * If there is no base for the URL then the
532 * current base URL is used. After the fetch
533 * the base URL reflects the new location.
534 * @param string $url URL to fetch.
535 * @param hash $parameters Optional additional GET data.
536 * @return boolean True on success.
539 function post($url, $parameters = false
) {
540 $content = $this->_browser
->post($url, $parameters);
541 if ($content === false
) {
548 * Does a HTTP HEAD fetch, fetching only the page
549 * headers. The current base URL is unchanged by this.
550 * @param string $url URL to fetch.
551 * @param hash $parameters Optional additional GET data.
552 * @return boolean True on success.
555 function head($url, $parameters = false
) {
556 return $this->_browser
->head($url, $parameters);
560 * Equivalent to hitting the retry button on the
561 * browser. Will attempt to repeat the page fetch.
562 * @return boolean True if fetch succeeded.
566 return $this->_browser
->retry();
570 * Equivalent to hitting the back button on the
572 * @return boolean True if history entry and
577 return $this->_browser
->back();
581 * Equivalent to hitting the forward button on the
583 * @return boolean True if history entry and
588 return $this->_browser
->forward();
592 * Retries a request after setting the authentication
593 * for the current realm.
594 * @param string $username Username for realm.
595 * @param string $password Password for realm.
596 * @return boolean True if successful fetch. Note
597 * that authentication may still have
601 function authenticate($username, $password) {
602 return $this->_browser
->authenticate($username, $password);
606 * Accessor for current frame focus. Will be
607 * false if no frame has focus.
608 * @return integer/string/boolean Label if any, otherwise
609 * the position in the frameset
613 function getFrameFocus() {
614 return $this->_browser
->getFrameFocus();
618 * Sets the focus by index. The integer index starts from 1.
619 * @param integer $choice Chosen frame.
620 * @return boolean True if frame exists.
623 function setFrameFocusByIndex($choice) {
624 return $this->_browser
->setFrameFocusByIndex($choice);
628 * Sets the focus by name.
629 * @param string $name Chosen frame.
630 * @return boolean True if frame exists.
633 function setFrameFocus($name) {
634 return $this->_browser
->setFrameFocus($name);
638 * Clears the frame focus. All frames will be searched
642 function clearFrameFocus() {
643 return $this->_browser
->clearFrameFocus();
647 * Clicks the submit button by label. The owning
648 * form will be submitted by this.
649 * @param string $label Button label. An unlabeled
650 * button can be triggered by 'Submit'.
651 * @return boolean True on success.
654 function clickSubmit($label = 'Submit') {
655 return $this->_browser
->clickSubmit($label);
659 * Clicks the submit button by name attribute. The owning
660 * form will be submitted by this.
661 * @param string $name Name attribute of button.
662 * @return boolean True on success.
665 function clickSubmitByName($name) {
666 return $this->_browser
->clickSubmitByName($name);
670 * Clicks the submit button by ID attribute. The owning
671 * form will be submitted by this.
672 * @param string $id ID attribute of button.
673 * @return boolean True on successful submit.
676 function clickSubmitById($id) {
677 return $this->_browser
->clickSubmitById($id);
681 * Clicks the submit image by some kind of label. Usually
682 * the alt tag or the nearest equivalent. The owning
683 * form will be submitted by this. Clicking outside of
684 * the boundary of the coordinates will result in
686 * @param string $label Alt attribute of button.
687 * @param integer $x X-coordinate of imaginary click.
688 * @param integer $y Y-coordinate of imaginary click.
689 * @return boolean True on successful submit.
692 function clickImage($label, $x = 1, $y = 1) {
693 return $this->_browser
->clickImage($label, $x, $y);
697 * Clicks the submit image by the name. Usually
698 * the alt tag or the nearest equivalent. The owning
699 * form will be submitted by this. Clicking outside of
700 * the boundary of the coordinates will result in
702 * @param string $name Name attribute of button.
703 * @param integer $x X-coordinate of imaginary click.
704 * @param integer $y Y-coordinate of imaginary click.
705 * @return boolean True on successful submit.
708 function clickImageByName($name, $x = 1, $y = 1) {
709 return $this->_browser
->clickImageByName($name, $x, $y);
713 * Clicks the submit image by ID attribute. The owning
714 * form will be submitted by this. Clicking outside of
715 * the boundary of the coordinates will result in
717 * @param integer/string $id ID attribute of button.
718 * @param integer $x X-coordinate of imaginary click.
719 * @param integer $y Y-coordinate of imaginary click.
720 * @return boolean True on successful submit.
723 function clickImageById($id, $x = 1, $y = 1) {
724 return $this->_browser
->clickImageById($id, $x, $y);
728 * Submits a form by the ID.
729 * @param string $id Form ID. No button information
730 * is submitted this way.
731 * @return boolean True on success.
734 function submitFormById($id) {
735 return $this->_browser
->submitFormById($id);
739 * Follows a link by name. Will click the first link
740 * found with this link text by default, or a later
741 * one if an index is given. Match is case insensitive
742 * with normalised space.
743 * @param string $label Text between the anchor tags.
744 * @param integer $index Link position counting from zero.
745 * @return boolean True if link present.
748 function clickLink($label, $index = 0) {
749 return $this->_browser
->clickLink($label, $index);
753 * Follows a link by id attribute.
754 * @param string $id ID attribute value.
755 * @return boolean True if successful.
758 function clickLinkById($id) {
759 return $this->_browser
->clickLinkById($id);
763 * Tests for the presence of a link label. Match is
764 * case insensitive with normalised space.
765 * @param string $label Text between the anchor tags.
766 * @param string $message Message to display. Default
767 * can be embedded with %s.
768 * @return boolean True if link present.
771 function assertLink($label, $message = "%s") {
772 return $this->assertTrue(
773 $this->_browser
->isLink($label),
774 sprintf($message, "Link [$label] should exist"));
778 * Tests for the non-presence of a link label. Match is
779 * case insensitive with normalised space.
780 * @param string/integer $label Text between the anchor tags
782 * @param string $message Message to display. Default
783 * can be embedded with %s.
784 * @return boolean True if link missing.
787 function assertNoLink($label, $message = "%s") {
788 return $this->assertFalse(
789 $this->_browser
->isLink($label) ||
$this->_browser
->isLinkById($label),
790 sprintf($message, "Link [$label] should not exist"));
794 * Tests for the presence of a link id attribute.
795 * @param string $id Id attribute value.
796 * @param string $message Message to display. Default
797 * can be embedded with %s.
798 * @return boolean True if link present.
801 function assertLinkById($id, $message = "%s") {
802 return $this->assertTrue(
803 $this->_browser
->isLinkById($id),
804 sprintf($message, "Link ID [$id] should exist"));
808 * Sets all form fields with that name.
809 * @param string $name Name of field in forms.
810 * @param string $value New value of field.
811 * @return boolean True if field exists, otherwise false.
814 function setField($name, $value) {
815 return $this->_browser
->setField($name, $value);
819 * Sets all form fields with that name.
820 * @param string/integer $id Id of field in forms.
821 * @param string $value New value of field.
822 * @return boolean True if field exists, otherwise false.
825 function setFieldById($id, $value) {
826 return $this->_browser
->setFieldById($id, $value);
830 * Confirms that the form element is currently set
831 * to the expected value. A missing form will always
832 * fail. If no value is given then only the existence
833 * of the field is checked.
834 * @param string $name Name of field in forms.
835 * @param mixed $expected Expected string/array value or
836 * false for unset fields.
837 * @param string $message Message to display. Default
838 * can be embedded with %s.
839 * @return boolean True if pass.
842 function assertField($name, $expected = true
, $message = "%s") {
843 $value = $this->_browser
->getField($name);
844 if ($expected === true
) {
845 return $this->assertTrue(
847 sprintf($message, "Field [$name] should exist"));
849 return $this->assertExpectation(
850 new FieldExpectation($expected),
852 sprintf($message, "Field [$name] should match with [%s]"));
857 * Confirms that the form element is currently set
858 * to the expected value. A missing form will always
859 * fail. If no ID is given then only the existence
860 * of the field is checked.
861 * @param string/integer $id Name of field in forms.
862 * @param mixed $expected Expected string/array value or
863 * false for unset fields.
864 * @param string $message Message to display. Default
865 * can be embedded with %s.
866 * @return boolean True if pass.
869 function assertFieldById($id, $expected = true
, $message = "%s") {
870 $value = $this->_browser
->getFieldById($id);
871 if ($expected === true
) {
872 return $this->assertTrue(
874 sprintf($message, "Field of ID [$id] should exist"));
876 return $this->assertExpectation(
877 new FieldExpectation($expected),
879 sprintf($message, "Field of ID [$id] should match with [%s]"));
884 * Checks the response code against a list
885 * of possible values.
886 * @param array $responses Possible responses for a pass.
887 * @param string $message Message to display. Default
888 * can be embedded with %s.
889 * @return boolean True if pass.
892 function assertResponse($responses, $message = '%s') {
893 $responses = (is_array($responses) ?
$responses : array($responses));
894 $code = $this->_browser
->getResponseCode();
895 $message = sprintf($message, "Expecting response in [" .
896 implode(", ", $responses) . "] got [$code]");
897 return $this->assertTrue(in_array($code, $responses), $message);
901 * Checks the mime type against a list
902 * of possible values.
903 * @param array $types Possible mime types for a pass.
904 * @param string $message Message to display.
905 * @return boolean True if pass.
908 function assertMime($types, $message = '%s') {
909 $types = (is_array($types) ?
$types : array($types));
910 $type = $this->_browser
->getMimeType();
911 $message = sprintf($message, "Expecting mime type in [" .
912 implode(", ", $types) . "] got [$type]");
913 return $this->assertTrue(in_array($type, $types), $message);
917 * Attempt to match the authentication type within
918 * the security realm we are currently matching.
919 * @param string $authentication Usually basic.
920 * @param string $message Message to display.
921 * @return boolean True if pass.
924 function assertAuthentication($authentication = false
, $message = '%s') {
925 if (! $authentication) {
926 $message = sprintf($message, "Expected any authentication type, got [" .
927 $this->_browser
->getAuthentication() . "]");
928 return $this->assertTrue(
929 $this->_browser
->getAuthentication(),
932 $message = sprintf($message, "Expected authentication [$authentication] got [" .
933 $this->_browser
->getAuthentication() . "]");
934 return $this->assertTrue(
935 strtolower($this->_browser
->getAuthentication()) == strtolower($authentication),
941 * Checks that no authentication is necessary to view
943 * @param string $message Message to display.
944 * @return boolean True if pass.
947 function assertNoAuthentication($message = '%s') {
948 $message = sprintf($message, "Expected no authentication type, got [" .
949 $this->_browser
->getAuthentication() . "]");
950 return $this->assertFalse($this->_browser
->getAuthentication(), $message);
954 * Attempts to match the current security realm.
955 * @param string $realm Name of security realm.
956 * @param string $message Message to display.
957 * @return boolean True if pass.
960 function assertRealm($realm, $message = '%s') {
961 $message = sprintf($message, "Expected realm [$realm] got [" .
962 $this->_browser
->getRealm() . "]");
963 return $this->assertTrue(
964 strtolower($this->_browser
->getRealm()) == strtolower($realm),
969 * Checks each header line for the required value. If no
970 * value is given then only an existence check is made.
971 * @param string $header Case insensitive header name.
972 * @param string $value Case sensitive trimmed string to
974 * @return boolean True if pass.
977 function assertHeader($header, $value = false
, $message = '%s') {
978 return $this->assertExpectation(
979 new HttpHeaderExpectation($header, $value),
980 $this->_browser
->getHeaders(),
985 * Checks each header line for the required pattern.
986 * @param string $header Case insensitive header name.
987 * @param string $pattern Pattern to match value against.
988 * @return boolean True if pass.
991 function assertHeaderPattern($header, $pattern, $message = '%s') {
992 return $this->assertExpectation(
993 new HttpHeaderPatternExpectation($header, $pattern),
994 $this->_browser
->getHeaders(),
999 * Confirms that the header type has not been received.
1000 * Only the landing page is checked. If you want to check
1001 * redirect pages, then you should limit redirects so
1002 * as to capture the page you want.
1003 * @param string $header Case insensitive header name.
1004 * @return boolean True if pass.
1007 function assertNoUnwantedHeader($header, $message = '%s') {
1008 return $this->assertExpectation(
1009 new HttpUnwantedHeaderExpectation($header),
1010 $this->_browser
->getHeaders(),
1015 * Tests the text between the title tags.
1016 * @param string $title Expected title or empty
1017 * if expecting no title.
1018 * @param string $message Message to display.
1019 * @return boolean True if pass.
1022 function assertTitle($title = false
, $message = '%s') {
1023 return $this->assertTrue(
1024 $title === $this->_browser
->getTitle(),
1027 "Expecting title [$title] got [" . $this->_browser
->getTitle() . "]"));
1031 * Will trigger a pass if the Perl regex pattern
1032 * is found in the raw content.
1033 * @param string $pattern Perl regex to look for including
1034 * the regex delimiters.
1035 * @param string $message Message to display.
1036 * @return boolean True if pass.
1039 function assertWantedPattern($pattern, $message = '%s') {
1040 return $this->assertExpectation(
1041 new WantedPatternExpectation($pattern),
1042 $this->_browser
->getContent(),
1047 * Will trigger a pass if the perl regex pattern
1048 * is not present in raw content.
1049 * @param string $pattern Perl regex to look for including
1050 * the regex delimiters.
1051 * @param string $message Message to display.
1052 * @return boolean True if pass.
1055 function assertNoUnwantedPattern($pattern, $message = "%s") {
1056 return $this->assertExpectation(
1057 new UnwantedPatternExpectation($pattern),
1058 $this->_browser
->getContent(),
1063 * Checks that a cookie is set for the current page
1064 * and optionally checks the value.
1065 * @param string $name Name of cookie to test.
1066 * @param string $expected Expected value as a string or
1067 * false if any value will do.
1068 * @param string $message Message to display.
1069 * @return boolean True if pass.
1072 function assertCookie($name, $expected = false
, $message = "%s") {
1073 $value = $this->_browser
->getCurrentCookieValue($name);
1075 return $this->assertTrue($value === $expected, sprintf(
1077 "Expecting cookie [$name] value [$expected], got [$value]"));
1079 return $this->assertTrue(
1081 sprintf($message, "Expecting cookie [$name]"));
1086 * Checks that no cookie is present or that it has
1087 * been successfully cleared.
1088 * @param string $name Name of cookie to test.
1089 * @param string $message Message to display.
1090 * @return boolean True if pass.
1093 function assertNoCookie($name, $message = "%s") {
1094 return $this->assertTrue(
1095 $this->_browser
->getCurrentCookieValue($name) === false
,
1096 sprintf($message, "Not expecting cookie [$name]"));