You are here

RequiredByRoleBasic.test in Required by role 7

Same filename and directory in other branches
  1. 7.2 tests/required_by_role_test/RequiredByRoleBasic.test

Tests for Required by role module.

File

tests/required_by_role_test/RequiredByRoleBasic.test
View source
<?php

/**
 * @file
 * Tests for Required by role module.
 */

/**
 * Base class for all required by role web test cases.
 */
abstract class RequiredByRoleBasic extends DrupalWebTestCase {
  protected $entity_type = 'node';
  protected $entity_bundle = 'article';
  protected $basePermissions = array();
  protected $required_fields_rid = NULL;
  static $required_user = NULL;
  static $non_required_user = NULL;

  /**
   * Setup method.
   */
  protected function setUp() {
    parent::setUp('field_ui', 'required_by_role_test');
    $this->basePermissions = array(
      'access content',
      'create ' . $this->entity_bundle . ' content',
      'edit any ' . $this->entity_bundle . ' content',
      'administer content types',
      'administer nodes',
      'administer filters',
      'access comments',
      'post comments',
      'access administration pages',
    );

    // Create Basic page and Article node types.
    if ($this->profile != 'standard') {
      $this
        ->drupalCreateContentType(array(
        'type' => $this->entity_bundle,
        'name' => 'Article',
      ));
    }
    module_load_include('inc', 'field', 'field.crud');
    module_load_include('inc', 'node', 'node.pages');

    // Create a role for required fields.
    $this->required_fields_rid = $this
      ->drupalCreateRole($this->basePermissions, 'Required fields role');
  }

  /**
   * Helper method to ghet a required user.
   */
  protected function getRequiredUser() {
    $account = self::$required_user;
    if (is_null($account)) {
      $account = $this
        ->drupalCreateUser($this->basePermissions);
      $edit = array();
      $edit['roles'] = array(
        $this->required_fields_rid => $this->required_fields_rid,
      );
      $account = user_save($account, $edit);
      self::$required_user = $account;
    }
    return $account;
  }

  /**
   * Helper method to ghet a non-required user.
   */
  protected function getNonRequiredUser() {
    $account = self::$non_required_user;
    if (is_null($account)) {
      $account = $this
        ->drupalCreateUser($this->basePermissions);
      self::$non_required_user = $account;
    }
    return $account;
  }

}

Classes

Namesort descending Description
RequiredByRoleBasic Base class for all required by role web test cases.