Merge pull request #10946 from mattwire/CRM-21037_activity_sendsms_unittests
[civicrm-core.git] / tests / phpunit / api / v3 / JobTest.php
index 400ef2d0d12cd96d31b037e074580a79f2c703bc..c42d29017f7c06fd2e086ed4dc7d6be82855f8a0 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -31,7 +31,7 @@
  * @package CiviCRM_APIv3
  * @subpackage API_Job
  *
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
  */
 
 /**
@@ -882,6 +882,28 @@ class api_v3_JobTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test the batch merge copes with view only custom data field.
+   */
+  public function testBatchMergeCustomDataViewOnlyField() {
+    CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact');
+    $mouseParams = ['first_name' => 'Mickey', 'last_name' => 'Mouse', 'email' => 'tha_mouse@mouse.com'];
+    $this->individualCreate($mouseParams);
+
+    $customGroup = $this->CustomGroupCreate();
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'], 'is_view' => 1));
+    $this->individualCreate(array_merge($mouseParams, ['custom_' . $customField['id'] => 'blah']));
+
+    $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0, 'mode' => 'safe'));
+    $this->assertEquals(1, count($result['values']['merged']));
+    $mouseParams['return'] = 'custom_' . $customField['id'];
+    $mouse = $this->callAPISuccess('Contact', 'getsingle', $mouseParams);
+    $this->assertEquals('blah', $mouse['custom_' . $customField['id']]);
+
+    $this->customFieldDelete($customGroup['id']);
+    $this->customGroupDelete($customGroup['id']);
+  }
+
   /**
    * Test the batch merge function actually works!
    *
@@ -1680,4 +1702,34 @@ class api_v3_JobTest extends CiviUnitTestCase {
     return $data;
   }
 
+  /**
+   * Test processing membership for deceased contacts.
+   */
+  public function testProcessMembership() {
+    $this->callAPISuccess('Job', 'process_membership', []);
+    $deadManWalkingID = $this->individualCreate();
+    $membershipID = $this->contactMembershipCreate(array('contact_id' => $deadManWalkingID));
+    $this->callAPISuccess('Contact', 'create', ['id' => $deadManWalkingID, 'is_deceased' => 1]);
+    $this->callAPISuccess('Job', 'process_membership', []);
+    $membership = $this->callAPISuccessGetSingle('Membership', ['id' => $membershipID]);
+    $deceasedStatusId = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Deceased');
+    $this->assertEquals($deceasedStatusId, $membership['status_id']);
+  }
+
+  /**
+   * Test we get an error is deceased status is disabled.
+   */
+  public function testProcessMembershipNoDeceasedStatus() {
+    $deceasedStatusId = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Deceased');
+    $this->callAPISuccess('MembershipStatus', 'create', ['is_active' => 0, 'id' => $deceasedStatusId]);
+    CRM_Core_PseudoConstant::flush();
+
+    $deadManWalkingID = $this->individualCreate();
+    $this->contactMembershipCreate(array('contact_id' => $deadManWalkingID));
+    $this->callAPISuccess('Contact', 'create', ['id' => $deadManWalkingID, 'is_deceased' => 1]);
+    $this->callAPIFailure('Job', 'process_membership', []);
+
+    $this->callAPISuccess('MembershipStatus', 'create', ['is_active' => 1, 'id' => $deceasedStatusId]);
+  }
+
 }