Merge pull request #17981 from eileenmcnaughton/merge_form
[civicrm-core.git] / tests / phpunit / CRM / UF / Page / ProfileEditorTest.php
index 38d16f1d616906ece85a05982fa3b4eab4908b9a..7ea035594e0d4d89fdd0c2eacfa270b9d8bd8f0a 100644 (file)
@@ -2,8 +2,10 @@
 
 /**
  * Class CRM_UF_Page_ProfileEditorTest
+ * @group headless
  */
 class CRM_UF_Page_ProfileEditorTest extends CiviUnitTestCase {
+
   public function setUp() {
     parent::setUp();
   }
@@ -12,7 +14,7 @@ class CRM_UF_Page_ProfileEditorTest extends CiviUnitTestCase {
    * Spot check a few fields that should appear in schema.
    */
   public function testGetSchema() {
-    $schema = CRM_UF_Page_ProfileEditor::getSchema(array('IndividualModel', 'ActivityModel'));
+    $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'ActivityModel']);
     foreach ($schema as $entityName => $entityDef) {
       foreach ($entityDef['schema'] as $fieldName => $fieldDef) {
         $this->assertNotEmpty($fieldDef['type']);
@@ -43,4 +45,28 @@ class CRM_UF_Page_ProfileEditorTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test that with an extension adding in UF Fields for an enttiy that isn't supplied by Core e.g. Grant
+   * That an appropriate entitytype can be specfied in the backbone.marionette profile editor e.g. GrantModel
+   */
+  public function testGetSchemaWithHooks() {
+    CRM_Utils_Hook::singleton()->setHook('civicrm_alterUFFields', [$this, 'hook_civicrm_alterUFFIelds']);
+    $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'GrantModel']);
+    $this->assertEquals('Grant', $schema['GrantModel']['schema']['grant_decision_date']['civiFieldType']);
+  }
+
+  /**
+   * Tries to load up the profile schema for a model where there is no corresponding set of fields avaliable.
+   *
+   * @expectedException \CRM_Core_Exception
+   */
+  public function testGetSchemaWithHooksWithInvalidModel() {
+    CRM_Utils_Hook::singleton()->setHook('civicrm_alterUFFields', [$this, 'hook_civicrm_alterUFFIelds']);
+    $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'GrantModel', 'PledgeModel']);
+  }
+
+  public function hook_civicrm_alterUFFIelds(&$fields) {
+    $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
+  }
+
 }