You are here

crm_core_activity_ui.test in CRM Core 7

Tests for Activity UI module.

File

modules/crm_core_activity_ui/crm_core_activity_ui.test
View source
<?php

/**
 * @file
 * Tests for Activity UI module.
 */

/**
 * Activity UI test case.
 */
class CRMCoreActivityUITestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => t('Activity UI'),
      'description' => t('Test create/edit/delete activities.'),
      'group' => t('CRM Core'),
    );
  }

  /**
   * Enabled dependency modules.
   */
  public function setUp() {
    parent::setUp('crm_core_activity_ui');
  }

  /**
   * Test basic UI operations with Activities.
   *
   * Create a contact.
   * Add activity of every type to contact.
   * Assert activities listed on Activities tab listing page.
   * Edit every activity. Assert activities changed from listing page.
   * Delete every activity. Assert they disappeared from listing page.
   */
  public function testActivityOperations() {

    // Create and login user.
    // User should be able to create contacts and activities.
    $user = $this
      ->drupalCreateUser(array(
      'administer crm_core_contact entities',
      'view any crm_core_contact entity',
      'administer crm_core_activity entities',
      'view any crm_core_activity entity',
    ));
    $this
      ->drupalLogin($user);

    // Create Houshold contact.
    $household_contact = array(
      'contact_name[und][0][family]' => $this
        ->randomName(),
    );
    $this
      ->drupalPost('crm-core/contact/add/household', $household_contact, t('Save Household'));
    $this
      ->drupalGet('crm-core/contact/1/activity');
    $this
      ->assertText(t('There are no activities available.'), t('No activities avaiable for newly created contact.'));
    $this
      ->assertLink(t('Add an activity'));
    $this
      ->drupalGet('crm-core/contact/1/activity/add');
    $this
      ->assertLink(t('Meeting'));
    $this
      ->assertLink(t('Phone call'));

    // Create Meeting activity. Ensure it it listed.
    $meeting_activity = array(
      'title' => $this
        ->randomName(),
      'field_activity_date[und][0][value][date]' => $this
        ->randomDate(),
      'field_activity_date[und][0][value][time]' => $this
        ->randomTime(),
      'field_activity_notes[und][0][value]' => $this
        ->randomString(),
    );
    $this
      ->drupalPost('crm-core/contact/1/activity/add/meeting', $meeting_activity, t('Save Activity'));
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors after adding new activity.'));

    // Create Meeting activity. Ensure it it listed.
    $phonecall_activity = array(
      'title' => $this
        ->randomName(),
      'field_activity_date[und][0][value][date]' => $this
        ->randomDate(),
      'field_activity_date[und][0][value][time]' => $this
        ->randomTime(),
      'field_activity_notes[und][0][value]' => $this
        ->randomString(),
    );
    $this
      ->drupalPost('crm-core/contact/1/activity/add/phone_call', $phonecall_activity, t('Save Activity'));
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors after adding new activity.'));

    // Update activity and assert its title changed on the list.
    $meeting_activity = array(
      'title' => $this
        ->randomName(),
      'field_activity_date[und][0][value][date]' => $this
        ->randomDate(),
      'field_activity_date[und][0][value][time]' => $this
        ->randomTime(),
      'field_activity_notes[und][0][value]' => $this
        ->randomString(),
    );
    $this
      ->drupalPost('crm-core/activity/1/edit', $meeting_activity, t('Save Activity'));
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors after updating activity.'));
    $this
      ->assertText($meeting_activity['title'], t('Activity updated.'));
    $this
      ->drupalGet('crm-core/contact/1/activity');
    $this
      ->assertRaw($meeting_activity['title'], t('Updated activity listed properly.'));

    // Update phone call activity and assert its title changed on the list.
    $phonecall_activity = array(
      'title' => $this
        ->randomName(),
      'field_activity_date[und][0][value][date]' => $this
        ->randomDate(),
      'field_activity_date[und][0][value][time]' => $this
        ->randomTime(),
      'field_activity_notes[und][0][value]' => $this
        ->randomString(),
    );
    $this
      ->drupalPost('crm-core/activity/2/edit', $phonecall_activity, t('Save Activity'));
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors after updating activity.'));
    $this
      ->assertText($phonecall_activity['title'], t('Activity updated.'));
    $this
      ->drupalGet('crm-core/contact/1/activity');
    $this
      ->assertRaw($phonecall_activity['title'], t('Updated activity listed properly.'));

    // Delete Meeting activity.
    $this
      ->drupalPost('crm-core/activity/1/delete', array(), t('Delete'));
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors after deleting activity.'));
    $this
      ->assertNoRaw($meeting_activity['title'] . ' </td>', t('Deleted activity is no more listed.'));

    // Delete Phone call activity.
    $this
      ->drupalPost('crm-core/activity/2/delete', array(), t('Delete'));
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors after deleting activity.'));
    $this
      ->drupalGet('crm-core/contact/1/activity');
    $this
      ->assertNoRaw($phonecall_activity['title'] . ' </td>', t('Deleted activity is no more listed.'));

    // Assert there is no activities left.
    $this
      ->drupalGet('crm-core/contact/1/activity');
    $this
      ->assertText(t('There are no activities available.'), t('No activities listed.'));
  }

  /**
   * Generate random Date for form element input.
   */
  function randomDate() {
    return format_date(REQUEST_TIME + rand(0, 100000), 'custom', 'm/d/Y');
  }

  /**
   * Generate random Time for form element input.
   */
  function randomTime() {
    return rand(0, 23) . ':' . rand(0, 60);
  }

}

Classes

Namesort descending Description
CRMCoreActivityUITestCase Activity UI test case.