<?php
/**
 * @file
 * Test definitions for the PM Ticket module.
 */
class PMTicketTestCase extends DrupalWebTestCase {

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

  /**
   * Standard configuration for all test cases.
   */
  public function setUp() {
    parent::setUp('pm', 'pmorganization', 'pmproject', 'pmtask', 'pmticket');
  }

  /**
   * Test case covering access of ticket list.
   */
  public function testpmticketAccess() {
    $this->drupalGet('pm/tickets');
    $this->assertResponse(403, t('Make sure access is denied to Project Management Tickets list for anonymous user'));

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

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

  /**
   * Test case covering creation of pmtickets.
   */
  public function testpmticketCreate() {
    // 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', 'Project Management Ticket: add', 'Project Management Ticket: 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),
    );
    $ticket = 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->drupalPost('node/add/pmticket', $ticket, t('Save'));

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