DrupalWebTestCase Class Reference

Inheritance diagram for DrupalWebTestCase:
[legend]
Collaboration diagram for DrupalWebTestCase:
[legend]

List of all members.


Public Member Functions

 __construct ($label=NULL)
 drupalCreateNode ($settings=array())
 drupalCreateContentType ($settings=array())
 drupalGetTestFiles ($type, $size=NULL)
 drupalCompareFiles ($file1, $file2)
 randomName ($number=4, $prefix= 'simpletest_')
 drupalModuleEnable ($name)
 drupalModuleDisable ($name)
 drupalCreateUser ($permissions=NULL)
 drupalLogin ($user=NULL)
 drupalLogout ()
 setUp ()
 refreshVariables ()
 tearDown ()
 run (&$reporter)
 drupalGet ($path, $options=array())
 drupalPost ($path, $edit, $submit, $tamper=FALSE)
 clickLink ($label, $index=0)
 getAbsoluteUrl ($path)
 getUrl ()
 drupalGetContent ()
 assertRaw ($raw, $message="%s", $group= 'Other')
 assertNoRaw ($raw, $message="%s", $group= 'Other')
 assertText ($text, $message= '', $group= 'Other')
 assertNoText ($text, $message= '', $group= 'Other')
 assertPattern ($pattern, $message= '%s', $group= 'Other')
 assertNoPattern ($pattern, $message= '%s', $group= 'Other')
 assertTitle ($title, $message, $group= 'Other')
 assertFieldByXPath ($xpath, $value, $message, $group= 'Other')
 assertNoFieldByXPath ($xpath, $value, $message, $group= 'Other')
 assertFieldByName ($name, $value= '', $message= '')
 assertNoFieldByName ($name, $value= '', $message= '')
 assertFieldById ($id, $value= '', $message= '')
 assertNoFieldById ($id, $value= '', $message= '')
 assertField ($field, $message= '', $group= 'Other')
 assertNoField ($field, $message= '', $group= 'Other')
 _constructFieldXpath ($attribute, $value)
 assertResponse ($code, $message= '')

Protected Member Functions

 curlConnect ()
 curlExec ($curl_options)
 curlClose ()
 parse ()
 handleForm (&$post, &$edit, &$upload, $submit, $form)
 assertTextHelper ($text, $message, $group, $not_exists)

Protected Attributes

 $_logged_in = FALSE
 $_content
 $plain_text
 $ch
 $elements
 $_modules = array()
 $cookie_file = NULL
 $curl_options = array()
 $db_prefix_original
 $original_file_directory

Private Member Functions

 _drupalCreateRole ($permissions=NULL)
 getAllOptions (SimpleXMLElement $element)


Detailed Description

Test case for typical Drupal tests.

Definition at line 7 of file drupal_web_test_case.php.


Constructor & Destructor Documentation

DrupalWebTestCase::__construct ( label = NULL  ) 

Retrieve the test information from getInfo().

Parameters:
string $label Name of the test to be used by the SimpleTest library.

Definition at line 28 of file drupal_web_test_case.php.


Member Function Documentation

DrupalWebTestCase::drupalCreateNode ( settings = array()  ) 

Creates a node based on default settings.

Parameters:
settings An assocative array of settings to change from the defaults, keys are node properties, for example 'body' => 'Hello, world!'.
Returns:
object Created node object.

Definition at line 46 of file drupal_web_test_case.php.

References db_query(), format_date(), and randomName().

Here is the call graph for this function:

DrupalWebTestCase::drupalCreateContentType ( settings = array()  ) 

Creates a custom content type based on default settings.

Parameters:
settings An array of settings to change from the defaults. Example: 'type' => 'foo'.
Returns:
object Created content type.

Definition at line 91 of file drupal_web_test_case.php.

References $name, $type, and randomName().

Here is the call graph for this function:

DrupalWebTestCase::drupalGetTestFiles ( type,
size = NULL 
)

Get a list files that can be used in tests.

Parameters:
string $type File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'.
integer $size File size in bytes to match. Please check the tests/files folder.
Returns:
array List of files that match filter.

Definition at line 134 of file drupal_web_test_case.php.

References $type, and file_scan_directory().

Here is the call graph for this function:

DrupalWebTestCase::drupalCompareFiles ( file1,
file2 
)

Compare two files based on size.

Definition at line 160 of file drupal_web_test_case.php.

DrupalWebTestCase::randomName ( number = 4,
prefix = 'simpletest_' 
)

Generates a random string.

Parameters:
integer $number Number of characters in length to append to the prefix.
string $prefix Prefix to use.
Returns:
string Randomly generated string.

Definition at line 174 of file drupal_web_test_case.php.

Referenced by _drupalCreateRole(), drupalCreateContentType(), drupalCreateNode(), and drupalCreateUser().

DrupalWebTestCase::drupalModuleEnable ( name  ) 

Enables a drupal module in the test database. Any module that is not part of the required core modules needs to be enabled in order to use it in a test.

Parameters:
string $name Name of the module to enable.
Returns:
boolean Success.

Definition at line 193 of file drupal_web_test_case.php.

References $name, UnitTestCase::assertTrue(), cache_clear_all(), drupal_execute(), drupal_rebuild_theme_registry(), menu_rebuild(), module_exists(), module_rebuild_cache(), SimpleTestCase::pass(), and t().

Here is the call graph for this function:

DrupalWebTestCase::drupalModuleDisable ( name  ) 

Disables a drupal module in the test database.

Parameters:
string $name Name of the module.
Returns:
boolean Success.
See also:
drupalModuleEnable()

Definition at line 218 of file drupal_web_test_case.php.

References $name, UnitTestCase::assertTrue(), cache_clear_all(), drupal_execute(), drupal_rebuild_theme_registry(), menu_rebuild(), module_exists(), module_rebuild_cache(), SimpleTestCase::pass(), and t().

Here is the call graph for this function:

DrupalWebTestCase::drupalCreateUser ( permissions = NULL  ) 

Create a user with a given set of permissions. The permissions correspond to the names given on the privileges page.

Parameters:
array $permissions Array of permission names to assign to user.
Returns:
A fully loaded user object with pass_raw property, or FALSE if account creation fails.

Definition at line 244 of file drupal_web_test_case.php.

References _drupalCreateRole(), UnitTestCase::assertTrue(), randomName(), and t().

Here is the call graph for this function:

DrupalWebTestCase::_drupalCreateRole ( permissions = NULL  )  [private]

Internal helper function; Create a role with specified permissions.

Parameters:
array $permissions Array of permission names to assign to role.
Returns:
integer Role ID of newly created role, or FALSE if role creation failed.

Definition at line 277 of file drupal_web_test_case.php.

References UnitTestCase::assertTrue(), db_fetch_object(), db_query(), db_result(), randomName(), and t().

Referenced by drupalCreateUser(), and drupalLogin().

Here is the call graph for this function:

DrupalWebTestCase::drupalLogin ( user = NULL  ) 

Logs in a user with the internal browser. If already logged in then logs the current user out before logging in the specified user. If no user is specified then a new user will be created and logged in.

Parameters:
object $user User object representing the user to login.
Returns:
object User that was logged in. Useful if no user was passed in order to retreive the created user.

Definition at line 311 of file drupal_web_test_case.php.

References _drupalCreateRole(), assertNoText(), assertText(), drupalLogout(), drupalPost(), name, and t().

Here is the call graph for this function:

DrupalWebTestCase::drupalLogout (  ) 

Definition at line 338 of file drupal_web_test_case.php.

References assertField(), drupalGet(), and t().

Referenced by drupalLogin().

Here is the call graph for this function:

DrupalWebTestCase::setUp (  ) 

Generates a random database prefix and runs the install scripts on the prefixed database. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix. A temporary files directory is created with the same name as the database prefix.

Parameters:
... List modules to enable.

Reimplemented from SimpleTestCase.

Definition at line 358 of file drupal_web_test_case.php.

References $db_prefix, _drupal_flush_css_js(), actions_synchronize(), drupal_install_modules(), drupal_install_system(), drupal_map_assoc(), drupal_verify_profile(), file_check_directory(), file_directory_path(), menu_rebuild(), refreshVariables(), variable_get(), and variable_set().

Here is the call graph for this function:

DrupalWebTestCase::refreshVariables (  ) 

Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread.

In other words calling a settings page with $this->drupalPost() with a changed value would update a variable to reflect that change, but in the thread that made the call (thread running the test) the changed variable would not be picked up.

This method clears the variables cache and loads a fresh copy from the database to ensure that the most up-to-date set of variables is loaded.

Definition at line 414 of file drupal_web_test_case.php.

References cache_clear_all(), and variable_init().

Referenced by drupalGet(), drupalPost(), and setUp().

Here is the call graph for this function:

DrupalWebTestCase::tearDown (  ) 

Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.

Reimplemented from SimpleTestCase.

Definition at line 424 of file drupal_web_test_case.php.

References $db_prefix, $name, curlClose(), db_drop_table(), drupal_get_schema(), file_directory_path(), and variable_set().

Here is the call graph for this function:

DrupalWebTestCase::run ( &$  reporter  ) 

Set necessary reporter info.

Reimplemented from SimpleTestCase.

Definition at line 453 of file drupal_web_test_case.php.

DrupalWebTestCase::curlConnect (  )  [protected]

Initializes the cURL connection and gets a session cookie.

This function will add authentaticon headers as specified in simpletest_httpauth_username and simpletest_httpauth_pass variables. Also, see the description of $curl_options among the properties.

Definition at line 470 of file drupal_web_test_case.php.

References $base_url, $curl_options, $db_prefix, curlExec(), and variable_get().

Referenced by curlExec().

Here is the call graph for this function:

DrupalWebTestCase::curlExec ( curl_options  )  [protected]

Peforms a cURL exec with the specified options after calling curlConnect().

Parameters:
array $curl_options Custom cURL options.
Returns:
string Content returned from the exec.

Definition at line 499 of file drupal_web_test_case.php.

References $curl_options, $url, UnitTestCase::assertTrue(), curlConnect(), and t().

Referenced by clickLink(), curlConnect(), drupalGet(), and drupalPost().

Here is the call graph for this function:

DrupalWebTestCase::curlClose (  )  [protected]

Close the cURL handler and unset the handler.

Definition at line 513 of file drupal_web_test_case.php.

Referenced by tearDown().

DrupalWebTestCase::parse (  )  [protected]

Parse content returned from curlExec using DOM and simplexml.

Returns:
SimpleXMLElement A SimpleXMLElement or FALSE on failure.

Definition at line 525 of file drupal_web_test_case.php.

References UnitTestCase::assertTrue(), SimpleTestCase::fail(), getUrl(), and t().

Referenced by assertFieldByXPath(), assertNoFieldByXPath(), assertTitle(), clickLink(), and drupalPost().

Here is the call graph for this function:

DrupalWebTestCase::drupalGet ( path,
options = array() 
)

Retrieves a Drupal path or an absolute path.

Parameters:
$path string Drupal path or url to load into internal browser
array $options Options to be forwarded to url().
Returns:
The retrieved HTML string, also available as $this->drupalGetContent()

Definition at line 550 of file drupal_web_test_case.php.

References curlExec(), refreshVariables(), and url().

Referenced by drupalLogout(), and drupalPost().

Here is the call graph for this function:

DrupalWebTestCase::drupalPost ( path,
edit,
submit,
tamper = FALSE 
)

Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser By $reporting you specify if this request does assertions or not Warning: empty ("") returns will cause fails with $reporting

Parameters:
string $path Location of the post form. Either a Drupal path or an absolute path or NULL to post to the current page.
array $edit Field data in an assocative array. Changes the current input fields (where possible) to the values indicated. A checkbox can be set to TRUE to be checked and FALSE to be unchecked.
string $submit Untranslated value, id or name of the submit button.
$tamper If this is set to TRUE then you can post anything, otherwise hidden and nonexistent fields are not posted.

Definition at line 580 of file drupal_web_test_case.php.

References $name, $value, UnitTestCase::assertTrue(), curlExec(), drupalGet(), SimpleTestCase::fail(), getAbsoluteUrl(), getUrl(), handleForm(), parse(), refreshVariables(), and t().

Referenced by drupalLogin().

Here is the call graph for this function:

DrupalWebTestCase::handleForm ( &$  post,
&$  edit,
&$  upload,
submit,
form 
) [protected]

Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manor for the particular field type.

Parameters:
array $post Reference to array of post values.
array $edit Reference to array of edit values to be checked against the form.
string $submit Form submit button value.
array $form Array of form elements.
Returns:
boolean Submit value matches a valid submit input in the form.

Definition at line 652 of file drupal_web_test_case.php.

References $elements, $name, $type, $value, and getAllOptions().

Referenced by drupalPost().

Here is the call graph for this function:

DrupalWebTestCase::getAllOptions ( SimpleXMLElement $  element  )  [private]

Get all option elements, including nested options, in a select.

Parameters:
SimpleXMLElement $element
Returns:
array Option elements in select.

Definition at line 772 of file drupal_web_test_case.php.

Referenced by handleForm().

DrupalWebTestCase::clickLink ( label,
index = 0 
)

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 normalized space. The label is translated label. There is an assert for successful click. WARNING: Assertion fails on empty ("") output from the clicked link.

Parameters:
string $label Text between the anchor tags.
integer $index Link position counting from zero.
boolean $reporting Assertions or not.
Returns:
boolean/string Page on success.

Definition at line 800 of file drupal_web_test_case.php.

References $curl_options, UnitTestCase::assertTrue(), curlExec(), getAbsoluteUrl(), getUrl(), parse(), and t().

Here is the call graph for this function:

DrupalWebTestCase::getAbsoluteUrl ( path  ) 

Takes a path and returns an absolute path.

Parameters:
@path The path, can be a Drupal path or a site-relative path. It might have a query, too. Can even be an absolute path which is just passed through.
Returns:
An absolute path.

Definition at line 824 of file drupal_web_test_case.php.

References base_path(), and url().

Referenced by clickLink(), and drupalPost().

Here is the call graph for this function:

DrupalWebTestCase::getUrl (  ) 

Get the current url from the cURL handler.

Returns:
string current url.

Definition at line 848 of file drupal_web_test_case.php.

Referenced by clickLink(), drupalPost(), and parse().

DrupalWebTestCase::drupalGetContent (  ) 

Gets the current raw HTML of requested page.

Definition at line 855 of file drupal_web_test_case.php.

Referenced by assertNoPattern(), and assertPattern().

DrupalWebTestCase::assertRaw ( raw,
message = "%s",
group = 'Other' 
)

Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.

Parameters:
string $raw Raw string to look for.
string $message Message to display.
Returns:
boolean TRUE on pass.

Definition at line 867 of file drupal_web_test_case.php.

References UnitTestCase::assertFalse().

Here is the call graph for this function:

DrupalWebTestCase::assertNoRaw ( raw,
message = "%s",
group = 'Other' 
)

Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.

Parameters:
string $raw Raw string to look for.
string $message Message to display.
Returns:
boolean TRUE on pass.

Definition at line 879 of file drupal_web_test_case.php.

References UnitTestCase::assertTrue().

Here is the call graph for this function:

DrupalWebTestCase::assertText ( text,
message = '',
group = 'Other' 
)

Pass if the text IS found on the text version of the page. The text version is the equivilent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.

Parameters:
string $raw Text string to look for.
string $message Message to display.
Returns:
boolean TRUE on pass.

Definition at line 892 of file drupal_web_test_case.php.

References assertTextHelper().

Referenced by drupalLogin().

Here is the call graph for this function:

DrupalWebTestCase::assertNoText ( text,
message = '',
group = 'Other' 
)

Pass if the text is NOT found on the text version of the page. The text version is the equivilent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.

Parameters:
string $raw Text string to look for.
string $message Message to display.
Returns:
boolean TRUE on pass.

Definition at line 905 of file drupal_web_test_case.php.

References assertTextHelper().

Referenced by drupalLogin().

Here is the call graph for this function:

DrupalWebTestCase::assertTextHelper ( text,
message,
group,
not_exists 
) [protected]

Filter out the HTML of the page and assert that the plain text us found. Called by the plain text assertions.

Parameters:
string $text Text to look for.
string $message Message to display.
boolean $not_exists The assert to make in relation to the text's existance.
Returns:
boolean Assertion result.

Definition at line 918 of file drupal_web_test_case.php.

References UnitTestCase::assertTrue().

Referenced by assertNoText(), and assertText().

Here is the call graph for this function:

DrupalWebTestCase::assertPattern ( pattern,
message = '%s',
group = 'Other' 
)

Will trigger a pass if the Perl regex pattern is found in the raw content.

Parameters:
string $pattern Perl regex to look for including the regex delimiters.
string $message Message to display.
Returns:
boolean True if pass.

Definition at line 935 of file drupal_web_test_case.php.

References UnitTestCase::assertTrue(), and drupalGetContent().

Here is the call graph for this function:

DrupalWebTestCase::assertNoPattern ( pattern,
message = '%s',
group = 'Other' 
)

Will trigger a pass if the perl regex pattern is not present in raw content.

Parameters:
string $pattern Perl regex to look for including the regex delimiters.
string $message Message to display.
Returns:
boolean True if pass.

Definition at line 946 of file drupal_web_test_case.php.

References UnitTestCase::assertFalse(), and drupalGetContent().

Here is the call graph for this function:

DrupalWebTestCase::assertTitle ( title,
message,
group = 'Other' 
)

Pass if the page title is the given string.

Parameters:
$title Text string to look for.
$message Message to display.
Returns:
boolean TRUE on pass.

Definition at line 957 of file drupal_web_test_case.php.

References $title, UnitTestCase::assertTrue(), and parse().

Here is the call graph for this function:

DrupalWebTestCase::assertFieldByXPath ( xpath,
value,
message,
group = 'Other' 
)

Assert that a field exists in the current page by the given XPath.

Parameters:
string $xpath XPath used to find the field.
string $value Value of the field to assert.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 969 of file drupal_web_test_case.php.

References $value, UnitTestCase::assertTrue(), and parse().

Referenced by assertField(), assertFieldById(), and assertFieldByName().

Here is the call graph for this function:

DrupalWebTestCase::assertNoFieldByXPath ( xpath,
value,
message,
group = 'Other' 
)

Assert that a field does not exists in the current page by the given XPath.

Parameters:
string $xpath XPath used to find the field.
string $value Value of the field to assert.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 996 of file drupal_web_test_case.php.

References $value, UnitTestCase::assertFalse(), and parse().

Referenced by assertNoField(), assertNoFieldById(), and assertNoFieldByName().

Here is the call graph for this function:

DrupalWebTestCase::assertFieldByName ( name,
value = '',
message = '' 
)

Assert that a field exists in the current page with the given name and value.

Parameters:
string $name Name of field to assert.
string $value Value of the field to assert.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1023 of file drupal_web_test_case.php.

References $name, $value, _constructFieldXpath(), assertFieldByXPath(), and t().

Here is the call graph for this function:

DrupalWebTestCase::assertNoFieldByName ( name,
value = '',
message = '' 
)

Assert that a field does not exists in the current page with the given name and value.

Parameters:
string $name Name of field to assert.
string $value Value of the field to assert.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1035 of file drupal_web_test_case.php.

References $name, $value, _constructFieldXpath(), assertNoFieldByXPath(), and t().

Here is the call graph for this function:

DrupalWebTestCase::assertFieldById ( id,
value = '',
message = '' 
)

Assert that a field exists in the current page with the given id and value.

Parameters:
string $id Id of field to assert.
string $value Value of the field to assert.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1047 of file drupal_web_test_case.php.

References $value, _constructFieldXpath(), assertFieldByXPath(), and t().

Here is the call graph for this function:

DrupalWebTestCase::assertNoFieldById ( id,
value = '',
message = '' 
)

Assert that a field does not exists in the current page with the given id and value.

Parameters:
string $id Id of field to assert.
string $value Value of the field to assert.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1059 of file drupal_web_test_case.php.

References $value, _constructFieldXpath(), assertNoFieldByXPath(), and t().

Here is the call graph for this function:

DrupalWebTestCase::assertField ( field,
message = '',
group = 'Other' 
)

Assert that a field exists in the current page with the given name or id.

Parameters:
string $field Name or id of the field.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1070 of file drupal_web_test_case.php.

References _constructFieldXpath(), and assertFieldByXPath().

Referenced by drupalLogout().

Here is the call graph for this function:

DrupalWebTestCase::assertNoField ( field,
message = '',
group = 'Other' 
)

Assert that a field does not exists in the current page with the given name or id.

Parameters:
string $field Name or id of the field.
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1081 of file drupal_web_test_case.php.

References _constructFieldXpath(), and assertNoFieldByXPath().

Here is the call graph for this function:

DrupalWebTestCase::_constructFieldXpath ( attribute,
value 
)

Construct an XPath for the given set of attributes and value.

Parameters:
array $attribute Field attributes.
string $value Value of field.
Returns:
string XPath for specified values.

Definition at line 1092 of file drupal_web_test_case.php.

References $value.

Referenced by assertField(), assertFieldById(), assertFieldByName(), assertNoField(), assertNoFieldById(), and assertNoFieldByName().

DrupalWebTestCase::assertResponse ( code,
message = '' 
)

Assert the page responds with the specified response code.

Parameters:
integer $code Reponse code. For example 200 is a successful page request. For a list of all codes see
string $message Message to display.
Returns:
boolean Assertion result.

Definition at line 1104 of file drupal_web_test_case.php.

References UnitTestCase::assertTrue(), and t().

Here is the call graph for this function:


Member Data Documentation

DrupalWebTestCase::$_logged_in = FALSE [protected]

Definition at line 8 of file drupal_web_test_case.php.

DrupalWebTestCase::$_content [protected]

Definition at line 9 of file drupal_web_test_case.php.

DrupalWebTestCase::$plain_text [protected]

Definition at line 10 of file drupal_web_test_case.php.

DrupalWebTestCase::$ch [protected]

Definition at line 11 of file drupal_web_test_case.php.

DrupalWebTestCase::$elements [protected]

Definition at line 12 of file drupal_web_test_case.php.

Referenced by handleForm().

DrupalWebTestCase::$_modules = array() [protected]

Definition at line 13 of file drupal_web_test_case.php.

DrupalWebTestCase::$cookie_file = NULL [protected]

Definition at line 16 of file drupal_web_test_case.php.

DrupalWebTestCase::$curl_options = array() [protected]

Definition at line 19 of file drupal_web_test_case.php.

Referenced by clickLink(), curlConnect(), and curlExec().

DrupalWebTestCase::$db_prefix_original [protected]

Definition at line 20 of file drupal_web_test_case.php.

DrupalWebTestCase::$original_file_directory [protected]

Definition at line 21 of file drupal_web_test_case.php.


The documentation for this class was generated from the following file:

Generated on Mon Jun 2 15:09:08 2008 for SimpleTest by  1.5.5