You are here

crm_core_relationship_ui.test in CRM Core 7

File

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

class CRMCoreRelationshipUITestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => t('Relationship UI'),
      'description' => t('Test create/edit/delete relations.'),
      'group' => t('CRM Core'),
    );
  }

  /**
   * Enable dependencies.
   */
  public function setUp() {
    parent::setUp(array(
      'crm_core_contact_ui',
      'crm_core_relationship_ui',
    ));
    module_load_include('test', 'crm_core_contact_ui');
  }
  public function testRelationshipOperations() {
    $user = $this
      ->drupalCreateUser(array(
      'administer crm_core_contact entities',
      'view any crm_core_contact entity',
      'create relation entities of any contact relationship',
      'view relation entities of any contact relationship',
      'edit relation entities of any contact relationship',
    ));
    $this
      ->drupalLogin($user);

    // Create organization and individual contacts.
    $individual_contact = CRMCoreContactUITestCase::individualContactValues();
    $this
      ->drupalPost('crm-core/contact/add/individual', $individual_contact, crm_core_contact_ui_save_contact_button_name('individual'));
    $organization_contact = CRMCoreContactUITestCase::organizationContactValues();
    $this
      ->drupalPost('crm-core/contact/add/organization', $organization_contact, crm_core_contact_ui_save_contact_button_name('organization'));

    // Ensure Relationships tab on contact view page.
    $this
      ->drupalGet('crm-core/contact/1');
    $this
      ->assertLink(t('Relationships'));
    $this
      ->drupalGet('crm-core/contact/1/relationships');
    $this
      ->assertNoRaw('<div class="messages error">', t('No errors on Relationships page.'));

    // Assert link "Add Relationship".
    $this
      ->assertLink(t('Add a relationship'));

    // Assert standard relationship types.
    $this
      ->drupalGet('crm-core/contact/1/relationships/add');
    $this
      ->assertLink(t('works for'));
    $this
      ->assertLink(t('is friends with'));
    $this
      ->assertLink(t('is a member of'));

    // Create relationship "Employer of".
    $values = array(
      'destination_contact' => CRMCoreContactUITestCase::getOrganizationContactTitle($organization_contact) . ' [cid:2]',
    );
    $this
      ->drupalPost('crm-core/contact/1/relationships/add/crm_employee/0', $values, t('Save Relationship'));

    // Go to relationships list of the individual and ensure that
    // Organization link is there.
    $this
      ->drupalGet('crm-core/contact/1/relationships');
    $this
      ->assertLink(CRMCoreContactUITestCase::getOrganizationContactTitle($organization_contact));

    // Go to relationships list of the individual and ensure that
    // Organization link is there.
    $this
      ->drupalGet('crm-core/contact/2/relationships');
    $this
      ->assertLink(CRMCoreContactUITestCase::getIndividualContactTitle($individual_contact));
  }

}

Classes