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

/**
 * Test definition for the PM Person module.
 */
class PMPersonTestCase extends DrupalWebTestCase {

  /**
   * Defines test meta-data.
   */
  public static function getInfo() {
    return array(
      'name' => 'PM Person functionality',
      'description' => 'Test the functionality of the PM Person module',
      'group' => 'Project Management',
    );
  }

  /**
   * Set up environment for test.
   */
  public function setUp() {
    parent::setUp('pm', 'pmorganization', 'pmperson');
    $privileged_user = $this->drupalCreateUser(array('Project Management Organization: add', 'Project Management Organization: view all', 'Project Management Person: add'));
    $this->drupalLogin($privileged_user);
  }

  /**
   * Access test case.
   */
  public function testpmpersonAccess() {
    $this->drupalGet('pm/people');
    $this->assertResponse(403, t('Make sure access is denied to Project Management People list for anonymous user'));

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

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

  /**
   * Node creation test case.
   */
  public function testpmpersonCreate() {
    $org = array(
      'title' => $this->randomName(32),
      'body[und][0][value]' => $this->randomName(64),
    );
    $person = array(
      'title' => $this->randomName(32),
      'body[und][0][value]' => $this->randomName(64),
    );

    $this->drupalPost('node/add/pmorganization', $org, t('Save'));
    $this->drupalPost('node/add/pmperson', $person, t('Save'));
    $this->assertText(t('Person @title has been created.', array('@title' => $person['title'])));
  }
}
