Commit | Line | Data |
---|---|---|
58e06f88 E |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
58e06f88 | 5 | | | |
7d61e75f TO |
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 | | |
58e06f88 E |
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() { | |
9099cab3 | 29 | $values = []; |
370d56eb CW |
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'); | |
58e06f88 E |
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' | |
58e06f88 E |
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 | ||
c62c37c7 SL |
49 | /** |
50 | * optionGroupTests | |
51 | * | |
52 | * @return array | |
53 | */ | |
54 | public function optionGroupTests() { | |
9099cab3 CW |
55 | $tests = []; |
56 | $tests[] = ['event_type', 'Integer']; | |
57 | $tests[] = ['addressee', 'null']; | |
58 | $tests[] = ['activity_status', 'Integer']; | |
c62c37c7 SL |
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 | ||
ccbfdc72 | 78 | public function emailAddressTests() { |
9099cab3 CW |
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>']; | |
ccbfdc72 MM |
82 | return $tests; |
83 | } | |
84 | ||
ccbfdc72 MM |
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 | ||
58e06f88 | 94 | } |