You are here

function ContentAccessTestCase::setUp in Content Access 6

Same name and namespace in other branches
  1. 5 tests/content_access_test_help.php \ContentAccessTestCase::setUp()
  2. 7 tests/content_access_test_help.php \ContentAccessTestCase::setUp()

Preparation work that is done before each test. Test users, content types, nodes etc. are created.

Overrides DrupalWebTestCase::setUp

2 calls to ContentAccessTestCase::setUp()
ContentAccessACLTestCase::setUp in tests/content_access_acl.test
Setup configuration before each test
ContentAccessModuleTestCase::setUp in tests/content_access.test
Preparation work that is done before each test. Test users, content types, nodes etc. are created.
2 methods override ContentAccessTestCase::setUp()
ContentAccessACLTestCase::setUp in tests/content_access_acl.test
Setup configuration before each test
ContentAccessModuleTestCase::setUp in tests/content_access.test
Preparation work that is done before each test. Test users, content types, nodes etc. are created.

File

tests/content_access_test_help.php, line 21
Helper class with auxiliary functions for content access module tests

Class

ContentAccessTestCase
@file Helper class with auxiliary functions for content access module tests

Code

function setUp($module = '') {
  if (empty($module)) {

    // Enable content access module
    parent::setUp('content_access');
  }
  else {

    // Enable content access module plus another module
    parent::setUp('content_access', $module);

    // Stop setup when module could not be enabled
    if (!module_exists($module)) {
      return;
    }
  }

  // Create test user with seperate role
  $this->test_user = $this
    ->drupalCreateUser();

  // Create admin user
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'access content',
    'administer content types',
    'grant content access',
    'grant own content access',
    'administer nodes',
    'access administration pages',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // Rebuild content access permissions
  $this
    ->drupalPost('admin/content/node-settings/rebuild', array(), t('Rebuild permissions'));

  // This would be nice to have - but it does not work in the current simpletest version
  // Create test content type

  //$content_type = $this->drupalCreateContentType();

  //$this->url_content_type_name = $content_type->type;

  //$this->url_content_type_name = str_replace('_', '-', $content_type->type);

  // Create test content type (the old way)
  $this->content_type_name = strtolower($this
    ->randomName(5));
  $edit = array(
    'name' => $this->content_type_name,
    'type' => $this->content_type_name,
  );
  $this
    ->drupalPost('admin/content/types/add', $edit, t('Save content type'));
  $this
    ->assertRaw(t('The content type %type has been added.', array(
    '%type' => $this->content_type_name,
  )), 'Test content type was added successfully: ' . $this->content_type_name);
  $this->url_content_type_name = str_replace('_', '-', $this->content_type_name);
}