CRM-15542 - Unit test.
authorJohan Vervloet <johan.vervloet@gmail.com>
Mon, 3 Nov 2014 20:50:41 +0000 (21:50 +0100)
committerJohan Vervloet <johan.vervloet@gmail.com>
Mon, 3 Nov 2014 20:59:24 +0000 (21:59 +0100)
----------------------------------------
* CRM-15542: The api ignores option_group_id when creating a new custom_field.
  https://issues.civicrm.org/jira/browse/CRM-15542

tests/phpunit/api/v3/CustomFieldTest.php

index ef86546086cc5afe0867a9baee1f03b8d0a95d9a..293988a78d02a941ccdf5bb15db2fac84427f780 100644 (file)
@@ -261,6 +261,35 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
     $this->assertEquals(0, $optionValueCount);
   }
 
+  /**
+   * Test custom field with existing option group
+   */
+  function testCustomFieldExistingOptionGroup() {
+    $customGroup = $this->customGroupCreate(array('extends' => 'Organization', 'title' => 'test_group'));
+    $params = array(
+      'custom_group_id' => $customGroup['id'],
+      // Just to say something:
+      'label' => 'Organization Gender',
+      'html_type' => 'Select',
+      'data_type' => 'Int',
+      'weight' => 4,
+      'is_required' => 1,
+      'is_searchable' => 0,
+      'is_active' => 1,
+      // Option group id 3: gender
+      'option_group_id' => 3,
+    );
+
+    $customField = $this->callAPISuccess('custom_field', 'create', $params);
+    $this->assertNotNull($customField['id']);
+    $optionGroupID = $this->callAPISuccess('custom_field', 'getvalue', array(
+      'id' => $customField['id'],
+      'return' => 'option_group_id',
+    ));
+
+    $this->assertEquals($optionGroupID,3);
+  }
+
 
   /**
    * Test custom field get works & return param works