4 * Class CRM_UF_Page_ProfileEditorTest
7 class CRM_UF_Page_ProfileEditorTest
extends CiviUnitTestCase
{
9 public function setUp() {
14 * Spot check a few fields that should appear in schema.
16 public function testGetSchema() {
17 $schema = CRM_UF_Page_ProfileEditor
::getSchema(['IndividualModel', 'ActivityModel']);
18 foreach ($schema as $entityName => $entityDef) {
19 foreach ($entityDef['schema'] as $fieldName => $fieldDef) {
20 $this->assertNotEmpty($fieldDef['type']);
21 $this->assertNotEmpty($fieldDef['title']);
22 $this->assertNotEmpty($fieldDef['civiFieldType']);
26 $this->assertEquals('Individual', $schema['IndividualModel']['schema']['first_name']['civiFieldType']);
27 $this->assertTrue(empty($schema['IndividualModel']['schema']['first_name']['civiIsLocation']));
28 $this->assertTrue(empty($schema['IndividualModel']['schema']['first_name']['civiIsPhone']));
30 $this->assertEquals('Contact', $schema['IndividualModel']['schema']['street_address']['civiFieldType']);
31 $this->assertNotEmpty($schema['IndividualModel']['schema']['street_address']['civiIsLocation']);
32 $this->assertTrue(empty($schema['IndividualModel']['schema']['street_address']['civiIsPhone']));
34 $this->assertEquals('Contact', $schema['IndividualModel']['schema']['phone_and_ext']['civiFieldType']);
35 $this->assertNotEmpty($schema['IndividualModel']['schema']['phone_and_ext']['civiIsLocation']);
36 $this->assertNotEmpty($schema['IndividualModel']['schema']['phone_and_ext']['civiIsPhone']);
38 $this->assertEquals('Activity', $schema['ActivityModel']['schema']['activity_subject']['civiFieldType']);
39 $this->assertTrue(empty($schema['ActivityModel']['schema']['activity_subject']['civiIsLocation']));
40 $this->assertTrue(empty($schema['ActivityModel']['schema']['activity_subject']['civiIsPhone']));
42 // don't mix up contacts and activities
43 $this->assertTrue(empty($schema['IndividualModel']['schema']['activity_subject']));
44 $this->assertTrue(empty($schema['ActivityModel']['schema']['street_address']));
49 * Test that with an extension adding in UF Fields for an enttiy that isn't supplied by Core e.g. Grant
50 * That an appropriate entitytype can be specfied in the backbone.marionette profile editor e.g. GrantModel
52 public function testGetSchemaWithHooks() {
53 CRM_Utils_Hook
::singleton()->setHook('civicrm_alterUFFields', [$this, 'hook_civicrm_alterUFFIelds']);
54 $schema = CRM_UF_Page_ProfileEditor
::getSchema(['IndividualModel', 'GrantModel']);
55 $this->assertEquals('Grant', $schema['GrantModel']['schema']['grant_decision_date']['civiFieldType']);
59 * Tries to load up the profile schema for a model where there is no corresponding set of fields avaliable.
61 * @expectedException \CRM_Core_Exception
63 public function testGetSchemaWithHooksWithInvalidModel() {
64 CRM_Utils_Hook
::singleton()->setHook('civicrm_alterUFFields', [$this, 'hook_civicrm_alterUFFIelds']);
65 $schema = CRM_UF_Page_ProfileEditor
::getSchema(['IndividualModel', 'GrantModel', 'PledgeModel']);
68 public function hook_civicrm_alterUFFIelds(&$fields) {
69 $fields['Grant'] = CRM_Grant_BAO_Grant
::exportableFields();