You are here

public function PMExpenseTestCase::testpmexpenseCreate in Drupal PM (Project Management) 7

Same name and namespace in other branches
  1. 8 pmexpense/pmexpense.test \PMExpenseTestCase::testpmexpenseCreate()
  2. 7.3 pmexpense/pmexpense.test \PMExpenseTestCase::testpmexpenseCreate()
  3. 7.2 pmexpense/pmexpense.test \PMExpenseTestCase::testpmexpenseCreate()

Tests creation of an Expense.

File

pmexpense/pmexpense.test, line 33
Test definitions for the PM Expense module

Class

PMExpenseTestCase
Defines tests for the PM Expense module.

Code

public function testpmexpenseCreate() {

  // Test access to the PM Expense list for anonymous users.
  $this
    ->drupalGet('pm/expenses');
  $this
    ->assertResponse(403, t('Make sure access is denied to Project Management Expense list for anonymous user'));

  // Create user with no additional permissions, and login.
  $user_basic = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user_basic);

  // Test access to the PM Expense list for this basic user.
  $this
    ->drupalGet('pm/expenses');
  $this
    ->assertResponse(403, t('Make sure access is denied to Project Management Expense list for basic user'));

  // Create user with permissions to add content
  $user_content = $this
    ->drupalCreateUser(array(
    'Project Management Organization: add',
    'Project Management Organization: view all',
    'Project Management expense: add',
    'Project Management expense: view all',
    'Project Management Project: view all',
    'Project Management Task: view all',
  ));
  $this
    ->drupalLogin($user_content);

  // Create an organization node.
  $org = array(
    'title' => $this
      ->randomName(32),
  );
  $this
    ->drupalPost('node/add/pmorganization', $org, t('Save'));

  // Create an expense node.
  $expense = array(
    'organization_nid' => '1',
    'title' => $this
      ->randomName(32),
  );
  $this
    ->drupalPost('node/add/pmexpense', $expense, t('Save'));

  // Test that the expense node is created.
  $this
    ->assertText(t('Expense @title has been created.', array(
    '@title' => $expense['title'],
  )));

  // Create user with permission to access Expense list.
  $user_access = $this
    ->drupalCreateUser(array(
    'Project Management expense: access',
  ));
  $this
    ->drupalLogin($user_access);

  // Test access to the Expense list.
  $this
    ->drupalGet('pm/expenses');
  $this
    ->assertText('Expenses', t('Make sure the correct page has been displayed by checking that the title is "Expenses".'));

  // Test that the created Expense is included in the list.
  $this
    ->assertText($expense['title'], t('Make sure that the created Expense appears in the displayed list.'));
}