Public Member Functions | |
__construct ($test_id=NULL) | |
Constructor for DrupalWebTestCase. | |
run () | |
Run all tests in this class. | |
errorHandler ($severity, $message, $file=NULL, $line=NULL) | |
Handle errors. | |
drupalGetNodeByTitle ($title) | |
Get a node from the database based on its title. | |
Static Public Member Functions | |
static | randomName ($number=4, $prefix= 'simpletest_') |
Generates a random string. | |
Public Attributes | |
$results | |
Protected Member Functions | |
getAssertionCall () | |
Cycles through backtrace until the first non-assertion method is found. | |
assertTrue ($value, $message= '', $group= 'Other') | |
Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
assertFalse ($value, $message= '', $group= 'Other') | |
Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
assertNull ($value, $message= '', $group= 'Other') | |
Check to see if a value is NULL. | |
assertNotNull ($value, $message= '', $group= 'Other') | |
Check to see if a value is not NULL. | |
assertEqual ($first, $second, $message= '', $group= 'Other') | |
Check to see if two values are equal. | |
assertNotEqual ($first, $second, $message= '', $group= 'Other') | |
Check to see if two values are not equal. | |
assertIdentical ($first, $second, $message= '', $group= 'Other') | |
Check to see if two values are identical. | |
assertNotIdentical ($first, $second, $message= '', $group= 'Other') | |
Check to see if two values are not identical. | |
pass ($message=NULL, $group= 'Other') | |
Fire an assertion that is always positive. | |
fail ($message=NULL, $group= 'Other') | |
Fire an assertion that is always negative. | |
error ($message= '', $group= 'Other', array $caller=NULL) | |
Fire an error assertion. | |
exceptionHandler ($exception) | |
Handle exceptions. | |
drupalCreateNode ($settings=array()) | |
Creates a node based on default settings. | |
drupalCreateContentType ($settings=array()) | |
Creates a custom content type based on default settings. | |
drupalGetTestFiles ($type, $size=NULL) | |
Get a list files that can be used in tests. | |
drupalCompareFiles ($file1, $file2) | |
Compare two files based on size and file name. | |
drupalCreateUser ($permissions=NULL) | |
Create a user with a given set of permissions. | |
_drupalCreateRole (array $permissions=NULL) | |
Internal helper function; Create a role with specified permissions. | |
checkPermissions (array $permissions, $reset=FALSE) | |
Check to make sure that the array of permissions are valid. | |
drupalLogin (stdClass $user) | |
Log in a user with the internal browser. | |
drupalLogout () | |
setUp () | |
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. | |
preloadRegistry () | |
This method is called by DrupalWebTestCase::setUp, and preloads the registry from the testing site to cut down on the time it takes to setup a clean environment for the current test run. | |
refreshVariables () | |
Refresh the in-memory set of variables. | |
tearDown () | |
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. | |
curlInitialize () | |
Initializes the cURL connection. | |
curlExec ($curl_options) | |
Performs a cURL exec with the specified options after calling curlConnect(). | |
curlHeaderCallback ($curlHandler, $header) | |
Reads headers and registers errors received from the tested site. | |
curlClose () | |
Close the cURL handler and unset the handler. | |
parse () | |
Parse content returned from curlExec using DOM and SimpleXML. | |
drupalGet ($path, array $options=array(), array $headers=array()) | |
Retrieves a Drupal path or an absolute path. | |
drupalPost ($path, $edit, $submit, array $options=array(), array $headers=array()) | |
Execute a POST request on a Drupal page. | |
checkForMetaRefresh () | |
Check for meta refresh tag and if found call drupalGet() recursively. | |
drupalHead ($path, array $options=array(), array $headers=array()) | |
Retrieves only the headers for a Drupal path or an absolute path. | |
handleForm (&$post, &$edit, &$upload, $submit, $form) | |
Handle form input related to drupalPost(). | |
xpath ($xpath) | |
Perform an xpath search on the contents of the internal browser. | |
getAllOptions (SimpleXMLElement $element) | |
Get all option elements, including nested options, in a select. | |
assertLink ($label, $index=0, $message= '', $group= 'Other') | |
Pass if a link with the specified label is found, and optional with the specified index. | |
assertNoLink ($label, $message= '', $group= 'Other') | |
Pass if a link with the specified label is not found. | |
clickLink ($label, $index=0) | |
Follows a link by name. | |
getAbsoluteUrl ($path) | |
Takes a path and returns an absolute path. | |
getUrl () | |
Get the current url from the cURL handler. | |
drupalGetHeaders ($all_requests=FALSE) | |
Gets the HTTP response headers of the requested page. | |
drupalGetHeader ($name, $all_requests=FALSE) | |
Gets the value of an HTTP response header. | |
drupalGetContent () | |
Gets the current raw HTML of requested page. | |
drupalSetContent ($content, $url= 'internal:') | |
Sets the raw HTML content. | |
assertRaw ($raw, $message= '%s found', $group= 'Other') | |
Pass if the raw text IS found on the loaded page, fail otherwise. | |
assertNoRaw ($raw, $message= '%s found', $group= 'Other') | |
Pass if the raw text is NOT found on the loaded page, fail otherwise. | |
assertText ($text, $message= '', $group= 'Other') | |
Pass if the text IS found on the text version of the page. | |
assertNoText ($text, $message= '', $group= 'Other') | |
Pass if the text is NOT found on the text version of the page. | |
assertTextHelper ($text, $message, $group, $not_exists) | |
Helper for assertText and assertNoText. | |
assertUniqueText ($text, $message= '', $group= 'Other') | |
Pass if the text is found ONLY ONCE on the text version of the page. | |
assertNoUniqueText ($text, $message= '', $group= 'Other') | |
Pass if the text is found MORE THAN ONCE on the text version of the page. | |
assertUniqueTextHelper ($text, $message, $group, $be_unique) | |
Helper for assertUniqueText and assertNoUniqueText. | |
assertPattern ($pattern, $message= 'Pattern%s found', $group= 'Other') | |
Will trigger a pass if the Perl regex pattern is found in the raw content. | |
assertNoPattern ($pattern, $message= 'Pattern%s not found', $group= 'Other') | |
Will trigger a pass if the perl regex pattern is not present in raw content. | |
assertTitle ($title, $message, $group= 'Other') | |
Pass if the page title is the given string. | |
assertNoTitle ($title, $message, $group= 'Other') | |
Pass if the page title is not the given string. | |
assertFieldByXPath ($xpath, $value, $message, $group= 'Other') | |
Assert that a field exists in the current page by the given XPath. | |
getSelectedItem (SimpleXMLElement $element) | |
Get the selected value from a select field. | |
assertNoFieldByXPath ($xpath, $value, $message, $group= 'Other') | |
Assert that a field does not exist in the current page by the given XPath. | |
assertFieldByName ($name, $value= '', $message= '') | |
Assert that a field exists in the current page with the given name and value. | |
assertNoFieldByName ($name, $value= '', $message= '') | |
Assert that a field does not exist with the given name and value. | |
assertFieldById ($id, $value= '', $message= '') | |
Assert that a field exists in the current page with the given id and value. | |
assertNoFieldById ($id, $value= '', $message= '') | |
Assert that a field does not exist with the given id and value. | |
assertField ($field, $message= '', $group= 'Other') | |
Assert that a field exists with the given name or id. | |
assertNoField ($field, $message= '', $group= 'Other') | |
Assert that a field does not exist with the given name or id. | |
constructFieldXpath ($attribute, $value) | |
Helper function: construct an XPath for the given set of attributes and value. | |
assertResponse ($code, $message= '') | |
Assert the page responds with the specified response code. | |
Protected Attributes | |
$testId | |
$url | |
$curlHandle | |
$headers | |
$content | |
$plainTextContent | |
$elements = NULL | |
$loggedInUser = FALSE | |
$cookieFile = NULL | |
The current cookie file used by cURL. | |
$additionalCurlOptions = array() | |
Additional cURL options. | |
$originalPrefix = NULL | |
$originalFileDirectory = NULL | |
$originalUser = NULL | |
$assertions = array() | |
$timeLimit = 180 | |
Time limit for the test. |
Definition at line 17 of file drupal_web_test_case.php.
DrupalWebTestCase::__construct | ( | $ | test_id = NULL |
) |
Constructor for DrupalWebTestCase.
$test_id | Tests with the same id are reported together. |
Definition at line 141 of file drupal_web_test_case.php.
References $test_id.
00141 { 00142 $this->testId = $test_id; 00143 }
DrupalWebTestCase::_drupalCreateRole | ( | array $ | permissions = NULL |
) | [protected] |
Internal helper function; Create a role with specified permissions.
$permissions | Array of permission names to assign to role. |
Definition at line 720 of file drupal_web_test_case.php.
References assertTrue(), checkPermissions(), and randomName().
00720 { 00721 // Generate string version of permissions list. 00722 if ($permissions === NULL) { 00723 $permissions = array('access comments', 'access content', 'post comments', 'post comments without approval'); 00724 } 00725 00726 if (!$this->checkPermissions($permissions)) { 00727 return FALSE; 00728 } 00729 00730 // Create new role. 00731 $role_name = $this->randomName(); 00732 db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name); 00733 $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = '%s'", $role_name)); 00734 $this->assertTrue($role, t('Created role of name: @role_name, id: @rid', array('@role_name' => $role_name, '@rid' => (isset($role->rid) ? $role->rid : t('-n/a-')))), t('Role')); 00735 if ($role && !empty($role->rid)) { 00736 // // Assign permissions to role and mark it for clean-up. 00737 // foreach ($permissions as $permission_string) { 00738 // db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", $role->rid, $permission_string); 00739 // } 00740 // $count = db_result(db_query("SELECT COUNT(*) FROM {role_permission} WHERE rid = %d", $role->rid)); 00741 // $this->assertTrue($count == count($permissions), t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role')); 00742 // return $role->rid; 00743 00744 // Assign permissions to role and mark it for clean-up. 00745 db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', $permissions)); 00746 $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", $role->rid)); 00747 $this->assertTrue(count(explode(', ', $perm)) == count($permissions), t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role')); 00748 return $role->rid; 00749 } 00750 else { 00751 return FALSE; 00752 } 00753 }
DrupalWebTestCase::assertEqual | ( | $ | first, | |
$ | second, | |||
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if two values are equal.
$first | The first value to check. | |
$second | The second value to check. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 305 of file drupal_web_test_case.php.
00305 { 00306 return $this->assert($first == $second, $message ? $message : t('First value is equal to second value'), $group); 00307 }
DrupalWebTestCase::assertFalse | ( | $ | value, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if a value is false (an empty string, 0, NULL, or FALSE).
$value | The value on which the assertion is to be done. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 255 of file drupal_web_test_case.php.
00255 { 00256 return $this->assert(!$value, $message ? $message : t('Value is FALSE'), $group); 00257 }
DrupalWebTestCase::assertField | ( | $ | field, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Assert that a field exists with the given name or id.
$field | Name or id of field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2108 of file drupal_web_test_case.php.
References assertFieldByXPath(), and constructFieldXpath().
02108 { 02109 return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), '', $message, $group); 02110 }
DrupalWebTestCase::assertFieldById | ( | $ | id, | |
$ | value = '' , |
|||
$ | message = '' | |||
) | [protected] |
Assert that a field exists in the current page with the given id and value.
$id | Id of field to assert. | |
$value | Value of the field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2074 of file drupal_web_test_case.php.
References assertFieldByXPath(), and constructFieldXpath().
02074 { 02075 return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), t('Browser')); 02076 }
DrupalWebTestCase::assertFieldByName | ( | $ | name, | |
$ | value = '' , |
|||
$ | message = '' | |||
) | [protected] |
Assert that a field exists in the current page with the given name and value.
$name | Name of field to assert. | |
$value | Value of the field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2038 of file drupal_web_test_case.php.
References assertFieldByXPath(), and constructFieldXpath().
02038 { 02039 return $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Found field by name @name', array('@name' => $name)), t('Browser')); 02040 }
DrupalWebTestCase::assertFieldByXPath | ( | $ | xpath, | |
$ | value, | |||
$ | message, | |||
$ | group = 'Other' | |||
) | [protected] |
Assert that a field exists in the current page by the given XPath.
$xpath | XPath used to find the field. | |
$value | Value of the field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 1934 of file drupal_web_test_case.php.
References assertTrue(), getAllOptions(), getSelectedItem(), and xpath().
01934 { 01935 $fields = $this->xpath($xpath); 01936 01937 // If value specified then check array for match. 01938 $found = TRUE; 01939 if ($value) { 01940 $found = FALSE; 01941 if ($fields) { 01942 foreach ($fields as $field) { 01943 if (isset($field['value']) && $field['value'] == $value) { 01944 // Input element with correct value. 01945 $found = TRUE; 01946 } 01947 elseif (isset($field->option)) { 01948 // Select element found. 01949 if ($this->getSelectedItem($field) == $value) { 01950 $found = TRUE; 01951 } 01952 else { 01953 // No item selected so use first item. 01954 $items = $this->getAllOptions($field); 01955 if (!empty($items) && $items[0]['value'] == $value) { 01956 $found = TRUE; 01957 } 01958 } 01959 } 01960 elseif ((string) $field == $value) { 01961 // Text area with correct text. 01962 $found = TRUE; 01963 } 01964 } 01965 } 01966 } 01967 return $this->assertTrue($fields && $found, $message, $group); 01968 }
DrupalWebTestCase::assertIdentical | ( | $ | first, | |
$ | second, | |||
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if two values are identical.
$first | The first value to check. | |
$second | The second value to check. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 341 of file drupal_web_test_case.php.
00341 { 00342 return $this->assert($first === $second, $message ? $message : t('First value is identical to second value'), $group); 00343 }
DrupalWebTestCase::assertLink | ( | $ | label, | |
$ | index = 0 , |
|||
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if a link with the specified label is found, and optional with the specified index.
$label | Text between the anchor tags. | |
$index | Link position counting from zero. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1486 of file drupal_web_test_case.php.
References xpath().
01486 { 01487 $links = $this->xpath('//a[text()="' . $label . '"]'); 01488 $message = ($message ? $message : t('Link with label "!label" found.', array('!label' => $label))); 01489 $this->assert(isset($links[$index]), $message, $group); 01490 }
DrupalWebTestCase::assertNoField | ( | $ | field, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Assert that a field does not exist with the given name or id.
$field | Name or id of field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2124 of file drupal_web_test_case.php.
References assertNoFieldByXPath(), and constructFieldXpath().
02124 { 02125 return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), '', $message, $group); 02126 }
DrupalWebTestCase::assertNoFieldById | ( | $ | id, | |
$ | value = '' , |
|||
$ | message = '' | |||
) | [protected] |
Assert that a field does not exist with the given id and value.
$id | Id of field to assert. | |
$value | Value of the field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2092 of file drupal_web_test_case.php.
References assertNoFieldByXPath(), and constructFieldXpath().
02092 { 02093 return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), t('Browser')); 02094 }
DrupalWebTestCase::assertNoFieldByName | ( | $ | name, | |
$ | value = '' , |
|||
$ | message = '' | |||
) | [protected] |
Assert that a field does not exist with the given name and value.
$name | Name of field to assert. | |
$value | Value of the field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2056 of file drupal_web_test_case.php.
References assertNoFieldByXPath(), and constructFieldXpath().
02056 { 02057 return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), t('Browser')); 02058 }
DrupalWebTestCase::assertNoFieldByXPath | ( | $ | xpath, | |
$ | value, | |||
$ | message, | |||
$ | group = 'Other' | |||
) | [protected] |
Assert that a field does not exist in the current page by the given XPath.
$xpath | XPath used to find the field. | |
$value | Value of the field to assert. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 2006 of file drupal_web_test_case.php.
References assertFalse(), and xpath().
02006 { 02007 $fields = $this->xpath($xpath); 02008 02009 // If value specified then check array for match. 02010 $found = TRUE; 02011 if ($value) { 02012 $found = FALSE; 02013 if ($fields) { 02014 foreach ($fields as $field) { 02015 if ($field['value'] == $value) { 02016 $found = TRUE; 02017 } 02018 } 02019 } 02020 } 02021 return $this->assertFalse($fields && $found, $message, $group); 02022 }
DrupalWebTestCase::assertNoLink | ( | $ | label, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if a link with the specified label is not found.
$label | Text between the anchor tags. | |
$index | Link position counting from zero. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1504 of file drupal_web_test_case.php.
References xpath().
01504 { 01505 $links = $this->xpath('//a[text()="' . $label . '"]'); 01506 $message = ($message ? $message : t('Link with label "!label" not found.', array('!label' => $label))); 01507 $this->assert(empty($links), $message, $group); 01508 }
DrupalWebTestCase::assertNoPattern | ( | $ | pattern, | |
$ | message = 'Pattern %s not found' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Will trigger a pass if the perl regex pattern is not present in raw content.
$pattern | Perl regex to look for including the regex delimiters. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 1884 of file drupal_web_test_case.php.
References drupalGetContent().
01884 { 01885 return $this->assert(!preg_match($pattern, $this->drupalGetContent()), $message, $group); 01886 }
DrupalWebTestCase::assertNoRaw | ( | $ | raw, | |
$ | message = '%s found' , |
|||
$ | group = 'Other' | |||
) | [protected] |
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.
$raw | Raw (HTML) string to look for. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1718 of file drupal_web_test_case.php.
01718 { 01719 return $this->assert(strpos($this->content, $raw) === FALSE, $message, $group); 01720 }
DrupalWebTestCase::assertNotEqual | ( | $ | first, | |
$ | second, | |||
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if two values are not equal.
$first | The first value to check. | |
$second | The second value to check. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 323 of file drupal_web_test_case.php.
00323 { 00324 return $this->assert($first != $second, $message ? $message : t('First value is not equal to second value'), $group); 00325 }
DrupalWebTestCase::assertNoText | ( | $ | text, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if the text is NOT found on the text version of the page.
The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
$text | Plain text to look for. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1754 of file drupal_web_test_case.php.
References assertTextHelper().
01754 { 01755 return $this->assertTextHelper($text, $message, $group, TRUE); 01756 }
DrupalWebTestCase::assertNotIdentical | ( | $ | first, | |
$ | second, | |||
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if two values are not identical.
$first | The first value to check. | |
$second | The second value to check. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 359 of file drupal_web_test_case.php.
00359 { 00360 return $this->assert($first !== $second, $message ? $message : t('First value is not identical to second value'), $group); 00361 }
DrupalWebTestCase::assertNoTitle | ( | $ | title, | |
$ | message, | |||
$ | group = 'Other' | |||
) | [protected] |
Pass if the page title is not the given string.
$title | The string the title should not be. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 1916 of file drupal_web_test_case.php.
References assertNotEqual(), and xpath().
01916 { 01917 return $this->assertNotEqual(current($this->xpath('//title')), $title, $message, $group); 01918 }
DrupalWebTestCase::assertNotNull | ( | $ | value, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if a value is not NULL.
$value | The value on which the assertion is to be done. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 287 of file drupal_web_test_case.php.
00287 { 00288 return $this->assert(isset($value), $message ? $message : t('Value is not NULL'), $group); 00289 }
DrupalWebTestCase::assertNoUniqueText | ( | $ | text, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if the text is found MORE THAN ONCE on the text version of the page.
The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
$text | Plain text to look for. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1820 of file drupal_web_test_case.php.
References assertUniqueTextHelper().
01820 { 01821 return $this->assertUniqueTextHelper($text, $message, $group, FALSE); 01822 }
DrupalWebTestCase::assertNull | ( | $ | value, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if a value is NULL.
$value | The value on which the assertion is to be done. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 271 of file drupal_web_test_case.php.
00271 { 00272 return $this->assert(!isset($value), $message ? $message : t('Value is NULL'), $group); 00273 }
DrupalWebTestCase::assertPattern | ( | $ | pattern, | |
$ | message = 'Pattern %s found' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Will trigger a pass if the Perl regex pattern is found in the raw content.
$pattern | Perl regex to look for including the regex delimiters. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 1868 of file drupal_web_test_case.php.
References drupalGetContent().
01868 { 01869 return $this->assert((bool) preg_match($pattern, $this->drupalGetContent()), $message, $group); 01870 }
DrupalWebTestCase::assertRaw | ( | $ | raw, | |
$ | message = '%s found' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if the raw text IS found on the loaded page, fail otherwise.
Raw text refers to the raw HTML that the page generated.
$raw | Raw (HTML) string to look for. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1701 of file drupal_web_test_case.php.
01701 { 01702 return $this->assert(strpos($this->content, $raw) !== FALSE, $message, $group); 01703 }
DrupalWebTestCase::assertResponse | ( | $ | code, | |
$ | message = '' | |||
) | [protected] |
Assert the page responds with the specified response code.
$code | Response code. For example 200 is a successful page request. For a list of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. | |
$message | Message to display. |
Definition at line 2153 of file drupal_web_test_case.php.
References assertTrue().
02153 { 02154 $curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE); 02155 $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code; 02156 return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser')); 02157 }
DrupalWebTestCase::assertText | ( | $ | text, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if the text IS found on the text version of the page.
The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
$text | Plain text to look for. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1736 of file drupal_web_test_case.php.
References assertTextHelper().
01736 { 01737 return $this->assertTextHelper($text, $message, $group, FALSE); 01738 }
DrupalWebTestCase::assertTextHelper | ( | $ | text, | |
$ | message, | |||
$ | group, | |||
$ | not_exists | |||
) | [protected] |
Helper for assertText and assertNoText.
It is not recommended to call this function directly.
$text | Plain text to look for. | |
$message | Message to display. | |
$group | The group this message belongs to. | |
$not_exists | TRUE if this text should not exist, FALSE if it should. |
Definition at line 1774 of file drupal_web_test_case.php.
01774 { 01775 if ($this->plainTextContent === FALSE) { 01776 $this->plainTextContent = filter_xss($this->content, array()); 01777 } 01778 if (!$message) { 01779 $message = '"' . $text . '"' . ($not_exists ? ' not found' : ' found'); 01780 } 01781 return $this->assert($not_exists == (strpos($this->plainTextContent, $text) === FALSE), $message, $group); 01782 }
DrupalWebTestCase::assertTitle | ( | $ | title, | |
$ | message, | |||
$ | group = 'Other' | |||
) | [protected] |
Pass if the page title is the given string.
$title | The string the title should be. | |
$message | Message to display. | |
$group | The group this message belongs to. |
Definition at line 1900 of file drupal_web_test_case.php.
References assertEqual(), and xpath().
01900 { 01901 return $this->assertEqual(current($this->xpath('//title')), $title, $message, $group); 01902 }
DrupalWebTestCase::assertTrue | ( | $ | value, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
$value | The value on which the assertion is to be done. | |
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 239 of file drupal_web_test_case.php.
00239 { 00240 return $this->assert((bool) $value, $message ? $message : t('Value is TRUE'), $group); 00241 }
DrupalWebTestCase::assertUniqueText | ( | $ | text, | |
$ | message = '' , |
|||
$ | group = 'Other' | |||
) | [protected] |
Pass if the text is found ONLY ONCE on the text version of the page.
The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
$text | Plain text to look for. | |
$message | Message to display. | |
$group | The group this message belongs to, defaults to 'Other'. |
Definition at line 1800 of file drupal_web_test_case.php.
References assertUniqueTextHelper().
01800 { 01801 return $this->assertUniqueTextHelper($text, $message, $group, TRUE); 01802 }
DrupalWebTestCase::assertUniqueTextHelper | ( | $ | text, | |
$ | message, | |||
$ | group, | |||
$ | be_unique | |||
) | [protected] |
Helper for assertUniqueText and assertNoUniqueText.
It is not recommended to call this function directly.
$text | Plain text to look for. | |
$message | Message to display. | |
$group | The group this message belongs to. | |
$be_unique | TRUE if this text should be found only once, FALSE if it should be found more than once. |
Definition at line 1840 of file drupal_web_test_case.php.
01840 { 01841 if ($this->plainTextContent === FALSE) { 01842 $this->plainTextContent = filter_xss($this->content, array()); 01843 } 01844 if (!$message) { 01845 $message = '"' . $text . '"'. ($be_unique ? ' found only once' : ' found more than once'); 01846 } 01847 $first_occurance = strpos($this->plainTextContent, $text); 01848 if ($first_occurance === FALSE) { 01849 return $this->assert(FALSE, $message, $group); 01850 } 01851 $offset = $first_occurance + strlen($text); 01852 $second_occurance = strpos($this->plainTextContent, $text, $offset); 01853 return $this->assert($be_unique == ($second_occurance === FALSE), $message, $group); 01854 }
DrupalWebTestCase::checkForMetaRefresh | ( | ) | [protected] |
Check for meta refresh tag and if found call drupalGet() recursively.
This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
Definition at line 1267 of file drupal_web_test_case.php.
References drupalGet(), drupalGetContent(), getAbsoluteUrl(), parse(), and xpath().
01267 { 01268 if ($this->drupalGetContent() != '' && $this->parse()) { 01269 $refresh = $this->xpath('//meta[@http-equiv="Refresh"]'); 01270 if (!empty($refresh)) { 01271 // Parse the content attribute of the meta tag for the format: 01272 // "[delay]: URL=[page_to_redirect_to]". 01273 if (preg_match('/\d+;\s*URL=(?P<url>.*)/i', $refresh[0]['content'], $match)) { 01274 return $this->drupalGet($this->getAbsoluteUrl(decode_entities($match['url']))); 01275 } 01276 } 01277 } 01278 return FALSE; 01279 }
DrupalWebTestCase::checkPermissions | ( | array $ | permissions, | |
$ | reset = FALSE | |||
) | [protected] |
Check to make sure that the array of permissions are valid.
$permissions | Permissions to check. | |
$reset | Reset cached available permissions. |
Definition at line 765 of file drupal_web_test_case.php.
References fail().
00765 { 00766 static $available; 00767 00768 if (!isset($available) || $reset) { 00769 // $available = array_keys(module_invoke_all('perm')); 00770 $available = module_invoke_all('perm'); 00771 } 00772 00773 $valid = TRUE; 00774 foreach ($permissions as $permission) { 00775 if (!in_array($permission, $available)) { 00776 $this->fail(t('Invalid permission %permission.', array('%permission' => $permission)), t('Role')); 00777 $valid = FALSE; 00778 } 00779 } 00780 return $valid; 00781 }
DrupalWebTestCase::clickLink | ( | $ | label, | |
$ | index = 0 | |||
) | [protected] |
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.
$label | Text between the anchor tags. | |
$index | Link position counting from zero. |
Definition at line 1525 of file drupal_web_test_case.php.
References assertTrue(), drupalGet(), getAbsoluteUrl(), getUrl(), and xpath().
01525 { 01526 $url_before = $this->getUrl(); 01527 $urls = $this->xpath('//a[text()="' . $label . '"]'); 01528 01529 if (isset($urls[$index])) { 01530 $url_target = $this->getAbsoluteUrl($urls[$index]['href']); 01531 } 01532 01533 $this->assertTrue(isset($urls[$index]), t('Clicked link "!label" (!url_target) from !url_before', array('!label' => $label, '!url_target' => $url_target, '!url_before' => $url_before)), t('Browser')); 01534 01535 if (isset($urls[$index])) { 01536 return $this->drupalGet($url_target); 01537 } 01538 return FALSE; 01539 }
DrupalWebTestCase::constructFieldXpath | ( | $ | attribute, | |
$ | value | |||
) | [protected] |
Helper function: construct an XPath for the given set of attributes and value.
$attribute | Field attributes. | |
$value | Value of field. |
Definition at line 2138 of file drupal_web_test_case.php.
02138 { 02139 return '//textarea[@' . $attribute . '="' . $value . '"]|//input[@' . $attribute . '="' . $value . '"]|//select[@' . $attribute . '="' . $value . '"]'; 02140 }
DrupalWebTestCase::curlClose | ( | ) | [protected] |
Close the cURL handler and unset the handler.
Definition at line 1103 of file drupal_web_test_case.php.
01103 { 01104 if (isset($this->curlHandle)) { 01105 curl_close($this->curlHandle); 01106 unset($this->curlHandle); 01107 } 01108 }
DrupalWebTestCase::curlExec | ( | $ | curl_options | ) | [protected] |
Performs a cURL exec with the specified options after calling curlConnect().
$curl_options | Custom cURL options. |
Definition at line 1052 of file drupal_web_test_case.php.
References $url, assertTrue(), curlInitialize(), drupalGetContent(), and drupalSetContent().
01052 { 01053 $this->curlInitialize(); 01054 $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL]; 01055 if (!empty($curl_options[CURLOPT_POST])) { 01056 // This is a fix for the Curl library to prevent Expect: 100-continue 01057 // headers in POST requests, that may cause unexpected HTTP response 01058 // codes from some webservers (like lighttpd that returns a 417 error 01059 // code). It is done by setting an empty "Expect" header field that is 01060 // not overwritten by Curl. 01061 $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:'; 01062 } 01063 curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options); 01064 $this->headers = array(); 01065 $this->drupalSetContent(curl_exec($this->curlHandle), curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL)); 01066 $message_vars = array( 01067 '!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), 01068 '@url' => $url, 01069 '@status' => curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE), 01070 '!length' => format_size(strlen($this->content)) 01071 ); 01072 $message = t('!method @url returned @status (!length).', $message_vars); 01073 $this->assertTrue($this->content !== FALSE, $message, t('Browser')); 01074 return $this->drupalGetContent(); 01075 }
DrupalWebTestCase::curlHeaderCallback | ( | $ | curlHandler, | |
$ | header | |||
) | [protected] |
Reads headers and registers errors received from the tested site.
$curlHandler | The cURL handler. | |
$header | An header. |
Definition at line 1087 of file drupal_web_test_case.php.
01087 { 01088 $this->headers[] = $header; 01089 // Errors are being sent via X-Drupal-Assertion-* headers, 01090 // generated by _drupal_log_error() in the exact form required 01091 // by DrupalWebTestCase::error(). 01092 if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) { 01093 // Call DrupalWebTestCase::error() with the parameters from the header. 01094 call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1]))); 01095 } 01096 // This is required by cURL. 01097 return strlen($header); 01098 }
DrupalWebTestCase::curlInitialize | ( | ) | [protected] |
Initializes the cURL connection.
This function will add authentication headers as specified in the simpletest_httpauth_username and simpletest_httpauth_pass variables. Also, see the description of $curl_options among the properties.
Definition at line 1017 of file drupal_web_test_case.php.
01017 { 01018 global $base_url, $db_prefix; 01019 if (!isset($this->curlHandle)) { 01020 $this->curlHandle = curl_init(); 01021 $curl_options = $this->additionalCurlOptions + array( 01022 CURLOPT_COOKIEJAR => $this->cookieFile, 01023 CURLOPT_URL => $base_url, 01024 CURLOPT_FOLLOWLOCATION => TRUE, 01025 CURLOPT_MAXREDIRS => 5, 01026 CURLOPT_RETURNTRANSFER => TRUE, 01027 CURLOPT_SSL_VERIFYPEER => FALSE, // Required to make the tests run on https:// 01028 CURLOPT_SSL_VERIFYHOST => FALSE, // Required to make the tests run on https:// 01029 CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'), 01030 ); 01031 if (preg_match('/simpletest\d+/', $db_prefix, $matches)) { 01032 $curl_options[CURLOPT_USERAGENT] = $matches[0]; 01033 } 01034 if (!isset($curl_options[CURLOPT_USERPWD]) && ($auth = variable_get('simpletest_httpauth_username', ''))) { 01035 if ($pass = variable_get('simpletest_httpauth_pass', '')) { 01036 $auth .= ':' . $pass; 01037 } 01038 $curl_options[CURLOPT_USERPWD] = $auth; 01039 } 01040 curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options); 01041 } 01042 }
DrupalWebTestCase::drupalCompareFiles | ( | $ | file1, | |
$ | file2 | |||
) | [protected] |
Compare two files based on size and file name.
Definition at line 642 of file drupal_web_test_case.php.
00642 { 00643 // $compare_size = filesize($file1->filepath) - filesize($file2->filepath); 00644 $compare_size = filesize($file1->filename) - filesize($file2->filename); 00645 if ($compare_size) { 00646 // Sort by file size. 00647 return $compare_size; 00648 } 00649 else { 00650 // The files were the same size, so sort alphabetically. 00651 return strnatcmp($file1->name, $file2->name); 00652 } 00653 }
DrupalWebTestCase::drupalCreateContentType | ( | $ | settings = array() |
) | [protected] |
Creates a custom content type based on default settings.
$settings | An array of settings to change from the defaults. Example: 'type' => 'foo'. |
Definition at line 561 of file drupal_web_test_case.php.
References assertEqual(), checkPermissions(), and randomName().
00561 { 00562 // find a non-existent random type name. 00563 do { 00564 $name = strtolower($this->randomName(3, 'type_')); 00565 } while (node_get_types('type', $name)); 00566 00567 // Populate defaults array 00568 $defaults = array( 00569 'type' => $name, 00570 'name' => $name, 00571 'description' => '', 00572 'help' => '', 00573 'min_word_count' => 0, 00574 'title_label' => 'Title', 00575 'body_label' => 'Body', 00576 'has_title' => 1, 00577 'has_body' => 1, 00578 ); 00579 // imposed values for a custom type 00580 $forced = array( 00581 'orig_type' => '', 00582 'old_type' => '', 00583 'module' => 'node', 00584 'custom' => 1, 00585 'modified' => 1, 00586 'locked' => 0, 00587 ); 00588 $type = $forced + $settings + $defaults; 00589 $type = (object)$type; 00590 00591 $saved_type = node_type_save($type); 00592 node_types_rebuild(); 00593 menu_rebuild(); // Drupal 6. 00594 00595 $this->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array('%type' => $type->type))); 00596 00597 // Reset permissions so that permissions for this content type are available. 00598 $this->checkPermissions(array(), TRUE); 00599 00600 return $type; 00601 }
DrupalWebTestCase::drupalCreateNode | ( | $ | settings = array() |
) | [protected] |
Creates a node based on default settings.
$settings | An associative array of settings to change from the defaults, keys are node properties, for example 'body' => 'Hello, world!'. |
Definition at line 501 of file drupal_web_test_case.php.
References randomName().
00501 { 00502 // Populate defaults array 00503 $settings += array( 00504 'body' => $this->randomName(32), 00505 'title' => $this->randomName(8), 00506 'comment' => 2, 00507 // 'changed' => REQUEST_TIME, 00508 'changed' => time(), 00509 'format' => FILTER_FORMAT_DEFAULT, 00510 'moderate' => 0, 00511 'promote' => 0, 00512 'revision' => 1, 00513 'log' => '', 00514 'status' => 1, 00515 'sticky' => 0, 00516 'type' => 'page', 00517 'revisions' => NULL, 00518 'taxonomy' => NULL, 00519 ); 00520 00521 // Use the original node's created time for existing nodes. 00522 if (isset($settings['created']) && !isset($settings['date'])) { 00523 $settings['date'] = format_date($settings['created'], 'custom', 'Y-m-d H:i:s O'); 00524 } 00525 00526 // Add the default teaser. 00527 if (!isset($settings['teaser'])) { 00528 $settings['teaser'] = $settings['body']; 00529 } 00530 00531 // If the node's user uid is not specified manually, use the currently 00532 // logged in user if available, or else the user running the test. 00533 if (!isset($settings['uid'])) { 00534 if ($this->loggedInUser) { 00535 $settings['uid'] = $this->loggedInUser->uid; 00536 } 00537 else { 00538 global $user; 00539 $settings['uid'] = $user->uid; 00540 } 00541 } 00542 00543 $node = (object) $settings; 00544 node_save($node); 00545 00546 // small hack to link revisions to our test user 00547 // db_query('UPDATE {node_revision} SET uid = %d WHERE vid = %d', $node->uid, $node->vid); 00548 db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid); 00549 return $node; 00550 }
DrupalWebTestCase::drupalCreateUser | ( | $ | permissions = NULL |
) | [protected] |
Create a user with a given set of permissions.
The permissions correspond to the names given on the privileges page.
$permissions | Array of permission names to assign to user. |
Definition at line 686 of file drupal_web_test_case.php.
References _drupalCreateRole(), assertTrue(), and randomName().
00686 { 00687 // Create a role with the given permission set. 00688 if (!($rid = $this->_drupalCreateRole($permissions))) { 00689 return FALSE; 00690 } 00691 00692 // Create a user assigned to that role. 00693 $edit = array(); 00694 $edit['name'] = $this->randomName(); 00695 $edit['mail'] = $edit['name'] . '@example.com'; 00696 $edit['roles'] = array($rid => $rid); 00697 $edit['pass'] = user_password(); 00698 $edit['status'] = 1; 00699 00700 $account = user_save('', $edit); 00701 00702 $this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login')); 00703 if (empty($account->uid)) { 00704 return FALSE; 00705 } 00706 00707 // Add the raw password so that we can log in as this user. 00708 $account->pass_raw = $edit['pass']; 00709 return $account; 00710 }
DrupalWebTestCase::drupalGet | ( | $ | path, | |
array $ | options = array() , |
|||
array $ | headers = array() | |||
) | [protected] |
Retrieves a Drupal path or an absolute path.
$path | Drupal path or URL to load into internal browser | |
$options | Options to be forwarded to url(). | |
$headers | An array containing additional HTTP request headers, each formatted as "name: value". |
Definition at line 1148 of file drupal_web_test_case.php.
References $headers, checkForMetaRefresh(), curlExec(), and refreshVariables().
01148 { 01149 $options['absolute'] = TRUE; 01150 01151 // We re-using a CURL connection here. If that connection still has certain 01152 // options set, it might change the GET into a POST. Make sure we clear out 01153 // previous options. 01154 $out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers)); 01155 $this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up. 01156 01157 // Replace original page output with new output from redirected page(s). 01158 if (($new = $this->checkForMetaRefresh())) { 01159 $out = $new; 01160 } 01161 return $out; 01162 }
DrupalWebTestCase::drupalGetContent | ( | ) | [protected] |
Gets the current raw HTML of requested page.
Definition at line 1668 of file drupal_web_test_case.php.
DrupalWebTestCase::drupalGetHeader | ( | $ | name, | |
$ | all_requests = FALSE | |||
) | [protected] |
Gets the value of an HTTP response header.
If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed from last to first until the header is found.
$name | The name of the header to retrieve. Names are case-insensitive (see RFC 2616 section 4.2). | |
$all_requests | Boolean value specifying whether to check all requests if the header is not found in the last request. Defaults to FALSE. |
Definition at line 1645 of file drupal_web_test_case.php.
References $headers, and drupalGetHeaders().
01645 { 01646 $name = strtolower($name); 01647 $header = FALSE; 01648 if ($all_requests) { 01649 foreach (array_reverse($this->drupalGetHeaders(TRUE)) as $headers) { 01650 if (isset($headers[$name])) { 01651 $header = $headers[$name]; 01652 break; 01653 } 01654 } 01655 } 01656 else { 01657 $headers = $this->drupalGetHeaders(); 01658 if (isset($headers[$name])) { 01659 $header = $headers[$name]; 01660 } 01661 } 01662 return $header; 01663 }
DrupalWebTestCase::drupalGetHeaders | ( | $ | all_requests = FALSE |
) | [protected] |
Gets the HTTP response headers of the requested page.
Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the page. Headers from all requests may be requested by passing TRUE to this function.
$all_requests | Boolean value specifying whether to return headers from all requests instead of just the last request. Defaults to FALSE. |
Values for duplicate headers are stored as a single comma-separated list.
Definition at line 1598 of file drupal_web_test_case.php.
References $headers.
01598 { 01599 $request = 0; 01600 $headers = array($request => array()); 01601 foreach ($this->headers as $header) { 01602 $header = trim($header); 01603 if ($header === '') { 01604 $request++; 01605 } 01606 else { 01607 if (strpos($header, 'HTTP/') === 0) { 01608 $name = ':status'; 01609 $value = $header; 01610 } 01611 else { 01612 list($name, $value) = explode(':', $header, 2); 01613 $name = strtolower($name); 01614 } 01615 if (isset($headers[$request][$name])) { 01616 $headers[$request][$name] .= ',' . trim($value); 01617 } 01618 else { 01619 $headers[$request][$name] = trim($value); 01620 } 01621 } 01622 } 01623 if (!$all_requests) { 01624 $headers = array_pop($headers); 01625 } 01626 return $headers; 01627 }
DrupalWebTestCase::drupalGetNodeByTitle | ( | $ | title | ) |
Get a node from the database based on its title.
title | A node title, usually generated by $this->randomName(). |
Definition at line 484 of file drupal_web_test_case.php.
00484 { 00485 // $nodes = node_load_multiple(array(), array('title' => $title)); 00486 // // Load the first node returned from the database. 00487 // $returned_node = reset($nodes); 00488 // return $returned_node; 00489 return node_load(array('title' => $title)); 00490 }
DrupalWebTestCase::drupalGetTestFiles | ( | $ | type, | |
$ | size = NULL | |||
) | [protected] |
Get a list files that can be used in tests.
$type | File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'. | |
$size | File size in bytes to match. Please check the tests/files folder. |
Definition at line 613 of file drupal_web_test_case.php.
00613 { 00614 $files = array(); 00615 00616 // Make sure type is valid. 00617 if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) { 00618 // Use original file directory instead of one created during setUp(). 00619 $path = $this->originalFileDirectory . '/simpletest'; 00620 // $files = file_scan_directory($path, '/' . $type . '\-.*/'); 00621 $files = file_scan_directory($path, '' . $type . '\-.*'); 00622 00623 // If size is set then remove any files that are not of that size. 00624 if ($size !== NULL) { 00625 foreach ($files as $file) { 00626 // $stats = stat($file->filepath); 00627 $stats = stat($file->filename); 00628 if ($stats['size'] != $size) { 00629 // unset($files[$file->filepath]); 00630 unset($files[$file->filename]); 00631 } 00632 } 00633 } 00634 } 00635 usort($files, array($this, 'drupalCompareFiles')); 00636 return $files; 00637 }
DrupalWebTestCase::drupalHead | ( | $ | path, | |
array $ | options = array() , |
|||
array $ | headers = array() | |||
) | [protected] |
Retrieves only the headers for a Drupal path or an absolute path.
$path | Drupal path or URL to load into internal browser | |
$options | Options to be forwarded to url(). | |
$headers | An array containing additional HTTP request headers, each formatted as "name: value". |
Definition at line 1294 of file drupal_web_test_case.php.
References $headers, curlExec(), and refreshVariables().
01294 { 01295 $options['absolute'] = TRUE; 01296 $out = $this->curlExec(array(CURLOPT_NOBODY => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_HTTPHEADER => $headers)); 01297 $this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up. 01298 return $out; 01299 }
DrupalWebTestCase::drupalLogin | ( | stdClass $ | user | ) | [protected] |
Log in a user with the internal browser.
If a user is already logged in, then the current user is logged out before logging in the specified user.
Please note that neither the global $user nor the passed in user object is populated with data of the logged in user. If you need full access to the user object after logging in, it must be updated manually. If you also need access to the plain-text password of the user (set by drupalCreateUser()), e.g. to login the same user again, then it must be re-assigned manually. For example:
// Create a user. $account = $this->drupalCreateUser(array()); $this->drupalLogin($account); // Load real user object. $pass_raw = $account->pass_raw; $account = user_load($account->uid); $account->pass_raw = $pass_raw;
$user | User object representing the user to login. |
Definition at line 810 of file drupal_web_test_case.php.
References assertNoText(), assertText(), drupalLogout(), and drupalPost().
00810 { 00811 if ($this->loggedInUser) { 00812 $this->drupalLogout(); 00813 } 00814 00815 $edit = array( 00816 'name' => $user->name, 00817 'pass' => $user->pass_raw 00818 ); 00819 $this->drupalPost('user', $edit, t('Log in')); 00820 00821 $pass = $this->assertText($user->name, t('Found name: %name', array('%name' => $user->name)), t('User login')); 00822 $pass = $pass && $this->assertNoText(t('The username %name has been blocked.', array('%name' => $user->name)), t('No blocked message at login page'), t('User login')); 00823 $pass = $pass && $this->assertNoText(t('The name %name is a reserved username.', array('%name' => $user->name)), t('No reserved message at login page'), t('User login')); 00824 00825 if ($pass) { 00826 $this->loggedInUser = $user; 00827 } 00828 }
DrupalWebTestCase::drupalLogout | ( | ) | [protected] |
Definition at line 833 of file drupal_web_test_case.php.
References assertField(), and drupalGet().
00833 { 00834 // Make a request to the logout page. 00835 // $this->drupalGet('user/logout'); 00836 $this->drupalGet('logout'); 00837 00838 // Load the user page, the idea being if you were properly logged out you should be seeing a login screen. 00839 $this->drupalGet('user'); 00840 $pass = $this->assertField('name', t('Username field found.'), t('Logout')); 00841 $pass = $pass && $this->assertField('pass', t('Password field found.'), t('Logout')); 00842 00843 if ($pass) { 00844 $this->loggedInUser = FALSE; 00845 } 00846 }
DrupalWebTestCase::drupalPost | ( | $ | path, | |
$ | edit, | |||
$ | submit, | |||
array $ | options = array() , |
|||
array $ | headers = array() | |||
) | [protected] |
Execute a POST request on a Drupal page.
It will be done as usual POST request with SimpleBrowser.
$path | Location of the post form. Either a Drupal path or an absolute path or NULL to post to the current page. For multi-stage forms you can set the path to NULL and have it post to the last received page. Example: |
// Second step in form. $edit = array(...); $this->drupalPost(NULL, $edit, t('Save'));
$edit | Field data in an associative 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. Note that when a form contains file upload fields, other fields cannot start with the '@' character. |
$submit | Value of the submit button. | |
$options | Options to be forwarded to url(). | |
$headers | An array containing additional HTTP request headers, each formatted as "name: value". |
Definition at line 1199 of file drupal_web_test_case.php.
References $headers, assertTrue(), checkForMetaRefresh(), curlExec(), drupalGet(), fail(), getAbsoluteUrl(), getUrl(), handleForm(), parse(), refreshVariables(), and xpath().
01199 { 01200 $submit_matches = FALSE; 01201 if (isset($path)) { 01202 $html = $this->drupalGet($path, $options); 01203 } 01204 if ($this->parse()) { 01205 $edit_save = $edit; 01206 // Let's iterate over all the forms. 01207 $forms = $this->xpath('//form'); 01208 foreach ($forms as $form) { 01209 // We try to set the fields of this form as specified in $edit. 01210 $edit = $edit_save; 01211 $post = array(); 01212 $upload = array(); 01213 $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form); 01214 $action = isset($form['action']) ? $this->getAbsoluteUrl($form['action']) : $this->getUrl(); 01215 01216 // We post only if we managed to handle every field in edit and the 01217 // submit button matches. 01218 if (!$edit && $submit_matches) { 01219 if ($upload) { 01220 // TODO: cURL handles file uploads for us, but the implementation 01221 // is broken. This is a less than elegant workaround. Alternatives 01222 // are being explored at #253506. 01223 foreach ($upload as $key => $file) { 01224 $file = realpath($file); 01225 if ($file && is_file($file)) { 01226 $post[$key] = '@' . $file; 01227 } 01228 } 01229 } 01230 else { 01231 foreach ($post as $key => $value) { 01232 // Encode according to application/x-www-form-urlencoded 01233 // Both names and values needs to be urlencoded, according to 01234 // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 01235 $post[$key] = urlencode($key) . '=' . urlencode($value); 01236 } 01237 $post = implode('&', $post); 01238 } 01239 $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers)); 01240 // Ensure that any changes to variables in the other thread are picked up. 01241 $this->refreshVariables(); 01242 01243 // Replace original page output with new output from redirected page(s). 01244 if (($new = $this->checkForMetaRefresh())) { 01245 $out = $new; 01246 } 01247 return $out; 01248 } 01249 } 01250 // We have not found a form which contained all fields of $edit. 01251 foreach ($edit as $name => $value) { 01252 $this->fail(t('Failed to set field @name to @value', array('@name' => $name, '@value' => $value))); 01253 } 01254 $this->assertTrue($submit_matches, t('Found the @submit button', array('@submit' => $submit))); 01255 $this->fail(t('Found the requested form fields at @path', array('@path' => $path))); 01256 } 01257 }
DrupalWebTestCase::drupalSetContent | ( | $ | content, | |
$ | url = 'internal:' | |||
) | [protected] |
Sets the raw HTML content.
This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
A good example would be when testing drupal_http_request(). After fetching the page the content can be set and page elements can be checked to ensure that the function worked properly.
Definition at line 1681 of file drupal_web_test_case.php.
References $content, and $url.
01681 :') { 01682 $this->content = $content; 01683 $this->url = $url; 01684 $this->plainTextContent = FALSE; 01685 $this->elements = FALSE; 01686 }
DrupalWebTestCase::error | ( | $ | message = '' , |
|
$ | group = 'Other' , |
|||
array $ | caller = NULL | |||
) | [protected] |
Fire an error assertion.
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". | |
$caller | The caller of the error. |
Definition at line 403 of file drupal_web_test_case.php.
DrupalWebTestCase::errorHandler | ( | $ | severity, | |
$ | message, | |||
$ | file = NULL , |
|||
$ | line = NULL | |||
) |
Handle errors.
Because this is registered in set_error_handler(), it has to be public.
Definition at line 440 of file drupal_web_test_case.php.
References _drupal_get_last_caller(), and error().
00440 { 00441 if ($severity & error_reporting()) { 00442 $error_map = array( 00443 E_STRICT => 'Run-time notice', 00444 E_WARNING => 'Warning', 00445 E_NOTICE => 'Notice', 00446 E_CORE_ERROR => 'Core error', 00447 E_CORE_WARNING => 'Core warning', 00448 E_USER_ERROR => 'User error', 00449 E_USER_WARNING => 'User warning', 00450 E_USER_NOTICE => 'User notice', 00451 E_RECOVERABLE_ERROR => 'Recoverable error', 00452 ); 00453 00454 $backtrace = debug_backtrace(); 00455 $this->error($message, $error_map[$severity], _drupal_get_last_caller($backtrace)); 00456 } 00457 return TRUE; 00458 }
DrupalWebTestCase::exceptionHandler | ( | $ | exception | ) | [protected] |
Handle exceptions.
Definition at line 465 of file drupal_web_test_case.php.
References _drupal_get_last_caller(), and error().
00465 { 00466 $backtrace = $exception->getTrace(); 00467 // Push on top of the backtrace the call that generated the exception. 00468 array_unshift($backtrace, array( 00469 'line' => $exception->getLine(), 00470 'file' => $exception->getFile(), 00471 )); 00472 $this->error($exception->getMessage(), 'Uncaught exception', _drupal_get_last_caller($backtrace)); 00473 }
DrupalWebTestCase::fail | ( | $ | message = NULL , |
|
$ | group = 'Other' | |||
) | [protected] |
Fire an assertion that is always negative.
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 387 of file drupal_web_test_case.php.
DrupalWebTestCase::getAbsoluteUrl | ( | $ | path | ) | [protected] |
Takes a path and returns an absolute path.
$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. |
Definition at line 1550 of file drupal_web_test_case.php.
01550 { 01551 $options = array('absolute' => TRUE); 01552 $parts = parse_url($path); 01553 // This is more crude than the menu_is_external but enough here. 01554 if (empty($parts['host'])) { 01555 $path = $parts['path']; 01556 $base_path = base_path(); 01557 $n = strlen($base_path); 01558 if (substr($path, 0, $n) == $base_path) { 01559 $path = substr($path, $n); 01560 } 01561 if (isset($parts['query'])) { 01562 $options['query'] = $parts['query']; 01563 } 01564 $path = url($path, $options); 01565 } 01566 return $path; 01567 }
DrupalWebTestCase::getAllOptions | ( | SimpleXMLElement $ | element | ) | [protected] |
Get all option elements, including nested options, in a select.
$element | The element for which to get the options. |
Definition at line 1457 of file drupal_web_test_case.php.
01457 { 01458 $options = array(); 01459 // Add all options items. 01460 foreach ($element->option as $option) { 01461 $options[] = $option; 01462 } 01463 01464 // Search option group children. 01465 if (isset($element->optgroup)) { 01466 foreach ($element->optgroup as $group) { 01467 $options = array_merge($options, $this->getAllOptions($group)); 01468 } 01469 } 01470 return $options; 01471 }
DrupalWebTestCase::getAssertionCall | ( | ) | [protected] |
Cycles through backtrace until the first non-assertion method is found.
Definition at line 211 of file drupal_web_test_case.php.
References _drupal_get_last_caller().
00211 { 00212 $backtrace = debug_backtrace(); 00213 00214 // The first element is the call. The second element is the caller. 00215 // We skip calls that occurred in one of the methods of DrupalWebTestCase 00216 // or in an assertion function. 00217 while (($caller = $backtrace[1]) && 00218 ((isset($caller['class']) && $caller['class'] == 'DrupalWebTestCase') || 00219 substr($caller['function'], 0, 6) == 'assert')) { 00220 // We remove that call. 00221 array_shift($backtrace); 00222 } 00223 00224 return _drupal_get_last_caller($backtrace); 00225 }
DrupalWebTestCase::getSelectedItem | ( | SimpleXMLElement $ | element | ) | [protected] |
Get the selected value from a select field.
$element | SimpleXMLElement select element. |
Definition at line 1978 of file drupal_web_test_case.php.
01978 { 01979 foreach ($element->children() as $item) { 01980 if (isset($item['selected'])) { 01981 return $item['value']; 01982 } 01983 elseif ($item->getName() == 'optgroup') { 01984 if ($value = $this->getSelectedItem($item)) { 01985 return $value; 01986 } 01987 } 01988 } 01989 return FALSE; 01990 }
DrupalWebTestCase::getUrl | ( | ) | [protected] |
Get the current url from the cURL handler.
Definition at line 1575 of file drupal_web_test_case.php.
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 manner for the particular field type.
$post | Reference to array of post values. | |
$edit | Reference to array of edit values to be checked against the form. | |
$submit | Form submit button value. | |
$form | Array of form elements. |
Definition at line 1317 of file drupal_web_test_case.php.
References $elements, and getAllOptions().
01317 { 01318 // Retrieve the form elements. 01319 $elements = $form->xpath('.//input|.//textarea|.//select'); 01320 $submit_matches = FALSE; 01321 foreach ($elements as $element) { 01322 // SimpleXML objects need string casting all the time. 01323 $name = (string) $element['name']; 01324 // This can either be the type of <input> or the name of the tag itself 01325 // for <select> or <textarea>. 01326 $type = isset($element['type']) ? (string)$element['type'] : $element->getName(); 01327 $value = isset($element['value']) ? (string)$element['value'] : ''; 01328 $done = FALSE; 01329 if (isset($edit[$name])) { 01330 switch ($type) { 01331 case 'text': 01332 case 'textarea': 01333 case 'password': 01334 $post[$name] = $edit[$name]; 01335 unset($edit[$name]); 01336 break; 01337 case 'radio': 01338 if ($edit[$name] == $value) { 01339 $post[$name] = $edit[$name]; 01340 unset($edit[$name]); 01341 } 01342 break; 01343 case 'checkbox': 01344 // To prevent checkbox from being checked.pass in a FALSE, 01345 // otherwise the checkbox will be set to its value regardless 01346 // of $edit. 01347 if ($edit[$name] === FALSE) { 01348 unset($edit[$name]); 01349 continue 2; 01350 } 01351 else { 01352 unset($edit[$name]); 01353 $post[$name] = $value; 01354 } 01355 break; 01356 case 'select': 01357 $new_value = $edit[$name]; 01358 $index = 0; 01359 $key = preg_replace('/\[\]$/', '', $name); 01360 $options = $this->getAllOptions($element); 01361 foreach ($options as $option) { 01362 if (is_array($new_value)) { 01363 $option_value= (string)$option['value']; 01364 if (in_array($option_value, $new_value)) { 01365 $post[$key . '[' . $index++ . ']'] = $option_value; 01366 $done = TRUE; 01367 unset($edit[$name]); 01368 } 01369 } 01370 elseif ($new_value == $option['value']) { 01371 $post[$name] = $new_value; 01372 unset($edit[$name]); 01373 $done = TRUE; 01374 } 01375 } 01376 break; 01377 case 'file': 01378 $upload[$name] = $edit[$name]; 01379 unset($edit[$name]); 01380 break; 01381 } 01382 } 01383 if (!isset($post[$name]) && !$done) { 01384 switch ($type) { 01385 case 'textarea': 01386 $post[$name] = (string)$element; 01387 break; 01388 case 'select': 01389 $single = empty($element['multiple']); 01390 $first = TRUE; 01391 $index = 0; 01392 $key = preg_replace('/\[\]$/', '', $name); 01393 $options = $this->getAllOptions($element); 01394 foreach ($options as $option) { 01395 // For single select, we load the first option, if there is a 01396 // selected option that will overwrite it later. 01397 if ($option['selected'] || ($first && $single)) { 01398 $first = FALSE; 01399 if ($single) { 01400 $post[$name] = (string)$option['value']; 01401 } 01402 else { 01403 $post[$key . '[' . $index++ . ']'] = (string)$option['value']; 01404 } 01405 } 01406 } 01407 break; 01408 case 'file': 01409 break; 01410 case 'submit': 01411 case 'image': 01412 if ($submit == $value) { 01413 $post[$name] = $value; 01414 $submit_matches = TRUE; 01415 } 01416 break; 01417 case 'radio': 01418 case 'checkbox': 01419 if (!isset($element['checked'])) { 01420 break; 01421 } 01422 // Deliberate no break. 01423 default: 01424 $post[$name] = $value; 01425 } 01426 } 01427 } 01428 return $submit_matches; 01429 }
DrupalWebTestCase::parse | ( | ) | [protected] |
Parse content returned from curlExec using DOM and SimpleXML.
Definition at line 1116 of file drupal_web_test_case.php.
References fail(), getUrl(), and pass().
01116 { 01117 if (!$this->elements) { 01118 // DOM can load HTML soup. But, HTML soup can throw warnings, suppress 01119 // them. 01120 @$htmlDom = DOMDocument::loadHTML($this->content); 01121 if ($htmlDom) { 01122 $this->pass(t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser')); 01123 // It's much easier to work with simplexml than DOM, luckily enough 01124 // we can just simply import our DOM tree. 01125 $this->elements = simplexml_import_dom($htmlDom); 01126 } 01127 } 01128 if (!$this->elements) { 01129 $this->fail(t('Parsed page successfully.'), t('Browser')); 01130 } 01131 01132 return $this->elements; 01133 }
DrupalWebTestCase::pass | ( | $ | message = NULL , |
|
$ | group = 'Other' | |||
) | [protected] |
Fire an assertion that is always positive.
$message | The message to display along with the assertion. | |
$group | The type of assertion - examples are "Browser", "PHP". |
Definition at line 373 of file drupal_web_test_case.php.
DrupalWebTestCase::preloadRegistry | ( | ) | [protected] |
This method is called by DrupalWebTestCase::setUp, and preloads the registry from the testing site to cut down on the time it takes to setup a clean environment for the current test run.
Definition at line 933 of file drupal_web_test_case.php.
00933 { 00934 db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry'); 00935 db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file'); 00936 }
static DrupalWebTestCase::randomName | ( | $ | number = 4 , |
|
$ | prefix = 'simpletest_' | |||
) | [static] |
Generates a random string.
$number | Number of characters in length to append to the prefix. | |
$prefix | Prefix to use. |
Definition at line 665 of file drupal_web_test_case.php.
00665 { 00666 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'; 00667 for ($x = 0; $x < $number; $x++) { 00668 $prefix .= $chars{mt_rand(0, strlen($chars) - 1)}; 00669 if ($x == 0) { 00670 $chars .= '0123456789'; 00671 } 00672 } 00673 return $prefix; 00674 }
DrupalWebTestCase::refreshVariables | ( | ) | [protected] |
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 950 of file drupal_web_test_case.php.
00950 { 00951 global $conf; 00952 cache_clear_all('variables', 'cache'); 00953 $conf = variable_init(); 00954 }
DrupalWebTestCase::run | ( | ) |
Run all tests in this class.
Definition at line 410 of file drupal_web_test_case.php.
References exceptionHandler(), setUp(), and tearDown().
00410 { 00411 set_error_handler(array($this, 'errorHandler')); 00412 $methods = array(); 00413 // Iterate through all the methods in this class. 00414 foreach (get_class_methods(get_class($this)) as $method) { 00415 // If the current method starts with "test", run it - it's a test. 00416 if (strtolower(substr($method, 0, 4)) == 'test') { 00417 $this->setUp(); 00418 try { 00419 $this->$method(); 00420 // Finish up. 00421 } 00422 catch (Exception $e) { 00423 $this->exceptionHandler($e); 00424 } 00425 $this->tearDown(); 00426 } 00427 } 00428 // Clear out the error messages and restore error handler. 00429 drupal_get_messages(); 00430 restore_error_handler(); 00431 }
DrupalWebTestCase::setUp | ( | ) | [protected] |
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules.
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.
... | List of modules to enable for the duration of the test. |
Reimplemented in SimpleTestFunctionalTest, and BlockTestCase.
Definition at line 858 of file drupal_web_test_case.php.
References checkPermissions(), and refreshVariables().
00858 { 00859 global $db_prefix, $user, $language; // $language (Drupal 6). 00860 00861 // Store necessary current values before switching to prefixed database. 00862 $this->originalPrefix = $db_prefix; 00863 $this->originalFileDirectory = file_directory_path(); 00864 $clean_url_original = variable_get('clean_url', 0); 00865 00866 // Must reset locale here, since schema calls t(). (Drupal 6) 00867 if (module_exists('locale')) { 00868 $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); 00869 locale(NULL, NULL, TRUE); 00870 } 00871 00872 // Generate temporary prefixed database to ensure that tests have a clean starting point. 00873 // $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); 00874 $db_prefix = 'simpletest' . mt_rand(1000, 1000000); 00875 00876 // include_once DRUPAL_ROOT . '/includes/install.inc'; 00877 include_once './includes/install.inc'; 00878 drupal_install_system(); 00879 00880 // $this->preloadRegistry(); 00881 00882 // Add the specified modules to the list of modules in the default profile. 00883 $args = func_get_args(); 00884 // $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args)); 00885 $modules = array_unique(array_merge(drupal_verify_profile('default', 'en'), $args)); 00886 // drupal_install_modules($modules, TRUE); 00887 drupal_install_modules($modules); 00888 00889 // Because the schema is static cached, we need to flush 00890 // it between each run. If we don't, then it will contain 00891 // stale data for the previous run's database prefix and all 00892 // calls to it will fail. 00893 drupal_get_schema(NULL, TRUE); 00894 00895 // Run default profile tasks. 00896 $task = 'profile'; 00897 default_profile_tasks($task, ''); 00898 00899 // Rebuild caches. 00900 actions_synchronize(); 00901 _drupal_flush_css_js(); 00902 $this->refreshVariables(); 00903 $this->checkPermissions(array(), TRUE); 00904 user_access(NULL, NULL, TRUE); // Drupal 6. 00905 00906 // Log in with a clean $user. 00907 $this->originalUser = $user; 00908 // drupal_save_session(FALSE); 00909 // $user = user_load(1); 00910 session_save_session(FALSE); 00911 $user = user_load(array('uid' => 1)); 00912 00913 // Restore necessary variables. 00914 variable_set('install_profile', 'default'); 00915 variable_set('install_task', 'profile-finished'); 00916 variable_set('clean_url', $clean_url_original); 00917 variable_set('site_mail', 'simpletest@example.com'); 00918 00919 // Use temporary files directory with the same prefix as database. 00920 variable_set('file_directory_path', $this->originalFileDirectory . '/' . $db_prefix); 00921 $directory = file_directory_path(); 00922 // Create the files directory. 00923 file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); 00924 00925 set_time_limit($this->timeLimit); 00926 }
DrupalWebTestCase::tearDown | ( | ) | [protected] |
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
Definition at line 960 of file drupal_web_test_case.php.
References curlClose(), refreshVariables(), and simpletest_clean_temporary_directory().
00960 { 00961 global $db_prefix, $user; 00962 if (preg_match('/simpletest\d+/', $db_prefix)) { 00963 // Delete temporary files directory and reset files directory path. 00964 // file_unmanaged_delete_recursive(file_directory_path()); 00965 simpletest_clean_temporary_directory(file_directory_path()); 00966 variable_set('file_directory_path', $this->originalFileDirectory); 00967 00968 // Remove all prefixed tables (all the tables in the schema). 00969 $schema = drupal_get_schema(NULL, TRUE); 00970 $ret = array(); 00971 foreach ($schema as $name => $table) { 00972 db_drop_table($ret, $name); 00973 } 00974 00975 // Return the database prefix to the original. 00976 $db_prefix = $this->originalPrefix; 00977 00978 // Return the user to the original one. 00979 $user = $this->originalUser; 00980 // drupal_save_session(TRUE); 00981 session_save_session(TRUE); 00982 00983 // Bring back default language. (Drupal 6) 00984 if (module_exists('locale')) { 00985 drupal_init_language(); 00986 locale(NULL, NULL, TRUE); 00987 } 00988 00989 // Ensure that internal logged in variable and cURL options are reset. 00990 $this->loggedInUser = FALSE; 00991 $this->additionalCurlOptions = array(); 00992 00993 // Reload module list and implementations to ensure that test module hooks 00994 // aren't called after tests. 00995 module_list(TRUE); 00996 // module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE); 00997 module_implements('', '', TRUE); 00998 00999 // Reset the Field API. 01000 // field_cache_clear(); 01001 01002 // Rebuild caches. 01003 $this->refreshVariables(); 01004 01005 // Close the CURL handler. 01006 $this->curlClose(); 01007 } 01008 }
DrupalWebTestCase::xpath | ( | $ | xpath | ) | [protected] |
Perform an xpath search on the contents of the internal browser.
The search is relative to the root element (HTML tag normally) of the page.
$xpath | The xpath string to use in the search. |
Definition at line 1442 of file drupal_web_test_case.php.
References parse().
01442 { 01443 if ($this->parse()) { 01444 return $this->elements->xpath($xpath); 01445 } 01446 return FALSE; 01447 }
DrupalWebTestCase::$additionalCurlOptions = array() [protected] |
Additional cURL options.
DrupalWebTestCase itself never sets this but always obeys what is set.
Definition at line 88 of file drupal_web_test_case.php.
DrupalWebTestCase::$assertions = array() [protected] |
Definition at line 127 of file drupal_web_test_case.php.
DrupalWebTestCase::$content [protected] |
Definition at line 52 of file drupal_web_test_case.php.
DrupalWebTestCase::$cookieFile = NULL [protected] |
The current cookie file used by cURL.
We do not reuse the cookies in further runs, so we do not need a file but we still need cookie handling, so we set the jar to NULL.
Definition at line 81 of file drupal_web_test_case.php.
DrupalWebTestCase::$curlHandle [protected] |
Definition at line 38 of file drupal_web_test_case.php.
DrupalWebTestCase::$elements = NULL [protected] |
Definition at line 66 of file drupal_web_test_case.php.
DrupalWebTestCase::$headers [protected] |
Definition at line 45 of file drupal_web_test_case.php.
DrupalWebTestCase::$loggedInUser = FALSE [protected] |
Definition at line 73 of file drupal_web_test_case.php.
DrupalWebTestCase::$originalFileDirectory = NULL [protected] |
Definition at line 102 of file drupal_web_test_case.php.
DrupalWebTestCase::$originalPrefix = NULL [protected] |
Definition at line 95 of file drupal_web_test_case.php.
DrupalWebTestCase::$originalUser = NULL [protected] |
Definition at line 109 of file drupal_web_test_case.php.
DrupalWebTestCase::$plainTextContent [protected] |
Definition at line 59 of file drupal_web_test_case.php.
DrupalWebTestCase::$results |
Initial value:
array( '#pass' => 0, '#fail' => 0, '#exception' => 0, )
Definition at line 116 of file drupal_web_test_case.php.
DrupalWebTestCase::$testId [protected] |
Definition at line 24 of file drupal_web_test_case.php.
DrupalWebTestCase::$timeLimit = 180 [protected] |
DrupalWebTestCase::$url [protected] |
Definition at line 31 of file drupal_web_test_case.php.