View source
<?php
class CRMCoreContactUITestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('Contact UI'),
'description' => t('Test create/edit/delete contacts.'),
'group' => t('CRM Core'),
);
}
public function setUp() {
parent::setUp('crm_core_contact_ui');
}
public function testContactOperations() {
$user = $this
->drupalCreateUser(array(
'administer crm_core_contact entities',
'view any crm_core_contact entity',
));
$this
->drupalLogin($user);
$this
->drupalGet('crm-core/contact');
$this
->assertText(t('There are no contacts available. Add one now.'), t('No contacts available after fresh installation.'));
$this
->assertLink(t('Add a contact'));
$this
->drupalGet('crm-core/contact/add');
$this
->assertLink(t('Add Household'));
$this
->assertLink(t('Add Individual'));
$this
->assertLink(t('Add Organization'));
$household_node = array(
'contact_name[und][0][family]' => $this
->randomName(),
);
$this
->drupalPost('crm-core/contact/add/household', $household_node, crm_core_contact_ui_save_contact_button_name('household'));
$this
->assertUrl('crm-core/contact');
$this
->assertLink($household_node['contact_name[und][0][family]'], 0, t('Newly created contact title listed.'));
$this
->assertText(t('Household'), t('Newly created contact type listed.'));
$individual_node = array(
'contact_name[und][0][title]' => 'Mr.',
'contact_name[und][0][given]' => $this
->randomName(),
'contact_name[und][0][middle]' => $this
->randomName(),
'contact_name[und][0][family]' => $this
->randomName(),
'contact_name[und][0][generational]' => 'IV',
'contact_name[und][0][credentials]' => $this
->randomName(),
);
$this
->drupalPost('crm-core/contact/add/individual', $individual_node, crm_core_contact_ui_save_contact_button_name('individual'));
$this
->assertUrl('crm-core/contact');
$link_label = $this
->getIndividualContactTitle($individual_node);
$this
->assertLink($link_label, 0, t('Newly created contact title listed.'));
$this
->assertText(t('Individual'), t('Newly created contact type listed.'));
$organization_node = array(
'contact_name[und][0][family]' => $this
->randomName(),
);
$this
->drupalPost('crm-core/contact/add/organization', $organization_node, crm_core_contact_ui_save_contact_button_name('organization'));
$this
->assertUrl('crm-core/contact');
$this
->assertLink($organization_node['contact_name[und][0][family]'], 0, t('Newly created contact title listed.'));
$this
->assertText(t('Organization'), t('Newly created contact type listed.'));
$household_node = $this
->householdContactValues();
$this
->drupalPost('crm-core/contact/1/edit', $household_node, crm_core_contact_ui_save_contact_button_name('household'));
$this
->assertUrl('crm-core/contact/1');
$this
->assertText($household_node['contact_name[und][0][family]'], 0, t('Contact updated.'));
$this
->drupalGet('crm-core/contact');
$this
->assertLink($household_node['contact_name[und][0][family]'], 0, t('Updated contact title listed.'));
$this
->drupalPost('crm-core/contact/1/delete', array(), t('Yes'));
$this
->assertUrl('crm-core/contact');
$this
->assertNoLink($household_node['contact_name[und][0][family]'], 0, t('Deleted contact title no more listed.'));
$individual_node = $this
->individualContactValues();
$this
->drupalPost('crm-core/contact/2/edit', $individual_node, crm_core_contact_ui_save_contact_button_name('individual'));
$this
->assertUrl('crm-core/contact/2');
$this
->drupalGet('crm-core/contact');
$link_label = $this
->getIndividualContactTitle($individual_node);
$this
->assertLink($link_label, 0, t('Updated individual contact title listed.'));
$this
->drupalPost('crm-core/contact/2/delete', array(), t('Yes'));
$this
->assertUrl('crm-core/contact');
$this
->assertNoLink($link_label, 0, t('Deleted individual contact title no more listed.'));
$organization_node = $this
->organizationContactValues();
$this
->drupalPost('crm-core/contact/3/edit', $organization_node, crm_core_contact_ui_save_contact_button_name('organization'));
$this
->assertUrl('crm-core/contact/3');
$this
->assertText($organization_node['contact_name[und][0][family]'], 0, t('Contact updated.'));
$this
->drupalGet('crm-core/contact');
$this
->assertLink($organization_node['contact_name[und][0][family]'], 0, t('Updated contact title listed.'));
$this
->drupalPost('crm-core/contact/3/delete', array(), t('Yes'));
$this
->assertUrl('crm-core/contact');
$this
->assertNoLink($organization_node['contact_name[und][0][family]'], 0, t('Deleted contact title no more listed.'));
$this
->assertText(t('There are no contacts available. Add one now.'), t('No contacts available after fresh installation.'));
}
public static function getIndividualContactTitle($post_array) {
return $post_array['contact_name[und][0][title]'] . ' ' . $post_array['contact_name[und][0][given]'] . ' ' . $post_array['contact_name[und][0][middle]'] . ' ' . $post_array['contact_name[und][0][family]'] . ' ' . $post_array['contact_name[und][0][generational]'] . ', ' . $post_array['contact_name[und][0][credentials]'];
}
public static function individualContactValues() {
return array(
'contact_name[und][0][title]' => 'Ms.',
'contact_name[und][0][given]' => DrupalTestCase::randomName(),
'contact_name[und][0][middle]' => DrupalTestCase::randomName(),
'contact_name[und][0][family]' => DrupalTestCase::randomName(),
'contact_name[und][0][generational]' => 'Jr.',
'contact_name[und][0][credentials]' => DrupalTestCase::randomName(),
);
}
public static function householdContactValues() {
return array(
'contact_name[und][0][family]' => DrupalTestCase::randomName(),
);
}
public static function getOrganizationContactTitle($organization_values) {
return $organization_values['contact_name[und][0][family]'];
}
public static function organizationContactValues() {
return array(
'contact_name[und][0][family]' => DrupalTestCase::randomName(),
);
}
}