Merge pull request #10393 from JMAConsulting/exportBatch
[civicrm-core.git] / tests / phpunit / api / v3 / OptionGroupTest.php
index b226500e47b7e77fd240a8e6bd0943d6fb341daf..e9878770778ee831441803a4b1b7b9b75dfff62e 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
 | CiviCRM version 4.7                                                |
 +--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2015                                |
+| Copyright CiviCRM LLC (c) 2004-2017                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
@@ -27,6 +27,7 @@
 
 /**
  * Class api_v3_OptionGroupTest
+ * @group headless
  */
 class api_v3_OptionGroupTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
@@ -168,4 +169,26 @@ class api_v3_OptionGroupTest extends CiviUnitTestCase {
     $this->callAPIAndDocument('OptionGroup', 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
   }
 
+  /**
+   * Ensure only one option value exists after calling ensureOptionValueExists.
+   */
+  public function testEnsureOptionGroupExistsExistingValue() {
+    CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'participant_role'));
+    $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'participant_role'));
+  }
+
+  /**
+   * Ensure only one option value exists adds a new value.
+   */
+  public function testEnsureOptionGroupExistsNewValue() {
+    $optionGroupID = CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array(
+      'name' => 'Bombed',
+      'title' => ts('Catastrophy'),
+      'description' => ts('blah blah'),
+      'is_reserved' => 1,
+    ));
+    $optionGroup = $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'Bombed'));
+    $this->assertEquals($optionGroupID, $optionGroup['id']);
+  }
+
 }