Merge pull request #14662 from eileenmcnaughton/activity_pdf_71
[civicrm-core.git] / tests / phpunit / CRM / Core / FieldOptionsTest.php
index 8ac635e529e480f8629959fba9dbe91673e33dbd..fc26206354de848632ba7d967b19b11c24ec95bd 100644 (file)
@@ -1,27 +1,11 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
- |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
@@ -48,12 +32,12 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase {
 
   public function setUp() {
     parent::setUp();
-    CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', array($this, 'hook_civicrm_fieldOptions'));
+    CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', [$this, 'hook_civicrm_fieldOptions']);
   }
 
   public function tearDown() {
     parent::tearDown();
-    $this->quickCleanup(array('civicrm_custom_field', 'civicrm_custom_group'));
+    $this->quickCleanup(['civicrm_custom_field', 'civicrm_custom_group']);
   }
 
   /**
@@ -72,30 +56,30 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase {
      * - exclude: Any one value which should not be in the list.
      * - max: integer (default = 10) maximum number of option values expected.
      */
-    $fields = array(
-      'CRM_Core_BAO_Address' => array(
-        array(
+    $fields = [
+      'CRM_Core_BAO_Address' => [
+        [
           'fieldName' => 'state_province_id',
           'sample' => 'California',
           'max' => 60,
-          'props' => array('country_id' => 1228),
-        ),
-      ),
-      'CRM_Contact_BAO_Contact' => array(
-        array(
+          'props' => ['country_id' => 1228],
+        ],
+      ],
+      'CRM_Contact_BAO_Contact' => [
+        [
           'fieldName' => 'contact_sub_type',
           'sample' => 'Team',
           'exclude' => 'Organization',
-          'props' => array('contact_type' => 'Organization'),
-        ),
-      ),
-    );
+          'props' => ['contact_type' => 'Organization'],
+        ],
+      ],
+    ];
 
     foreach ($fields as $baoName => $baoFields) {
       foreach ($baoFields as $field) {
         $message = "BAO name: '{$baoName}', field: '{$field['fieldName']}'";
 
-        $props = CRM_Utils_Array::value('props', $field, array());
+        $props = CRM_Utils_Array::value('props', $field, []);
         $optionValues = $baoName::buildOptions($field['fieldName'], 'create', $props);
         $this->assertNotEmpty($optionValues, $message);
 
@@ -122,8 +106,8 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase {
 
     // Test replacing all options with a hook
     $this->targetField = 'case_type_id';
-    $this->replaceOptions = array('foo' => 'Foo', 'bar' => 'Bar');
-    $result = $this->callAPISuccess('case', 'getoptions', array('field' => 'case_type_id'));
+    $this->replaceOptions = ['foo' => 'Foo', 'bar' => 'Bar'];
+    $result = $this->callAPISuccess('case', 'getoptions', ['field' => 'case_type_id']);
     $this->assertEquals($result['values'], $this->replaceOptions);
 
     // TargetField doesn't match - should get unmodified option list
@@ -132,7 +116,7 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase {
 
     // This time we should get foo bar appended to the list
     $this->targetField = 'gender_id';
-    $this->appendOptions = array('foo' => 'Foo', 'bar' => 'Bar');
+    $this->appendOptions = ['foo' => 'Foo', 'bar' => 'Bar'];
     $this->replaceOptions = NULL;
     CRM_Core_PseudoConstant::flush();
     $result = CRM_Contact_BAO_Contact::buildOptions('gender_id');
@@ -145,65 +129,65 @@ class CRM_Core_FieldOptionsTest extends CiviUnitTestCase {
   public function testHookFieldOptionsWithCustomFields() {
     // Create a custom field group for testing.
     $custom_group_name = md5(microtime());
-    $api_params = array(
+    $api_params = [
       'title' => $custom_group_name,
       'extends' => 'Individual',
       'is_active' => TRUE,
-    );
+    ];
     $customGroup = $this->callAPISuccess('customGroup', 'create', $api_params);
 
     // Add a custom select field.
-    $api_params = array(
+    $api_params = [
       'custom_group_id' => $customGroup['id'],
       'label' => $custom_group_name . 1,
       'html_type' => 'Select',
       'data_type' => 'String',
-      'option_values' => array(
+      'option_values' => [
         'foo' => 'Foo',
         'bar' => 'Bar',
-      ),
-    );
+      ],
+    ];
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField1 = $result['id'];
 
     // Add a custom country field.
-    $api_params = array(
+    $api_params = [
       'custom_group_id' => $customGroup['id'],
       'label' => $custom_group_name . 2,
       'html_type' => 'Select Country',
       'data_type' => 'Country',
-    );
+    ];
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField2 = $result['id'];
 
     // Add a custom boolean field.
-    $api_params = array(
+    $api_params = [
       'custom_group_id' => $customGroup['id'],
       'label' => $custom_group_name . 3,
       'html_type' => 'Radio',
       'data_type' => 'Boolean',
-    );
+    ];
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField3 = $result['id'];
 
     $this->targetField = 'custom_' . $customField1;
     $this->replaceOptions = NULL;
-    $this->appendOptions = array('baz' => 'Baz');
+    $this->appendOptions = ['baz' => 'Baz'];
     $field = new CRM_Core_BAO_CustomField();
     $field->id = $customField1;
-    $this->assertEquals(array('foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'), $field->getOptions());
+    $this->assertEquals(['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'], $field->getOptions());
 
     $this->targetField = 'custom_' . $customField2;
-    $this->replaceOptions = array('nowhere' => 'Nowhere');
+    $this->replaceOptions = ['nowhere' => 'Nowhere'];
     $field = new CRM_Core_BAO_CustomField();
     $field->id = $customField2;
     $this->assertEquals($this->replaceOptions + $this->appendOptions, $field->getOptions());
 
     $this->targetField = 'custom_' . $customField3;
     $this->replaceOptions = NULL;
-    $this->appendOptions = array(2 => 'Maybe');
+    $this->appendOptions = [2 => 'Maybe'];
     $options = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', $this->targetField);
-    $this->assertEquals(array(1 => 'Yes', 0 => 'No', 2 => 'Maybe'), $options);
+    $this->assertEquals([1 => 'Yes', 0 => 'No', 2 => 'Maybe'], $options);
   }
 
   /**