CRM-15855 - Allow mailings to be saved (but not sent) without name+subject.
[civicrm-core.git] / tests / phpunit / api / v3 / OptionValueTest.php
index 5f783208be80bb88ca2a94a78f9b8c62a6b93ce4..c767a2318ab0396c41405e1801bf427a9a963efb 100644 (file)
@@ -23,7 +23,7 @@
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
-*/
+ */
 
 require_once 'CiviTest/CiviUnitTestCase.php';
 
@@ -33,7 +33,7 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 class api_v3_OptionValueTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
 
-  function setUp() {
+  public function setUp() {
     parent::setUp();
     $this->useTransaction(TRUE);
   }
@@ -58,7 +58,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   /**
    *  Test limit param
    */
-  function testGetOptionValueLimit() {
+  public function testGetOptionValueLimit() {
     $params = array();
     $result = $this->callAPISuccess('option_value', 'get', $params);
     $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__);
@@ -70,33 +70,36 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   /**
    *  Test offset param
    */
-  function testGetOptionValueOffSet() {
+  public function testGetOptionValueOffSet() {
 
     $result = $this->callAPISuccess('option_value', 'get', array(
       'option_group_id' => 1,
-       'value' => '1',      ));
+      'value' => '1',
+    ));
     $result2 = $this->callAPISuccess('option_value', 'get', array(
       'option_group_id' => 1,
-        'value' => '1',
-        'options' => array('offset' => 1),
-      ));
+      'value' => '1',
+      'options' => array('offset' => 1),
+    ));
     $this->assertGreaterThan($result2['count'], $result['count']);
   }
 
   /**
    *  Test offset param
    */
-  function testGetSingleValueOptionValueSort() {
+  public function testGetSingleValueOptionValueSort() {
     $description = "demonstrates use of Sort param (available in many api functions). Also, getsingle";
-    $subfile     = 'SortOption';
-    $result      = $this->callAPISuccess('option_value', 'getsingle', array(
-      'option_group_id' => 1,        'options' => array(
-          'sort' => 'label ASC',
-          'limit' => 1,
-        ),
-      ));
+    $subfile = 'SortOption';
+    $result = $this->callAPISuccess('option_value', 'getsingle', array(
+      'option_group_id' => 1,
+      'options' => array(
+        'sort' => 'label ASC',
+        'limit' => 1,
+      ),
+    ));
     $params = array(
-      'option_group_id' => 1,      'options' => array(
+      'option_group_id' => 1,
+      'options' => array(
         'sort' => 'label DESC',
         'limit' => 1,
       ),
@@ -108,14 +111,16 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   /**
    * Try to emulate a pagination: fetch the first page of 10 options, then fetch the second page with an offset of 9 (instead of 10) and check the start of the second page is the end of the 1st one.
    */
-  function testGetValueOptionPagination() {
+  public function testGetValueOptionPagination() {
     $pageSize = 10;
-    $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize),      ));
+    $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize)));
     $page2 = $this->callAPISuccess('option_value', 'get', array(
-      'options' => array('limit' => $pageSize,
-          // if you use it for pagination, option.offset=pageSize*pageNumber
-          'offset' => $pageSize - 1,
-        ),      ));
+      'options' => array(
+        'limit' => $pageSize,
+        // if you use it for pagination, option.offset=pageSize*pageNumber
+        'offset' => $pageSize - 1,
+      ),
+    ));
     $this->assertEquals($pageSize, $page1['count'], "Check only 10 retrieved in the 1st page " . __LINE__);
     $this->assertEquals($pageSize, $page2['count'], "Check only 10 retrieved in the 2nd page " . __LINE__);
 
@@ -156,7 +161,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
       'name' => 'from_email_address',
       'sequential' => 1,
       'api.option_value.create' => array('domain_id' => 2, 'name' => 'my@y.com'),
-      ));
+    ));
 
     $optionValueId = $result['values'][0]['api.option_value.create']['id'];
     $domain_id = $this->callAPISuccess('option_value', 'getvalue', array(
@@ -172,12 +177,14 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   public function testCreateOptionSpecifyComponentID() {
     $result = $this->callAPISuccess('option_group', 'get', array(
       'name' => 'from_email_address',
-      'sequential' => 1,      'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'),
+      'sequential' => 1,
+      'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'),
     ));
     $this->assertAPISuccess($result);
     $optionValueId = $result['values'][0]['api.option_value.create']['id'];
     $component_id = $this->callAPISuccess('option_value', 'getvalue', array(
-      'id' => $optionValueId,      'return' => 'component_id',
+      'id' => $optionValueId,
+      'return' => 'component_id',
     ));
     $this->assertEquals(2, $component_id);
   }
@@ -188,16 +195,18 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   public function testCreateOptionSpecifyComponent() {
     $result = $this->callAPISuccess('option_group', 'get', array(
       'name' => 'from_email_address',
-      'sequential' => 1,      'api.option_value.create' => array(
+      'sequential' => 1,
+      'api.option_value.create' => array(
         'component_id' => 'CiviContribute',
-        'name' => 'my@y.com'
-       ),
+        'name' => 'my@y.com',
+      ),
 
     ));
     $this->assertAPISuccess($result);
     $optionValueId = $result['values'][0]['api.option_value.create']['id'];
     $component_id = $this->callAPISuccess('option_value', 'getvalue', array(
-      'id' => $optionValueId,      'return' => 'component_id',
+      'id' => $optionValueId,
+      'return' => 'component_id',
     ));
     $this->assertEquals(2, $component_id);
   }
@@ -208,15 +217,18 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   public function testCreateOptionSpecifyComponentString() {
     $result = $this->callAPISuccess('option_group', 'get', array(
       'name' => 'from_email_address',
-      'sequential' => 1,      'api.option_value.create' => array(
+      'sequential' => 1,
+      'api.option_value.create' => array(
         'component_id' => 'CiviContribute',
-        'name' => 'my@y.com'),
+        'name' => 'my@y.com',
+      ),
 
     ));
     $this->assertAPISuccess($result);
     $optionValueId = $result['values'][0]['api.option_value.create']['id'];
     $component_id = $this->callAPISuccess('option_value', 'getvalue', array(
-      'id' => $optionValueId,      'return' => 'component_id',
+      'id' => $optionValueId,
+      'return' => 'component_id',
     ));
     $this->assertEquals(2, $component_id);
   }
@@ -227,22 +239,25 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   public function testCRM12133CreateOptionWeightNoValue() {
     $optionGroup = $this->callAPISuccess(
       'option_group', 'get', array(
-      'name' => 'gender',
-      'sequential' => 1,    ));
+        'name' => 'gender',
+        'sequential' => 1,
+      )
+    );
     $this->assertAPISuccess($optionGroup);
     $params = array(
       'option_group_id' => $optionGroup['id'],
-      'label' => 'my@y.com',      'weight' => 3,
+      'label' => 'my@y.com',
+      'weight' => 3,
     );
-    $optionValue = $this->callAPISuccess('option_value', 'create',  $params);
+    $optionValue = $this->callAPISuccess('option_value', 'create', $params);
     $this->assertAPISuccess($optionValue);
     $params['weight'] = 4;
-    $optionValue2 = $this->callAPISuccess('option_value', 'create',  $params );
+    $optionValue2 = $this->callAPISuccess('option_value', 'create', $params);
     $this->assertAPISuccess($optionValue2);
     $options = $this->callAPISuccess('option_value', 'get', array('option_group_id' => $optionGroup['id']));
     $this->assertNotEquals($options['values'][$optionValue['id']]['value'], $options['values'][$optionValue2['id']]['value']);
 
-  //cleanup
+    //cleanup
     $this->callAPISuccess('option_value', 'delete', array('id' => $optionValue['id']));
     $this->callAPISuccess('option_value', 'delete', array('id' => $optionValue2['id']));
   }
@@ -253,10 +268,11 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
   public function testCreateOptionNoName() {
     $optionGroup = $this->callAPISuccess('option_group', 'get', array(
       'name' => 'gender',
-      'sequential' => 1,    ));
+      'sequential' => 1,
+    ));
 
     $params = array('option_group_id' => $optionGroup['id'], 'label' => 'my@y.com');
-    $optionValue = $this->callAPISuccess('option_value', 'create',  $params);
+    $optionValue = $this->callAPISuccess('option_value', 'create', $params);
     $this->assertAPISuccess($optionValue);
     $this->getAndCheck($params, $optionValue['id'], 'option_value');
   }
@@ -266,7 +282,8 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
    * and deleted
    */
   public function testCRM11876CreateOptionPseudoConstantUpdated() {
-    $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array(      'name' => 'payment_instrument',
+    $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array(
+      'name' => 'payment_instrument',
       'return' => 'id',
     ));
     $newOption = (string) time();
@@ -297,9 +314,10 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
       array('option_group_id' => $og['id'], 'label' => 'test option value')
     );
     // update option value without 'option_group_id'
-    $res =     $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
+    $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
     $val = $this->callAPISuccess('option_value', 'getvalue', array(
-      'id' => $ov['id'], 'return' => 'is_active',
+      'id' => $ov['id'],
+      'return' => 'is_active',
     ));
     $this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__);
   }
@@ -310,16 +328,25 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
    */
   public function testUpdateOptionValueWithGroupId() {
     // create a option group
-    $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group for with group id', 'is_active' => 1));
+    $og = $this->callAPISuccess('option_group', 'create', array(
+      'name' => 'our test Option Group for with group id',
+      'is_active' => 1,
+    ));
     // create a option value
     $ov = $this->callAPISuccess('option_value', 'create',
       array('option_group_id' => $og['id'], 'label' => 'test option value')
     );
     // update option value without 'option_group_id'
-    $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'option_group_id' => $og['id'], 'is_active' => 0));
+    $this->callAPISuccess('option_value', 'create', array(
+      'id' => $ov['id'],
+      'option_group_id' => $og['id'],
+      'is_active' => 0,
+    ));
     $val = $this->callAPISuccess('option_value', 'getvalue', array(
-      'id' => $ov['id'], 'return' => 'is_active',
+      'id' => $ov['id'],
+      'return' => 'is_active',
     ));
     $this->assertEquals($val, 0, "update with group id is not proper " . __LINE__);
   }
+
 }