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

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

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

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

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

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

  /**
   * Test case covering creation of pmorganizations.
   */
  public function testpmorganizationCreate() {
    $privileged_user = $this->drupalCreateUser(array('Project Management Organization: add'));
    $this->drupalLogin($privileged_user);

    $edit = array(
      'title' => $this->randomName(32),
      'body[und][0][value]' => $this->randomName(64),
    );
    $this->drupalPost('node/add/pmorganization', $edit, t('Save'));
    $this->assertText(t('Organization @title has been created.', array('@title' => $edit['title'])));
  }

}
