<?php
/**
 * @file
 * Test definitions for the PM Task module
 */

/**
 * Class defining PM Task test cases.
 */
class PMTaskTestCase extends DrupalWebTestCase {

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

  /**
   * Provides standard set up for all test cases.
   */
  public function setUp() {
    parent::setUp('pm', 'pmorganization', 'pmproject', 'pmtask');
  }

  /**
   * Test of access controls on Task lists.
   */
  public function testpmtaskAccess() {
    $this->drupalGet('pm/tasks');
    $this->assertResponse(403, t('Make sure access is denied to Project Management Tasks list for anonymous user'));

    $basic_user = $this->drupalCreateUser();
    $this->drupalLogin($basic_user);
    $this->drupalGet('pm/tasks');
    $this->assertResponse(403, t('Make sure access is denied to Project Management Tasks list for basic user'));

    $privileged_user = $this->drupalCreateUser(array('Project Management Task: access'));
    $this->drupalLogin($privileged_user);
    $this->drupalGet('pm/tasks');
    $this->assertText(t('Tasks'), t('Make sure the correct page has been displayed by checking that the title is "Tasks".'));
  }

  /**
   * Test of Task node creation.
   */
  public function testpmtaskCreate() {
    // Create and login user
    $user = $this->drupalCreateUser(array('Project Management Organization: add', 'Project Management Organization: view all', 'Project Management Project: add', 'Project Management Project: view all', 'Project Management Task: add', 'Project Management Task: view all'));
    $this->drupalLogin($user);

    // Create organization and invoice
    $org = array(
      'title' => $this->randomName(32),
      'body[und][0][value]' => $this->randomName(64),
    );
    $prj = array(
      'title' => $this->randomName(32),
      'organization_nid' => '1',
    );
    $task = array(
      'title' => $this->randomName(32),
      'body[und][0][value]' => $this->randomName(64),
    );
    $this->drupalPost('node/add/pmorganization', $org, t('Save'));
    $this->drupalPost('node/add/pmproject', $prj, t('Save'));
    $this->drupalPost('node/add/pmtask', $task, t('Save'));

    $this->assertText(t('Task @title has been created.', array('@title' => $task['title'])));;
  }
}
