3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Tests for field options
32 class CRM_Core_OptionGroupTest
extends CiviUnitTestCase
{
35 * Test setup for every test.
37 public function setUp() {
42 * Ensure only one option value exists after calling ensureOptionValueExists.
44 public function testWeightOptionGroup() {
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");
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'
58 $dao = CRM_Core_DAO
::executeQuery($sql);
59 while ($dao->fetch()) {
60 $values[$dao->value
] = $dao->label
;
62 $this->assertTrue(($values === $options2), "The arrays retrieved should be the same and in the same order");
70 public function optionGroupTests() {
72 $tests[] = array('event_type', 'Integer');
73 $tests[] = array('addressee', 'null');
74 $tests[] = array('activity_status', 'Integer');
79 * Test Returning DataType of Option Group
82 * @dataProvider optionGroupTests
84 public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
85 $dataType = CRM_Admin_Form_Options
::getOptionGroupDataType($optionGroup);
86 if ($expectedDataType == 'null') {
87 $this->assertNull($dataType);
90 $this->assertEquals($dataType, $expectedDataType);
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>');
104 * @dataProvider emailAddressTests
106 public function testSanitizeFromEmailAddress($dirty, $clean) {
107 $form = new CRM_Admin_Form_Options();
108 $actual = $form->sanitizeFromEmailAddress($dirty);
109 $this->assertEquals($actual, $clean);