Commit | Line | Data |
---|---|---|
45cebbe4 TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * Test Activity.get API with the case_id field | |
5 | * | |
6 | * @package CiviCRM_APIv3 | |
7 | * @group headless | |
8 | */ | |
9 | class api_v3_ActivityCaseTest extends CiviCaseTestCase { | |
10 | protected $_params; | |
11 | protected $_entity; | |
12 | protected $_cid; | |
13 | ||
14 | /** | |
15 | * @var array | |
16 | * APIv3 Result (Case.create) | |
17 | */ | |
18 | protected $_case; | |
19 | ||
20 | /** | |
21 | * @var array | |
22 | * APIv3 Result (Activity.create) | |
23 | */ | |
24 | protected $_otherActivity; | |
25 | ||
26 | /** | |
27 | * Test setup for every test. | |
28 | * | |
29 | * Connect to the database, truncate the tables that will be used | |
30 | * and redirect stdin to a temporary file. | |
31 | */ | |
32 | public function setUp() { | |
33 | $this->_entity = 'case'; | |
34 | ||
35 | parent::setUp(); | |
36 | ||
37 | $this->_cid = $this->individualCreate(); | |
38 | ||
39 | $this->_case = $this->callAPISuccess('case', 'create', array( | |
40 | 'case_type_id' => $this->caseTypeId, | |
41 | 'subject' => __CLASS__, | |
42 | 'contact_id' => $this->_cid, | |
43 | )); | |
44 | ||
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.', | |
49 | )); | |
50 | } | |
51 | ||
52 | public function testGet() { | |
53 | $this->assertTrue(is_numeric($this->_case['id'])); | |
54 | $this->assertTrue(is_numeric($this->_otherActivity['id'])); | |
55 | ||
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']); | |
61 | ||
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']); | |
67 | ||
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']); | |
73 | ||
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)); | |
78 | } | |
79 | ||
80 | } |