Move getting dataType into own function and add test of loading data type also minor...
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 20 Jul 2016 23:54:33 +0000 (09:54 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 10 Sep 2016 21:53:24 +0000 (07:53 +1000)
CRM/Admin/Form/OptionGroup.php
CRM/Admin/Form/Options.php
CRM/Utils/Check/Component/OptionGroups.php
sql/civicrm_generated.mysql
tests/phpunit/CRM/Core/OptionGroupTest.php

index 05a504ec5e021926a95d0a36f38b1561a137d596..7fbe79817888a9d3f0bc5d200905cb76b2ebc68a 100644 (file)
  */
 class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form {
 
+  /**
+   * Explicitly declare the entity api name.
+   */
+  public function getDefaultEntity() {
+    return 'OptionGroup';
+  }
+
   /**
    * Build the form object.
    */
index 6d82d38c075f06ca295cc51a8636160172f9aa25..3ff8e98ec3ca19baabe17105444a20388b0c120b 100644 (file)
@@ -376,11 +376,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       }
     }
 
-    $optionGroup = civicrm_api3('OptionGroup', 'get', array(
-      'sequential' => 1,
-      'name' => $self->_gName,
-    ));
-    $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroup['id']);
+    $optionGroup = $this->getOptionGroupDataType($self->_gName);
     if ($dataType) {
       $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE);
       if (!$validate) {
@@ -392,6 +388,23 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
     return $errors;
   }
 
+  /**
+   * Get the DataType for a specified Option Group.
+   *
+   * @param string $optionGroupname name of the option group
+   *
+   * @return string|bool
+   */
+  public static function getOptionGroupDataType($optionGroupName) {
+    $optionGroup = civicrm_api3('OptionGroup', 'get', array(
+      'sequential' => 1,
+      'name' => $optionGroupName,
+    ));
+
+    $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroup['id']);
+    return $dataType;
+  }
+
   /**
    * Process the form submission.
    */
index e4e2b997e81e98a4454763f4e4f28030192d6e34..077e551e96375af5706cb685d71c1025a66bf5fe 100644 (file)
@@ -53,7 +53,7 @@ class CRM_Utils_Check_Component_OptionGroups extends CRM_Utils_Check_Component {
             $validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE);
             if (!$validate) {
               $problemValues[] = array(
-                'group_name' => $optionGroup['label'],
+                'group_name' => $optionGroup['title'],
                 'value_name' => $value['label'],
               );
             }
@@ -74,7 +74,7 @@ class CRM_Utils_Check_Component_OptionGroups extends CRM_Utils_Check_Component {
        __FUNCTION__,
        ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p>
         <p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') .
-        explode('\n', $strings) . ts('</tbody></table></p>'),
+        implode('\n', $strings) . ts('</tbody></table></p>'),
         ts('Option Values with problematic Values'),
         \Psr\Log\LogLevel::NOTICE,
         'fa-server'
index 8740f203362736dc8a8dc6771e3bf5f23254c5be..56124804bfc9c559f2f5fa69a3cd8942facd9ec6 100644 (file)
@@ -918,7 +918,6 @@ LOCK TABLES `civicrm_membership_log` WRITE;
 /*!40000 ALTER TABLE `civicrm_membership_log` DISABLE KEYS */;
 INSERT INTO `civicrm_membership_log` (`id`, `membership_id`, `status_id`, `start_date`, `end_date`, `modified_id`, `modified_date`, `membership_type_id`, `max_related`) VALUES (1,9,1,'2016-08-05','2018-08-04',11,'2016-08-13',1,NULL),(2,10,4,'2015-08-04','2016-08-03',15,'2016-08-13',2,NULL),(3,6,1,'2016-08-08','2017-08-07',35,'2016-08-13',2,NULL),(4,7,1,'2016-08-07','2018-08-06',36,'2016-08-13',1,NULL),(5,11,1,'2016-08-03',NULL,39,'2016-08-13',3,NULL),(6,5,4,'2015-08-09','2016-08-08',42,'2016-08-13',2,NULL),(7,2,1,'2016-08-12','2017-08-11',48,'2016-08-13',2,NULL),(8,24,1,'2016-07-21','2017-07-20',51,'2016-08-13',2,NULL),(9,19,1,'2016-07-26','2018-07-25',56,'2016-08-13',1,NULL),(10,23,1,'2016-07-22','2018-07-21',59,'2016-08-13',1,NULL),(11,22,1,'2016-07-23',NULL,70,'2016-08-13',3,NULL),(12,20,3,'2014-03-14','2016-03-13',76,'2016-08-13',1,NULL),(13,3,1,'2016-08-11','2018-08-10',79,'2016-08-13',1,NULL),(14,4,1,'2016-08-10','2017-08-09',94,'2016-08-13',2,NULL),(15,15,3,'2014-04-23','2016-04-22',99,'2016-08-13',1,NULL),(16,26,1,'2016-07-19','2017-07-18',103,'2016-08-13',2,NULL),(17,1,1,'2016-08-13','2018-08-12',104,'2016-08-13',1,NULL),(18,13,1,'2016-08-01','2018-07-31',105,'2016-08-13',1,NULL),(19,18,1,'2016-07-27','2017-07-26',109,'2016-08-13',2,NULL),(20,17,1,'2016-07-28','2018-07-27',133,'2016-08-13',1,NULL),(21,27,1,'2016-07-18','2018-07-17',139,'2016-08-13',1,NULL),(22,21,1,'2016-07-24','2018-07-23',145,'2016-08-13',1,NULL),(23,16,1,'2016-07-29','2017-07-28',148,'2016-08-13',2,NULL),(24,14,1,'2016-07-31','2017-07-30',161,'2016-08-13',2,NULL),(25,30,3,'2013-12-24','2015-12-23',172,'2016-08-13',1,NULL),(26,28,1,'2016-07-17','2017-07-16',174,'2016-08-13',2,NULL),(27,25,4,'2015-07-20','2016-07-19',179,'2016-08-13',2,NULL),(28,12,1,'2016-08-02','2017-08-01',197,'2016-08-13',2,NULL),(29,8,1,'2016-08-06','2017-08-05',198,'2016-08-13',2,NULL),(30,29,1,'2016-07-16','2018-07-15',201,'2016-08-13',1,NULL);
 /*!40000 ALTER TABLE `civicrm_membership_log` ENABLE KEYS */;
-UNLOCK TABLES;
 
 --
 -- Dumping data for table `civicrm_membership_payment`
index 73d7c404c77f9f9472d594b53627979fdc1dcc20..dad218314a0e6a6c7a8d4367ec2f63574170e62b 100644 (file)
@@ -63,4 +63,33 @@ class CRM_Core_OptionGroupTest extends CiviUnitTestCase {
     $this->assertTrue(($values === $options2), "The arrays retrieved should be the same and in the same order");
   }
 
+  /**
+   * optionGroupTests
+   *
+   * @return array
+   */
+  public function optionGroupTests() {
+    $tests = array();
+    $tests[] = array('event_type', 'Integer');
+    $tests[] = array('addressee', 'null');
+    $tests[] = array('activity_status', 'Integer');
+    return $tests;
+  }
+
+  /**
+   * Test Returning DataType of Option Group
+   *
+   *
+   * @dataProvider optionGroupTests
+   */
+  public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
+    $dataType = CRM_Admin_Form_Options::getOptionGroupDataType($optionGroup);
+    if ($expectedDataType == 'null') {
+      $this->assertNull($dataType);
+    }
+    else {
+      $this->assertEquals($dataType, $expectedDataType);
+    }
+  }
+
 }