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.',
52 public function testGet() {
53 $this->assertTrue(is_numeric($this->_case
['id']));
54 $this->assertTrue(is_numeric($this->_otherActivity
['id']));
56 $getByCaseId = $this->callAPIAndDocument('Activity', 'get', array(
57 'case_id' => $this->_case
['id'],
58 ), __FUNCTION__
, __FILE__
);
59 $this->assertNotEmpty($getByCaseId['values']);
60 $getByCaseId_ids = array_keys($getByCaseId['values']);
62 $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', array(
63 'case_id' => array('IS NOT NULL' => 1),
64 ), __FUNCTION__
, __FILE__
);
65 $this->assertNotEmpty($getByCaseNotNull['values']);
66 $getByCaseNotNull_ids = array_keys($getByCaseNotNull['values']);
68 $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', array(
69 'case_id' => array('IS NULL' => 1),
70 ), __FUNCTION__
, __FILE__
);
71 $this->assertNotEmpty($getByCaseNull['values']);
72 $getByCaseNull_ids = array_keys($getByCaseNull['values']);
74 $this->assertTrue(in_array($this->_otherActivity
['id'], $getByCaseNull_ids));
75 $this->assertNotTrue(in_array($this->_otherActivity
['id'], $getByCaseId_ids));
76 $this->assertEquals($getByCaseId_ids, $getByCaseNotNull_ids);
77 $this->assertEquals(array(), array_intersect($getByCaseId_ids, $getByCaseNull_ids));