4 * Test Activity.get API with the case_id field
6 * @package CiviCRM_APIv3
9 class api_v3_ActivityCaseTest
extends CiviCaseTestCase
{
16 * APIv3 Result (Case.create)
22 * APIv3 Result (Activity.create)
24 protected $_otherActivity;
27 * Test setup for every test.
29 * Connect to the database, truncate the tables that will be used
30 * and redirect stdin to a temporary file.
32 public function setUp() {
33 $this->_entity
= 'case';
37 $this->_cid
= $this->individualCreate();
39 $this->_case
= $this->callAPISuccess('case', 'create', array(
40 'case_type_id' => $this->caseTypeId
,
41 'subject' => __CLASS__
,
42 'contact_id' => $this->_cid
,
45 $this->_otherActivity
= $this->callAPISuccess('Activity', 'create', array(
46 'source_contact_id' => $this->_cid
,
47 'activity_type_id' => 'Phone Call',
48 'subject' => 'Ask not what your API can do for you, but what you can do for your API.',
53 * Test activity creation on case based
54 * on id or hash present in case subject.
56 public function testActivityCreateOnCase() {
57 $hash = substr(sha1(CIVICRM_SITE_KEY
. $this->_case
['id']), 0, 7);
59 "[case #{$this->_case['id']}] test activity recording under case with id",
60 "[case #{$hash}] test activity recording under case with id",
62 foreach ($subjectArr as $subject) {
63 $activity = $this->callAPISuccess('Activity', 'create', array(
64 'source_contact_id' => $this->_cid
,
65 'activity_type_id' => 'Phone Call',
66 'subject' => $subject,
68 $case = $this->callAPISuccessGetSingle('Activity', array('return' => array("case_id"), 'id' => $activity['id']));
69 //Check if case id is present for the activity.
70 $this->assertEquals($this->_case
['id'], $case['case_id'][0]);
74 public function testGet() {
75 $this->assertTrue(is_numeric($this->_case
['id']));
76 $this->assertTrue(is_numeric($this->_otherActivity
['id']));
78 $getByCaseId = $this->callAPIAndDocument('Activity', 'get', array(
79 'case_id' => $this->_case
['id'],
80 ), __FUNCTION__
, __FILE__
);
81 $this->assertNotEmpty($getByCaseId['values']);
82 $getByCaseId_ids = array_keys($getByCaseId['values']);
84 $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', array(
85 'case_id' => array('IS NOT NULL' => 1),
86 ), __FUNCTION__
, __FILE__
);
87 $this->assertNotEmpty($getByCaseNotNull['values']);
88 $getByCaseNotNull_ids = array_keys($getByCaseNotNull['values']);
90 $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', array(
91 'case_id' => array('IS NULL' => 1),
92 ), __FUNCTION__
, __FILE__
);
93 $this->assertNotEmpty($getByCaseNull['values']);
94 $getByCaseNull_ids = array_keys($getByCaseNull['values']);
96 $this->assertTrue(in_array($this->_otherActivity
['id'], $getByCaseNull_ids));
97 $this->assertNotTrue(in_array($this->_otherActivity
['id'], $getByCaseId_ids));
98 $this->assertEquals($getByCaseId_ids, $getByCaseNotNull_ids);
99 $this->assertEquals(array(), array_intersect($getByCaseId_ids, $getByCaseNull_ids));
102 public function testActivityGetWithCaseInfo() {
103 $activities = $this->callAPISuccess('Activity', 'get', array(
105 'case_id' => $this->_case
['id'],
106 'return' => array('case_id', 'case_id.subject'),
108 $this->assertEquals(__CLASS__
, $activities['values'][0]['case_id.subject']);
109 // Note - case_id is always an array
110 $this->assertEquals($this->_case
['id'], $activities['values'][0]['case_id'][0]);