home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (permissions.test)

This example Drupal source code file (permissions.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

access, and, array, confirmation, extends, form, function, node, permissions, php, submit, to, url, users

The permissions.test Drupal example source code


 * @file
 * Webform module permission tests.

include_once(dirname(__FILE__) . '/webform.test');

class WebformPermissionsTestCase extends WebformTestCase {
   * Implementation of getInfo().
  public static function getInfo() {
    return array(
      'name' => t('Webform permissions'),
      'description' => t('Create webforms and check editing and access permissions.'),
      'group' => t('Webform'),

   * Implementation of setUp().
  function setUp() {

   * Implementation of tearDown().
  function tearDown() {

   * Create a webform node in which authenticated users have access to submit.
  function testWebformSubmitAccess() {
    $node = $this->testWebformForm();
    $node->webform['roles'] = array(2);

    // Test that the authenticated user is able to access.
    $this->drupalGet('node/' . $node->nid);
    $this->assertText($node->body[LANGUAGE_NONE][0]['value'], t('Webform node created and accessible to authenticated users at !url', array('!url' => 'node/' . $node->nid)), t('Webform'));

    // Confirm that the submission has been created.
    $this->drupalPost(NULL, array(), 'Submit');
    $this->assertText($node->webform['confirmation'], t('Confirmation message "@confirmation" received.', array('@confirmation' => $node->webform['confirmation'])), t('Webform'));

    // The anonymous user should not be able to submit.
    $this->drupalGet('node/' . $node->nid);

    // Note: Should be: You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.
    // Something in SimpleTest isn't handling the string correctly.
    $this->assertText('to view this form.', t('Anonymous user is not allowed to submit form.'), t('Webform'));

   * Create webform


Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal permissions.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.