API functions
The internal browser
The DrupalWebTestCase features an internal browser that can be used to navigate on your test site. Please read the basic documentation of the WebTestCase class for more information.
function $this->drupalGet($path, $options = array())-
This function does a get request to a Drupal page.
The$pathindicates a page that can be visited;$optionscontains additional data which may be passed to the url() function in order to determine the url to visit. The content will be loaded and saved into $this->_content (as well as returned), where it can be retrieved by using the function $this->drupalGetContent(). function $this->drupalPost($path, $edit, $submit, $reporting = TRUE)-
This function does a post request on a Drupal page.
The$pathindicates a page containing a form that will be filled with$editdata. Then the button indicated by$submitwill be clicked (submit caption will be translated by this method).It also does assertion that the requests were successful and form fields could be set.
Example:
<?php
$name = $this->randomName();
$mail = "$name@example.com";
$edit = array('name' => $name,
'mail' => $mail);
$this->drupalPost('user/register', $edit, 'Create new account');
?>Note: this function used to be called drupalPostRequest()
function $this->clickLink($label, $index = 0)-
Follows a link on the current page by name. Will click the first link found with this link text by default, or a later one if an
$indexis given. The$labelis automatically translated.
An assertion is done about the availability of the link and the URL it points to. Also gives some output including current and requested URL.Example:
<?php
$this->clickLink(t('Log out'));
?> function $this->drupalCreateUser($permissions = NULL)-
This function creates a user and returns the user object with an additional value
pass_rawcontaining the non-hashed password.
It also creates a role with the specified$permissionsthat is assigned to the returned user.
The$permissionsare specified as an array of strings. If it is omitted or NULL, the default permissions for a registered user will be used:
'access comments, access content, post comments, post comments without approval'
An assertion for success is done as well as clean-up on the user and role tables. function $this->drupalLogin($user = NULL)-
This function logs a user into your site via the internal browser. You can just hand it a
$userobject (required is apass_rawvalue).
If the argument is omitted this function will create a user and role with the standard permissions mentioned above.After the user is logged in, you can now navigate with the internal browser.
Example:
<?php
// Prepare a user to do the stuff
$user = $this->drupalCreateUser(array('access content', 'create page content'));
$this->drupalLogin($user);
// Now do something with the users
$this->drupalGet('node/' . $node->nid));
?>This method also does several assertions about the login process from the browsers perspective.
function $this->_drupalCreateRole($permissions = NULL)-
This function is rarely useful. The
$permissionsparameter behaves exactly like indrupalCreateUser.
The return value is a role-id integer or FALSE on failure.
A success assertion is done, as well as decent clean-up of the role and permission tables.
function $this->randomName($number = 4, $prefix = 'simpletest_')
Returns a string with $number alphanumerical character(s) prefixed by $prefix.
The first character will not be a number.

drupalCreateNode() doesn't do permissions check
drupalCreateNode()does not do a permissions check to see if the currently logged in user can actually create a node of the given type. I found this out after wondering why some of my tests were failing, and I began to dig into the code forDrupalWebTestCase. I was hoping thatdrupalCreateNode()was just a pretty way of creating a node as if a user went to , but that is not the case. So, if one wishes to emulate the creation of a node as if a user did it, one must still usedrupalPost().