Merge pull request #17970 from eileenmcnaughton/case_export
[civicrm-core.git] / tests / phpunit / CRM / UF / Page / ProfileEditorTest.php
1 <?php
2
3 /**
4 * Class CRM_UF_Page_ProfileEditorTest
5 * @group headless
6 */
7 class CRM_UF_Page_ProfileEditorTest extends CiviUnitTestCase {
8
9 public function setUp() {
10 parent::setUp();
11 }
12
13 /**
14 * Spot check a few fields that should appear in schema.
15 */
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']);
23 }
24 }
25
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']));
29
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']));
33
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']);
37
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']));
41
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']));
45
46 }
47
48 /**
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
51 */
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']);
56 }
57
58 /**
59 * Tries to load up the profile schema for a model where there is no corresponding set of fields avaliable.
60 *
61 * @expectedException \CRM_Core_Exception
62 */
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']);
66 }
67
68 public function hook_civicrm_alterUFFIelds(&$fields) {
69 $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
70 }
71
72 }