From 45cebbe4dace7513c4f3005b8ad2e37d9dd757ce Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 31 May 2017 15:42:47 -0700 Subject: [PATCH] CRM-20642 - Activity.get - Add test for `case_id IS NULL` CRM-20642 requires an option for displaying "activities which are *not* case-related" (i.e. `case_id IS NULL`) . This adds a unit-test for ensuring that the filter works as expected. --- tests/phpunit/api/v3/ActivityCaseTest.php | 80 +++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/phpunit/api/v3/ActivityCaseTest.php diff --git a/tests/phpunit/api/v3/ActivityCaseTest.php b/tests/phpunit/api/v3/ActivityCaseTest.php new file mode 100644 index 0000000000..9f8a2a31e9 --- /dev/null +++ b/tests/phpunit/api/v3/ActivityCaseTest.php @@ -0,0 +1,80 @@ +_entity = 'case'; + + parent::setUp(); + + $this->_cid = $this->individualCreate(); + + $this->_case = $this->callAPISuccess('case', 'create', array( + 'case_type_id' => $this->caseTypeId, + 'subject' => __CLASS__, + 'contact_id' => $this->_cid, + )); + + $this->_otherActivity = $this->callAPISuccess('Activity', 'create', array( + 'source_contact_id' => $this->_cid, + 'activity_type_id' => 'Phone Call', + 'subject' => 'Ask not what your API can do for you, but what you can do for your API.', + )); + } + + public function testGet() { + $this->assertTrue(is_numeric($this->_case['id'])); + $this->assertTrue(is_numeric($this->_otherActivity['id'])); + + $getByCaseId = $this->callAPIAndDocument('Activity', 'get', array( + 'case_id' => $this->_case['id'], + ), __FUNCTION__, __FILE__); + $this->assertNotEmpty($getByCaseId['values']); + $getByCaseId_ids = array_keys($getByCaseId['values']); + + $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', array( + 'case_id' => array('IS NOT NULL' => 1), + ), __FUNCTION__, __FILE__); + $this->assertNotEmpty($getByCaseNotNull['values']); + $getByCaseNotNull_ids = array_keys($getByCaseNotNull['values']); + + $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', array( + 'case_id' => array('IS NULL' => 1), + ), __FUNCTION__, __FILE__); + $this->assertNotEmpty($getByCaseNull['values']); + $getByCaseNull_ids = array_keys($getByCaseNull['values']); + + $this->assertTrue(in_array($this->_otherActivity['id'], $getByCaseNull_ids)); + $this->assertNotTrue(in_array($this->_otherActivity['id'], $getByCaseId_ids)); + $this->assertEquals($getByCaseId_ids, $getByCaseNotNull_ids); + $this->assertEquals(array(), array_intersect($getByCaseId_ids, $getByCaseNull_ids)); + } + +} -- 2.25.1