Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[civicrm-core.git] / tests / phpunit / api / v3 / GroupContactTest.php
index 3283d88b357f7fbdd6728c38fc03b261def3f5a8..695d207cdcfd4436406cd33f2a7b3d0f59c570cf 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -86,8 +86,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
     );
   }
 
-  ///////////////// civicrm_group_contact_get methods
-
   /**
    * Test GroupContact.get by ID.
    */
@@ -168,8 +166,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
     $this->assertEquals($result['total_count'], 2);
   }
 
-  ///////////////// civicrm_group_contact_remove methods
-
   /**
    * Test GroupContact.delete by contact+group ID.
    */
@@ -238,6 +234,53 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
     $this->assertEquals($result2['total_count'], 1);
   }
 
+  /**
+   * CRM-19979 test that group cotnact delete action works when contact is in status of pendin.
+   */
+  public function testDeleteWithPending() {
+    $groupId3 = $this->groupCreate(array(
+      'name' => 'Test Group 3',
+      'domain_id' => 1,
+      'title' => 'New Test Group3 Created',
+      'description' => 'New Test Group3 Created',
+      'is_active' => 1,
+      'visibility' => 'User and User Admin Only',
+    ));
+    $groupContactCreateParams = array(
+      'contact_id' => $this->_contactId,
+      'group_id' => $groupId3,
+      'status' => 'Pending',
+    );
+    $groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
+    $groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
+    $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'status' => 'Removed'));
+    $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE));
+    $this->callAPISuccess('group', 'delete', array('id' => $groupId3));
+  }
+
+  /**
+   * CRM-19979 test that group cotnact delete action works when contact is in status of pendin and is a permanent delete.
+   */
+  public function testPermanentDeleteWithPending() {
+    $groupId3 = $this->groupCreate(array(
+      'name' => 'Test Group 3',
+      'domain_id' => 1,
+      'title' => 'New Test Group3 Created',
+      'description' => 'New Test Group3 Created',
+      'is_active' => 1,
+      'visibility' => 'User and User Admin Only',
+    ));
+    $groupContactCreateParams = array(
+      'contact_id' => $this->_contactId,
+      'group_id' => $groupId3,
+      'status' => 'Pending',
+    );
+    $groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
+    $groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
+    $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE));
+    $this->callAPISuccess('group', 'delete', array('id' => $groupId3));
+  }
+
   /**
    * CRM-16945 duplicate groups are showing up when contacts are hard-added to child groups or smart groups.
    *