Merge pull request #13343 from GinkgoFJG/case-issues-w-ufgroup-api
[civicrm-core.git] / tests / phpunit / CRM / Core / OptionGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 */
32 class 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() {
45 $values = array();
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');
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'
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
65 /**
66 * optionGroupTests
67 *
68 * @return array
69 */
70 public function optionGroupTests() {
71 $tests = array();
72 $tests[] = array('event_type', 'Integer');
73 $tests[] = array('addressee', 'null');
74 $tests[] = array('activity_status', 'Integer');
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
94
95 public function emailAddressTests() {
96 $tests[] = array('"Name"<email@example.com>', '"Name" <email@example.com>');
97 $tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
98 $tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
99 return $tests;
100 }
101
102
103 /**
104 * @dataProvider emailAddressTests
105 */
106 public function testSanitizeFromEmailAddress($dirty, $clean) {
107 $form = new CRM_Admin_Form_Options();
108 $actual = $form->sanitizeFromEmailAddress($dirty);
109 $this->assertEquals($actual, $clean);
110 }
111
112 }