Make domain_id optional in membership_type api.
authoreileen <emcnaughton@wikimedia.org>
Fri, 13 Jul 2018 03:53:32 +0000 (15:53 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 13 Jul 2018 04:10:05 +0000 (16:10 +1200)
This is in support of #12439 & making domain_id optional

api/v3/MembershipType.php
tests/phpunit/api/v3/MembershipTypeTest.php

index 5011383c689781edb7e60be0b059198d37af4732..82de053cfbd6c204132b81fb07022cd19b5d60ca 100644 (file)
@@ -59,8 +59,7 @@ function civicrm_api3_membership_type_create($params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_membership_type_create_spec(&$params) {
-  // todo could set default here probably
-  $params['domain_id']['api.required'] = 1;
+  $params['domain_id']['api.default'] = CRM_Core_Config::domainID();
   $params['member_of_contact_id']['api.required'] = 1;
   $params['financial_type_id']['api.required'] = 1;
   $params['name']['api.required'] = 1;
index af809934e5ddd2bd4f4b16ac7972be6b46bfae99..1fa73d53a0b36e4e099f94c0a07ce835cbbb66f3 100644 (file)
@@ -126,9 +126,9 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test update fails with no ID.
+   * Domain ID can be intuited..
    */
-  public function testUpdateWithoutId() {
+  public function testCreateWithoutDomainId() {
     $params = array(
       'name' => '60+ Membership',
       'description' => 'people above 60 are given health instructions',
@@ -141,8 +141,18 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
       'visibility' => 'public',
     );
 
-    $membershipType = $this->callAPIFailure('membership_type', 'create', $params);
-    $this->assertEquals($membershipType['error_message'], 'Mandatory key(s) missing from params array: domain_id');
+    $membershipType = $this->callAPISuccess('membership_type', 'create', $params);
+    $domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
+    $this->assertEquals(CRM_Core_Config::domainID(), $domainID);
+
+    $this->callAPISuccess('membership_type', 'create', ['domain_id' => 2, 'id' => $membershipType['id']]);
+    $domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
+    $this->assertEquals(2, $domainID);
+
+    $this->callAPISuccess('membership_type', 'create', ['id' => $membershipType['id'], 'description' => 'Cool member']);
+    $domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
+    $this->assertEquals(2, $domainID);
+
   }
 
   /**