-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cover for subscription history create
- Loading branch information
1 parent
60a8f75
commit 2f2ca94
Showing
2 changed files
with
54 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
use Civi\Api4\SubscriptionHistory; | ||
|
||
/** | ||
* Class api_v3_GroupContactTest | ||
* @group headless | ||
|
@@ -36,8 +38,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { | |
*/ | ||
public function setUp(): void { | ||
parent::setUp(); | ||
$this->useTransaction(TRUE); | ||
|
||
$this->_contactId = $this->individualCreate(); | ||
|
||
$this->_groupId1 = $this->groupCreate(); | ||
|
@@ -70,6 +70,14 @@ public function setUp(): void { | |
]; | ||
} | ||
|
||
/** | ||
* Cleanup after test. | ||
*/ | ||
public function tearDown(): void { | ||
$this->quickCleanup(['civicrm_group', 'civicrm_group_contact', 'civicrm_subscription_history']); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Test GroupContact.get by ID. | ||
*/ | ||
|
@@ -101,67 +109,43 @@ public function testGetGroupID() { | |
} | ||
} | ||
|
||
public function testCreateWithEmptyParams() { | ||
$params = []; | ||
$groups = $this->callAPIFailure('group_contact', 'create', $params); | ||
$this->assertEquals($groups['error_message'], | ||
'Mandatory key(s) missing from params array: group_id, contact_id' | ||
); | ||
} | ||
|
||
public function testCreateWithoutGroupIdParams() { | ||
$params = [ | ||
'contact_id' => $this->_contactId, | ||
]; | ||
|
||
$groups = $this->callAPIFailure('group_contact', 'create', $params); | ||
$this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); | ||
} | ||
|
||
public function testCreateWithoutContactIdParams() { | ||
$params = [ | ||
'group_id' => $this->_groupId1, | ||
]; | ||
$groups = $this->callAPIFailure('group_contact', 'create', $params); | ||
$this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); | ||
} | ||
|
||
public function testCreate() { | ||
$cont = [ | ||
/** | ||
* Test group contact create. | ||
*/ | ||
public function testCreate(): void { | ||
$this->_contactId1 = $this->individualCreate([ | ||
'first_name' => 'Amiteshwar', | ||
'middle_name' => 'L.', | ||
'last_name' => 'Prasad', | ||
'prefix_id' => 3, | ||
'suffix_id' => 3, | ||
'email' => '[email protected]', | ||
'contact_type' => 'Individual', | ||
]; | ||
|
||
$this->_contactId1 = $this->individualCreate($cont); | ||
]); | ||
$params = [ | ||
'contact_id' => $this->_contactId, | ||
'contact_id.2' => $this->_contactId1, | ||
'group_id' => $this->_groupId1, | ||
]; | ||
|
||
$result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); | ||
$this->assertEquals($result['not_added'], 1); | ||
$this->assertEquals($result['added'], 1); | ||
$this->assertEquals($result['total_count'], 2); | ||
$result = $this->callAPIAndDocument('GroupContact', 'create', $params, __FUNCTION__, __FILE__); | ||
$this->assertEquals(1, $result['not_added']); | ||
$this->assertEquals(1, $result['added']); | ||
$this->assertEquals(2, $result['total_count']); | ||
} | ||
|
||
/** | ||
* Test GroupContact.delete by contact+group ID. | ||
*/ | ||
public function testDelete() { | ||
public function testDelete(): void { | ||
$params = [ | ||
'contact_id' => $this->_contactId, | ||
'group_id' => $this->_groupId1, | ||
]; | ||
|
||
$result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); | ||
$this->assertEquals($result['removed'], 1); | ||
$this->assertEquals($result['total_count'], 1); | ||
$this->assertEquals(1, $result['removed']); | ||
$this->assertEquals(1, $result['total_count']); | ||
} | ||
|
||
public function testDeletePermanent() { | ||
|
@@ -219,9 +203,16 @@ public function testDeleteAndReAddWithId() { | |
} | ||
|
||
/** | ||
* CRM-19979 test that group cotnact delete action works when contact is in status of pendin. | ||
* CRM-19979 test that group contact delete action works when contact is in | ||
* status of pending. | ||
* | ||
* @param int $version | ||
* | ||
* @dataProvider versionThreeAndFour | ||
* @throws \API_Exception | ||
*/ | ||
public function testDeleteWithPending() { | ||
public function testDeleteWithPending(int $version): void { | ||
$this->_apiversion = $version; | ||
$groupId3 = $this->groupCreate([ | ||
'name' => 'Test Group 3', | ||
'domain_id' => 1, | ||
|
@@ -235,11 +226,19 @@ public function testDeleteWithPending() { | |
'group_id' => $groupId3, | ||
'status' => 'Pending', | ||
]; | ||
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams); | ||
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams); | ||
$this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'status' => 'Removed']); | ||
$this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]); | ||
$this->callAPISuccess('group', 'delete', ['id' => $groupId3]); | ||
$this->callAPISuccess('GroupContact', 'create', $groupContactCreateParams); | ||
$groupGetContact = $this->CallAPISuccess('GroupContact', 'get', $groupContactCreateParams); | ||
$history = SubscriptionHistory::get() | ||
->addSelect('*') | ||
->addWhere('group_id', '=', $groupId3) | ||
->addWhere('status', '=', 'Pending') | ||
->addWhere('contact_id', '=', $this->_contactId) | ||
->execute(); | ||
$this->assertCount(1, $history); | ||
$this->callAPISuccess('GroupContact', 'delete', ['id' => $groupGetContact['id'], 'status' => 'Removed']); | ||
$this->callAPISuccess('GroupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]); | ||
$this->callAPISuccess('Group', 'delete', ['id' => $groupId3]); | ||
|
||
} | ||
|
||
/** | ||
|