[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/test_tools/simpletest/ -> web_tester.php (sommaire)

Base include file for SimpleTest.

Version: $Id: web_tester.php 1397 2006-09-07 07:55:53Z wei $
Poids: 1455 lignes (58 kb)
Inclus ou requis: 2 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 6 classes

FieldExpectation:: (6 méthodes):
  FieldExpectation()
  test()
  _isSingle()
  _testSingle()
  _testMultiple()
  testMessage()

HttpHeaderExpectation:: (8 méthodes):
  HttpHeaderExpectation()
  _getExpectation()
  _normaliseHeader()
  test()
  _findHeader()
  _testHeaderLine()
  _testHeaderValue()
  testMessage()

NoHttpHeaderExpectation:: (3 méthodes):
  NoHttpHeaderExpectation()
  test()
  testMessage()

TextExpectation:: (5 méthodes):
  TextExpectation()
  _getSubstring()
  test()
  testMessage()
  _describeTextMatch()

NoTextExpectation:: (3 méthodes):
  NoTextExpectation()
  test()
  testMessage()

WebTestCase:: (79 méthodes):
  WebTestCase()
  before()
  after()
  getBrowser()
  setBrowser()
  unsetBrowser()
  createBrowser()
  getTransportError()
  getUrl()
  showRequest()
  showHeaders()
  showSource()
  showText()
  restart()
  ageCookies()
  ignoreFrames()
  ignoreCookies()
  ignoreErrors()
  _failOnError()
  addHeader()
  setMaximumRedirects()
  setConnectionTimeout()
  useProxy()
  get()
  post()
  head()
  retry()
  back()
  forward()
  authenticate()
  getCookie()
  setCookie()
  getFrameFocus()
  setFrameFocusByIndex()
  setFrameFocus()
  clearFrameFocus()
  click()
  clickSubmit()
  clickSubmitByName()
  clickSubmitById()
  clickImage()
  clickImageByName()
  clickImageById()
  submitFormById()
  clickLink()
  clickLinkById()
  assertEqual()
  assertNotEqual()
  assertLink()
  assertNoLink()
  assertLinkById()
  assertNoLinkById()
  setField()
  setFieldByName()
  setFieldById()
  assertField()
  assertFieldByName()
  assertFieldById()
  _assertFieldValue()
  assertResponse()
  assertMime()
  assertAuthentication()
  assertNoAuthentication()
  assertRealm()
  assertHeader()
  assertHeaderPattern()
  assertNoHeader()
  assertNoUnwantedHeader()
  assertTitle()
  assertText()
  assertWantedText()
  assertNoText()
  assertNoUnwantedText()
  assertPattern()
  assertWantedPattern()
  assertNoPattern()
  assertNoUnwantedPattern()
  assertCookie()
  assertNoCookie()


Classe: FieldExpectation  - X-Ref

Test for an HTML widget value match.

FieldExpectation($value, $message = '%s')   X-Ref
Sets the field value to compare against.

param: mixed $value     Test value to match. Can be an
param: string $message  Optiona message override. Can use %s as

test($compare)   X-Ref
Tests the expectation. True if it matches
a string value or an array value in any order.

param: mixed $compare        Comparison value. False for
return: boolean              True if correct.

_isSingle($value)   X-Ref
Tests for valid field comparisons with a single option.

param: mixed $value       Value to type check.
return: boolean           True if integer, string or float.

_testSingle($compare)   X-Ref
String comparison for simple field with a single option.

returns: boolean         True if matching.
param: mixed $compare    String to test against.

_testMultiple($compare)   X-Ref
List comparison for multivalue field.

returns: boolean         True if matching.
param: mixed $compare    List in any order to test against.

testMessage($compare)   X-Ref
Returns a human readable test message.

param: mixed $compare      Comparison value.
return: string             Description of success

Classe: HttpHeaderExpectation  - X-Ref

Test for a specific HTTP header within a header block.

HttpHeaderExpectation($header, $value = false, $message = '%s')   X-Ref
Sets the field and value to compare against.

param: string $header   Case insenstive trimmed header name.
param: mixed $value     Optional value to compare. If not
param: string $message  Optiona message override. Can use %s as

_getExpectation()   X-Ref
Accessor for aggregated object.

return: mixed        Expectation set in constructor.

_normaliseHeader($header)   X-Ref
Removes whitespace at ends and case variations.

param: string $header    Name of header.
param: string            Trimmed and lowecased header

test($compare)   X-Ref
Tests the expectation. True if it matches
a string value or an array value in any order.

param: mixed $compare   Raw header block to search.
return: boolean         True if header present.

_findHeader($compare)   X-Ref
Searches the incoming result. Will extract the matching
line as text.

param: mixed $compare   Raw header block to search.
return: string          Matching header line.

_testHeaderLine($line)   X-Ref
Compares a single header line against the expectation.

param: string $line      A single line to compare.
return: boolean          True if matched.

_testHeaderValue($value, $expected)   X-Ref
Tests the value part of the header.

param: string $value        Value to test.
param: mixed $expected      Value to test against.
return: boolean             True if matched.

testMessage($compare)   X-Ref
Returns a human readable test message.

param: mixed $compare      Raw header block to search.
return: string             Description of success

Classe: NoHttpHeaderExpectation  - X-Ref

Test for a specific HTTP header within a header block that
should not be found.

NoHttpHeaderExpectation($unwanted, $message = '%s')   X-Ref
Sets the field and value to compare against.

param: string $unwanted   Case insenstive trimmed header name.
param: string $message    Optiona message override. Can use %s as

test($compare)   X-Ref
Tests that the unwanted header is not found.

param: mixed $compare   Raw header block to search.
return: boolean         True if header present.

testMessage($compare)   X-Ref
Returns a human readable test message.

param: mixed $compare      Raw header block to search.
return: string             Description of success

Classe: TextExpectation  - X-Ref

Test for a text substring.

TextExpectation($substring, $message = '%s')   X-Ref
Sets the value to compare against.

param: string $substring  Text to search for.
param: string $message    Customised message on failure.

_getSubstring()   X-Ref
Accessor for the substring.

return: string       Text to match.

test($compare)   X-Ref
Tests the expectation. True if the text contains the
substring.

param: string $compare        Comparison value.
return: boolean               True if correct.

testMessage($compare)   X-Ref
Returns a human readable test message.

param: mixed $compare      Comparison value.
return: string             Description of success

_describeTextMatch($substring, $subject)   X-Ref
Describes a pattern match including the string
found and it's position.

param: string $substring      Text to search for.
param: string $subject        Subject to search.

Classe: NoTextExpectation  - X-Ref

Fail if a substring is detected within the
comparison text.

NoTextExpectation($substring, $message = '%s')   X-Ref
Sets the reject pattern

param: string $substring  Text to search for.
param: string $message    Customised message on failure.

test($compare)   X-Ref
Tests the expectation. False if the substring appears
in the text.

param: string $compare        Comparison value.
return: boolean               True if correct.

testMessage($compare)   X-Ref
Returns a human readable test message.

param: string $compare      Comparison value.
return: string              Description of success

Classe: WebTestCase  - X-Ref

Test case for testing of web pages. Allows
fetching of pages, parsing of HTML and
submitting forms.

WebTestCase($label = false)   X-Ref
Creates an empty test case. Should be subclassed
with test methods for a functional test case.

param: string $label     Name of test case. Will use

before($method)   X-Ref
Announces the start of the test.

param: string $method    Test method just started.

after($method)   X-Ref
Announces the end of the test. Includes private clean up.

param: string $method    Test method just finished.

getBrowser()   X-Ref
Gets a current browser reference for setting
special expectations or for detailed
examination of page fetches.

return: SimpleBrowser     Current test browser object.

setBrowser($browser)   X-Ref
Gets a current browser reference for setting
special expectations or for detailed
examination of page fetches.

param: SimpleBrowser $browser    New test browser object.

unsetBrowser()   X-Ref
Clears the current browser reference to help the
PHP garbage collector.


createBrowser()   X-Ref
Creates a new default web browser object.
Will be cleared at the end of the test method.

return: TestBrowser           New browser.

getTransportError()   X-Ref
Gets the last response error.

return: string    Last low level HTTP error.

getUrl()   X-Ref
Accessor for the currently selected URL.

return: string        Current location or false if

showRequest()   X-Ref
Dumps the current request for debugging.


showHeaders()   X-Ref
Dumps the current HTTP headers for debugging.


showSource()   X-Ref
Dumps the current HTML source for debugging.


showText()   X-Ref
Dumps the visible text only for debugging.


restart($date = false)   X-Ref
Simulates the closing and reopening of the browser.
Temporary cookies will be discarded and timed
cookies will be expired if later than the
specified time.

param: string/integer $date Time when session restarted.

ageCookies($interval)   X-Ref
Moves cookie expiry times back into the past.
Useful for testing timeouts and expiries.

param: integer $interval    Amount to age in seconds.

ignoreFrames()   X-Ref
Disables frames support. Frames will not be fetched
and the frameset page will be used instead.


ignoreCookies()   X-Ref
Switches off cookie sending and recieving.


ignoreErrors()   X-Ref
Skips errors for the next request only. You might
want to confirm that a page is unreachable for
example.


_failOnError($result)   X-Ref
Issues a fail if there is a transport error anywhere
in the current frameset. Only one such error is
reported.

param: string/boolean $result   HTML or failure.
return: string/boolean $result  Passes through result.

addHeader($header)   X-Ref
Adds a header to every fetch.

param: string $header       Header line to add to every

setMaximumRedirects($max)   X-Ref
Sets the maximum number of redirects before
the web page is loaded regardless.

param: integer $max        Maximum hops.

setConnectionTimeout($timeout)   X-Ref
Sets the socket timeout for opening a connection and
receiving at least one byte of information.

param: integer $timeout      Maximum time in seconds.

useProxy($proxy, $username = false, $password = false)   X-Ref
Sets proxy to use on all requests for when
testing from behind a firewall. Set URL
to false to disable.

param: string $proxy        Proxy URL.
param: string $username     Proxy username for authentication.
param: string $password     Proxy password for authentication.

get($url, $parameters = false)   X-Ref
Fetches a page into the page buffer. If
there is no base for the URL then the
current base URL is used. After the fetch
the base URL reflects the new location.

param: string $url          URL to fetch.
param: hash $parameters     Optional additional GET data.
return: boolean/string      Raw page on success.

post($url, $parameters = false)   X-Ref
Fetches a page by POST into the page buffer.
If there is no base for the URL then the
current base URL is used. After the fetch
the base URL reflects the new location.

param: string $url          URL to fetch.
param: hash $parameters     Optional additional GET data.
return: boolean/string      Raw page on success.

head($url, $parameters = false)   X-Ref
Does a HTTP HEAD fetch, fetching only the page
headers. The current base URL is unchanged by this.

param: string $url          URL to fetch.
param: hash $parameters     Optional additional GET data.
return: boolean             True on success.

retry()   X-Ref
Equivalent to hitting the retry button on the
browser. Will attempt to repeat the page fetch.

return: boolean     True if fetch succeeded.

back()   X-Ref
Equivalent to hitting the back button on the
browser.

return: boolean     True if history entry and

forward()   X-Ref
Equivalent to hitting the forward button on the
browser.

return: boolean     True if history entry and

authenticate($username, $password)   X-Ref
Retries a request after setting the authentication
for the current realm.

param: string $username    Username for realm.
param: string $password    Password for realm.
return: boolean/string     HTML on successful fetch. Note

getCookie($name)   X-Ref
Gets the cookie value for the current browser context.

param: string $name          Name of cookie.
return: string               Value of cookie or false if unset.

setCookie($name, $value, $host = false, $path = "/", $expiry = false)   X-Ref
Sets a cookie in the current browser.

param: string $name          Name of cookie.
param: string $value         Cookie value.
param: string $host          Host upon which the cookie is valid.
param: string $path          Cookie path if not host wide.
param: string $expiry        Expiry date.

getFrameFocus()   X-Ref
Accessor for current frame focus. Will be
false if no frame has focus.

return: integer/string/boolean    Label if any, otherwise

setFrameFocusByIndex($choice)   X-Ref
Sets the focus by index. The integer index starts from 1.

param: integer $choice    Chosen frame.
return: boolean           True if frame exists.

setFrameFocus($name)   X-Ref
Sets the focus by name.

param: string $name    Chosen frame.
return: boolean        True if frame exists.

clearFrameFocus()   X-Ref
Clears the frame focus. All frames will be searched
for content.


click($label)   X-Ref
Clicks a visible text item. Will first try buttons,
then links and then images.

param: string $label        Visible text or alt text.
return: string/boolean      Raw page or false.

clickSubmit($label = 'Submit', $additional = false)   X-Ref
Clicks the submit button by label. The owning
form will be submitted by this.

param: string $label    Button label. An unlabeled
param: hash $additional Additional form values.
return: boolean/string  Page on success, else false.

clickSubmitByName($name, $additional = false)   X-Ref
Clicks the submit button by name attribute. The owning
form will be submitted by this.

param: string $name     Name attribute of button.
param: hash $additional Additional form values.
return: boolean/string  Page on success.

clickSubmitById($id, $additional = false)   X-Ref
Clicks the submit button by ID attribute. The owning
form will be submitted by this.

param: string $id       ID attribute of button.
param: hash $additional Additional form values.
return: boolean/string  Page on success.

clickImage($label, $x = 1, $y = 1, $additional = false)   X-Ref
Clicks the submit image by some kind of label. Usually
the alt tag or the nearest equivalent. The owning
form will be submitted by this. Clicking outside of
the boundary of the coordinates will result in
a failure.

param: string $label    Alt attribute of button.
param: integer $x       X-coordinate of imaginary click.
param: integer $y       Y-coordinate of imaginary click.
param: hash $additional Additional form values.
return: boolean/string  Page on success.

clickImageByName($name, $x = 1, $y = 1, $additional = false)   X-Ref
Clicks the submit image by the name. Usually
the alt tag or the nearest equivalent. The owning
form will be submitted by this. Clicking outside of
the boundary of the coordinates will result in
a failure.

param: string $name     Name attribute of button.
param: integer $x       X-coordinate of imaginary click.
param: integer $y       Y-coordinate of imaginary click.
param: hash $additional Additional form values.
return: boolean/string  Page on success.

clickImageById($id, $x = 1, $y = 1, $additional = false)   X-Ref
Clicks the submit image by ID attribute. The owning
form will be submitted by this. Clicking outside of
the boundary of the coordinates will result in
a failure.

param: integer/string $id   ID attribute of button.
param: integer $x           X-coordinate of imaginary click.
param: integer $y           Y-coordinate of imaginary click.
param: hash $additional     Additional form values.
return: boolean/string      Page on success.

submitFormById($id)   X-Ref
Submits a form by the ID.

param: string $id       Form ID. No button information
return: boolean/string  Page on success.

clickLink($label, $index = 0)   X-Ref
Follows a link by name. Will click the first link
found with this link text by default, or a later
one if an index is given. Match is case insensitive
with normalised space.

param: string $label     Text between the anchor tags.
param: integer $index    Link position counting from zero.
return: boolean/string   Page on success.

clickLinkById($id)   X-Ref
Follows a link by id attribute.

param: string $id        ID attribute value.
return: boolean/string   Page on success.

assertEqual($first, $second, $message = "%s")   X-Ref
Will trigger a pass if the two parameters have
the same value only. Otherwise a fail. This
is for testing hand extracted text, etc.

param: mixed $first          Value to compare.
param: mixed $second         Value to compare.
param: string $message       Message to display.
return: boolean              True on pass

assertNotEqual($first, $second, $message = "%s")   X-Ref
Will trigger a pass if the two parameters have
a different value. Otherwise a fail. This
is for testing hand extracted text, etc.

param: mixed $first           Value to compare.
param: mixed $second          Value to compare.
param: string $message        Message to display.
return: boolean               True on pass

assertLink($label, $message = "%s")   X-Ref
Tests for the presence of a link label. Match is
case insensitive with normalised space.

param: string $label     Text between the anchor tags.
param: string $message   Message to display. Default
return: boolean          True if link present.

assertNoLink($label, $message = "%s")   X-Ref
Tests for the non-presence of a link label. Match is
case insensitive with normalised space.

param: string/integer $label    Text between the anchor tags
param: string $message          Message to display. Default
return: boolean                 True if link missing.

assertLinkById($id, $message = "%s")   X-Ref
Tests for the presence of a link id attribute.

param: string $id        Id attribute value.
param: string $message   Message to display. Default
return: boolean          True if link present.

assertNoLinkById($id, $message = "%s")   X-Ref
Tests for the non-presence of a link label. Match is
case insensitive with normalised space.

param: string $id        Id attribute value.
param: string $message   Message to display. Default
return: boolean          True if link missing.

setField($label, $value)   X-Ref
Sets all form fields with that label, or name if there
is no label attached.

param: string $name    Name of field in forms.
param: string $value   New value of field.
return: boolean        True if field exists, otherwise false.

setFieldByName($name, $value)   X-Ref
Sets all form fields with that name.

param: string $name    Name of field in forms.
param: string $value   New value of field.
return: boolean        True if field exists, otherwise false.

setFieldById($id, $value)   X-Ref
Sets all form fields with that name.

param: string/integer $id   Id of field in forms.
param: string $value        New value of field.
return: boolean             True if field exists, otherwise false.

assertField($label, $expected = true, $message = '%s')   X-Ref
Confirms that the form element is currently set
to the expected value. A missing form will always
fail. If no value is given then only the existence
of the field is checked.

param: string $name       Name of field in forms.
param: mixed $expected    Expected string/array value or
param: string $message    Message to display. Default
return: boolean           True if pass.

assertFieldByName($name, $expected = true, $message = '%s')   X-Ref
Confirms that the form element is currently set
to the expected value. A missing form element will always
fail. If no value is given then only the existence
of the field is checked.

param: string $name       Name of field in forms.
param: mixed $expected    Expected string/array value or
param: string $message    Message to display. Default
return: boolean           True if pass.

assertFieldById($id, $expected = true, $message = '%s')   X-Ref
Confirms that the form element is currently set
to the expected value. A missing form will always
fail. If no ID is given then only the existence
of the field is checked.

param: string/integer $id  Name of field in forms.
param: mixed $expected     Expected string/array value or
param: string $message     Message to display. Default
return: boolean            True if pass.

_assertFieldValue($identifier, $value, $expected, $message)   X-Ref
Tests the field value against the expectation.

param: string $identifier      Name, ID or label.
param: mixed $value            Current field value.
param: mixed $expected         Expected value to match.
param: string $message         Failure message.
return: boolean                True if pass

assertResponse($responses, $message = '%s')   X-Ref
Checks the response code against a list
of possible values.

param: array $responses    Possible responses for a pass.
param: string $message     Message to display. Default
return: boolean            True if pass.

assertMime($types, $message = '%s')   X-Ref
Checks the mime type against a list
of possible values.

param: array $types      Possible mime types for a pass.
param: string $message   Message to display.
return: boolean          True if pass.

assertAuthentication($authentication = false, $message = '%s')   X-Ref
Attempt to match the authentication type within
the security realm we are currently matching.

param: string $authentication   Usually basic.
param: string $message          Message to display.
return: boolean                 True if pass.

assertNoAuthentication($message = '%s')   X-Ref
Checks that no authentication is necessary to view
the desired page.

param: string $message     Message to display.
return: boolean            True if pass.

assertRealm($realm, $message = '%s')   X-Ref
Attempts to match the current security realm.

param: string $realm     Name of security realm.
param: string $message   Message to display.
return: boolean          True if pass.

assertHeader($header, $value = false, $message = '%s')   X-Ref
Checks each header line for the required value. If no
value is given then only an existence check is made.

param: string $header    Case insensitive header name.
param: mixed $value      Case sensitive trimmed string to
return: boolean          True if pass.

assertHeaderPattern($header, $pattern, $message = '%s')   X-Ref


assertNoHeader($header, $message = '%s')   X-Ref
Confirms that the header type has not been received.
Only the landing page is checked. If you want to check
redirect pages, then you should limit redirects so
as to capture the page you want.

param: string $header    Case insensitive header name.
return: boolean          True if pass.

assertNoUnwantedHeader($header, $message = '%s')   X-Ref


assertTitle($title = false, $message = '%s')   X-Ref
Tests the text between the title tags.

param: string $title      Expected title.
param: string $message    Message to display.
return: boolean           True if pass.

assertText($text, $message = '%s')   X-Ref
Will trigger a pass if the text is found in the plain
text form of the page.

param: string $text       Text to look for.
param: string $message    Message to display.
return: boolean           True if pass.

assertWantedText($text, $message = '%s')   X-Ref


assertNoText($text, $message = '%s')   X-Ref
Will trigger a pass if the text is not found in the plain
text form of the page.

param: string $text       Text to look for.
param: string $message    Message to display.
return: boolean           True if pass.

assertNoUnwantedText($text, $message = '%s')   X-Ref


assertPattern($pattern, $message = '%s')   X-Ref
Will trigger a pass if the Perl regex pattern
is found in the raw content.

param: string $pattern    Perl regex to look for including
param: string $message    Message to display.
return: boolean           True if pass.

assertWantedPattern($pattern, $message = '%s')   X-Ref


assertNoPattern($pattern, $message = '%s')   X-Ref
Will trigger a pass if the perl regex pattern
is not present in raw content.

param: string $pattern    Perl regex to look for including
param: string $message    Message to display.
return: boolean           True if pass.

assertNoUnwantedPattern($pattern, $message = '%s')   X-Ref


assertCookie($name, $expected = false, $message = '%s')   X-Ref
Checks that a cookie is set for the current page
and optionally checks the value.

param: string $name        Name of cookie to test.
param: string $expected    Expected value as a string or
param: string $message     Message to display.
return: boolean            True if pass.

assertNoCookie($name, $message = '%s')   X-Ref
Checks that no cookie is present or that it has
been successfully cleared.

param: string $name        Name of cookie to test.
param: string $message     Message to display.
return: boolean            True if pass.



Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7