Skip to content

Commit

Permalink
extended unit test to asset contact custom field token
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Jan 13, 2017
1 parent 8640061 commit 2273ddc
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,28 @@ public function setUp() {
'subject' => 'subject send reminder every unit after membership_end_date',
);

$customGroup = $this->callAPISuccess('CustomGroup', 'create', array(
'title' => ts('Test Contact Custom group'),
'name' => 'test_contact_cg',
'extends' => 'Contact',
'domain_id' => CRM_Core_Config::domainID(),
'is_active' => 1,
'collapse_adv_display' => 0,
'collapse_display' => 0,
));
$customField = $this->callAPISuccess('CustomField', 'create', array(
'label' => 'Test Text',
'data_type' => 'String',
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
));
$this->fixtures['contact_custom_token'] = array(
'id' => $customField['id'],
'token' => sprintf('{contact.custom_%s}', $customField['id']),
'name' => sprintf('custom_%s', $customField['id']),
'value' => 'text ' . substr(sha1(rand()), 0, 7),
);

$this->_setUp();
}

Expand All @@ -616,6 +638,10 @@ public function tearDown() {
'civicrm_event',
'civicrm_email',
));
$this->callAPISuccess('CustomField', 'delete', array('id' => $this->fixtures['contact_custom_token']['id']));
$this->callAPISuccess('CustomGroup', 'delete', array(
'id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'test_contact_cg', 'id', 'name'),
));
$this->_tearDown();
}

Expand All @@ -634,11 +660,12 @@ public function mailerExamples() {
$manyTokensTmpl = implode(';;', array(
$someTokensTmpl,
'{contact.email_greeting}',
$this->fixture['contact_custom_token']['token'],
));
// Note: The behavior of domain-tokens on a scheduled reminder is undefined. All we
// can really do is check that it has something.
$someTokensExpected = 'Churmondleia Ōtākou;;Female;;Female;;[a-zA-Z0-9 ]+;;Phone Call';
$manyTokensExpected = "$someTokensExpected;;Dear Churmondleia";
$manyTokensExpected = sprintf('%s;;Dear Churmondleia;;%s', $someTokensExpected, $this->fixture['contact_custom_token']['value']);

// In this example, we use a lot of tokens cutting across multiple components.
$cases[0] = array(
Expand Down Expand Up @@ -725,7 +752,12 @@ public function testMailer($schedule, $patterns) {

$activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phonecall']);
$this->assertTrue(is_numeric($activity->id));
$contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']);
$contact = $this->callAPISuccess('contact', 'create', array_merge(
$this->fixtures['contact'],
array(
$this->fixtures['contact_custom_token']['name'] => $this->fixtures['contact_custom_token']['value'],
)
));
$activity->save();

$source['contact_id'] = $contact['id'];
Expand Down

0 comments on commit 2273ddc

Please sign in to comment.