crm_core_contact.test in CRM Core 7
File
modules/crm_core_contact/tests/crm_core_contact.test
View source
<?php
class CRMCoreContactTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Contact types',
'description' => 'Tests for contact types.',
'group' => 'CRM Core',
);
}
function setUp() {
parent::setUp(array(
'crm_core_contact',
));
}
function testCRUD() {
$type = 'dog';
$contact_type = crm_core_contact_type_new($type);
$this
->assertTrue(isset($contact_type->description) && empty($contact_type->description), t('New contact type description exists.'));
$this
->assertTrue(isset($contact_type->name) && empty($contact_type->name), t('New contact type name exists.'));
$this
->assertTrue(isset($contact_type->type) && $contact_type->type == $type, t('New contact type type exists.'));
$contact_type->name = $this
->randomName();
$contact_type->description = $this
->randomString();
crm_core_contact_type_save($contact_type);
$contact_type_load = crm_core_contact_type_load($type);
$this
->assertEqual($contact_type->type, $contact_type_load->type, t('Loaded contact type has same type.'));
$this
->assertEqual($contact_type->name, $contact_type_load->name, t('Loaded contact type has same name.'));
$this
->assertEqual($contact_type->description, $contact_type_load->description, t('Loaded contact type has same description.'));
$this
->assertTrue(!empty($contact_type_load->id), 'Loaded contact type has id.');
$new_description = $this
->randomString();
$contact_type_load = crm_core_contact_type_load($type);
$contact_type_load->description = $new_description;
crm_core_contact_type_save($contact_type_load);
$contact_type_load_updated = crm_core_contact_type_load($type);
$this
->assertEqual($new_description, $contact_type_load_updated->description, 'Updated contact type description match.');
crm_core_contact_type_delete($contact_type->id);
$contact_type_load = crm_core_contact_type_load($type, TRUE);
$this
->assertTrue(empty($contact_type_load), t('Contact type deleted.'));
}
}