Merge pull request #15760 from colemanw/iconPicker
[civicrm-core.git] / tests / phpunit / CRM / Core / OptionGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Tests for field options
14 * @group headless
15 */
16 class CRM_Core_OptionGroupTest extends CiviUnitTestCase {
17
18 /**
19 * Test setup for every test.
20 */
21 public function setUp() {
22 parent::setUp();
23 }
24
25 /**
26 * Ensure only one option value exists after calling ensureOptionValueExists.
27 */
28 public function testWeightOptionGroup() {
29 $values = [];
30 $options1 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE);
31 $options2 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE, FALSE, 'value', 'name');
32 // Verify that arrays are equal.
33 $this->assertTrue(($options1 == $options2), "The arrays retrieved should be the same");
34 // Verify sequence is different.
35 $this->assertFalse(($options1 === $options2), "The arrays retrieved should be the same, but in a different order");
36 // Verify values.
37 $sql = "SELECT v.value, v.label
38 FROM civicrm_option_value v
39 INNER JOIN civicrm_option_group g ON g.id = v.option_group_id
40 AND g.name = 'activity_type'
41 ORDER BY v.name";
42 $dao = CRM_Core_DAO::executeQuery($sql);
43 while ($dao->fetch()) {
44 $values[$dao->value] = $dao->label;
45 }
46 $this->assertTrue(($values === $options2), "The arrays retrieved should be the same and in the same order");
47 }
48
49 /**
50 * optionGroupTests
51 *
52 * @return array
53 */
54 public function optionGroupTests() {
55 $tests = [];
56 $tests[] = ['event_type', 'Integer'];
57 $tests[] = ['addressee', 'null'];
58 $tests[] = ['activity_status', 'Integer'];
59 return $tests;
60 }
61
62 /**
63 * Test Returning DataType of Option Group
64 *
65 *
66 * @dataProvider optionGroupTests
67 */
68 public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
69 $dataType = CRM_Admin_Form_Options::getOptionGroupDataType($optionGroup);
70 if ($expectedDataType == 'null') {
71 $this->assertNull($dataType);
72 }
73 else {
74 $this->assertEquals($dataType, $expectedDataType);
75 }
76 }
77
78 public function emailAddressTests() {
79 $tests[] = ['"Name"<email@example.com>', '"Name" <email@example.com>'];
80 $tests[] = ['"Name" <email@example.com>', '"Name" <email@example.com>'];
81 $tests[] = ['"Name" <email@example.com>', '"Name" <email@example.com>'];
82 return $tests;
83 }
84
85 /**
86 * @dataProvider emailAddressTests
87 */
88 public function testSanitizeFromEmailAddress($dirty, $clean) {
89 $form = new CRM_Admin_Form_Options();
90 $actual = $form->sanitizeFromEmailAddress($dirty);
91 $this->assertEquals($actual, $clean);
92 }
93
94 }