<?php
/**
 * @file
 * Test definitions for the PM Project module
 */
class PMProjectTestCase extends DrupalWebTestCase {

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

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

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

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

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

  /**
   * Test case covering creation of pmprojects.
   */
  public function testpmprojectCreate() {
    // 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'));
    $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',
    );
    $this->drupalPost('node/add/pmorganization', $org, t('Save'));
    $this->drupalPost('node/add/pmproject', $prj, t('Save'));

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