You are here

pmexpense.test in Drupal PM (Project Management) 7

Test definitions for the PM Expense module

File

pmexpense/pmexpense.test
View source
<?php

/**
 * @file
 * Test definitions for the PM Expense module
 */

/**
 * Defines tests for the PM Expense module.
 */
class PMExpenseTestCase extends DrupalWebTestCase {

  /**
   * Defines metadata for test case.
   */
  public static function getInfo() {
    return array(
      'name' => t('PM Expense Functionality'),
      'description' => t('Test the functionality of the PM Expense module'),
      'group' => 'Project Management',
    );
  }

  /**
   * Defines modules to be enabled for each test run.
   */
  public function setUp() {
    parent::setUp('pm', 'pmorganization', 'pmproject', 'pmtask', 'pmticket', 'pmexpense');
  }

  /**
   * Tests creation of an Expense.
   */
  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.'));
  }

}

Classes

Namesort descending Description
PMExpenseTestCase Defines tests for the PM Expense module.