Merge pull request #14922 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / CRM / Core / OptionGroupTest.php
CommitLineData
58e06f88
E
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
58e06f88 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
58e06f88
E
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 * Tests for field options
30 * @group headless
31 */
32class CRM_Core_OptionGroupTest extends CiviUnitTestCase {
33
34 /**
35 * Test setup for every test.
36 */
37 public function setUp() {
38 parent::setUp();
39 }
40
41 /**
42 * Ensure only one option value exists after calling ensureOptionValueExists.
43 */
44 public function testWeightOptionGroup() {
9099cab3 45 $values = [];
370d56eb
CW
46 $options1 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE);
47 $options2 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE, FALSE, 'value', 'name');
58e06f88
E
48 // Verify that arrays are equal.
49 $this->assertTrue(($options1 == $options2), "The arrays retrieved should be the same");
50 // Verify sequence is different.
51 $this->assertFalse(($options1 === $options2), "The arrays retrieved should be the same, but in a different order");
52 // Verify values.
53 $sql = "SELECT v.value, v.label
54 FROM civicrm_option_value v
55 INNER JOIN civicrm_option_group g ON g.id = v.option_group_id
56 AND g.name = 'activity_type'
58e06f88
E
57 ORDER BY v.name";
58 $dao = CRM_Core_DAO::executeQuery($sql);
59 while ($dao->fetch()) {
60 $values[$dao->value] = $dao->label;
61 }
62 $this->assertTrue(($values === $options2), "The arrays retrieved should be the same and in the same order");
63 }
64
c62c37c7
SL
65 /**
66 * optionGroupTests
67 *
68 * @return array
69 */
70 public function optionGroupTests() {
9099cab3
CW
71 $tests = [];
72 $tests[] = ['event_type', 'Integer'];
73 $tests[] = ['addressee', 'null'];
74 $tests[] = ['activity_status', 'Integer'];
c62c37c7
SL
75 return $tests;
76 }
77
78 /**
79 * Test Returning DataType of Option Group
80 *
81 *
82 * @dataProvider optionGroupTests
83 */
84 public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
85 $dataType = CRM_Admin_Form_Options::getOptionGroupDataType($optionGroup);
86 if ($expectedDataType == 'null') {
87 $this->assertNull($dataType);
88 }
89 else {
90 $this->assertEquals($dataType, $expectedDataType);
91 }
92 }
93
ccbfdc72 94 public function emailAddressTests() {
9099cab3
CW
95 $tests[] = ['"Name"<email@example.com>', '"Name" <email@example.com>'];
96 $tests[] = ['"Name" <email@example.com>', '"Name" <email@example.com>'];
97 $tests[] = ['"Name" <email@example.com>', '"Name" <email@example.com>'];
ccbfdc72
MM
98 return $tests;
99 }
100
ccbfdc72
MM
101 /**
102 * @dataProvider emailAddressTests
103 */
104 public function testSanitizeFromEmailAddress($dirty, $clean) {
105 $form = new CRM_Admin_Form_Options();
106 $actual = $form->sanitizeFromEmailAddress($dirty);
107 $this->assertEquals($actual, $clean);
108 }
109
58e06f88 110}