3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Tests for field options
16 class CRM_Core_OptionGroupTest
extends CiviUnitTestCase
{
19 * Test setup for every test.
21 public function setUp() {
26 * Ensure only one option value exists after calling ensureOptionValueExists.
28 public function testWeightOptionGroup() {
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");
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'
42 $dao = CRM_Core_DAO
::executeQuery($sql);
43 while ($dao->fetch()) {
44 $values[$dao->value
] = $dao->label
;
46 $this->assertTrue(($values === $options2), "The arrays retrieved should be the same and in the same order");
54 public function optionGroupTests() {
56 $tests[] = ['event_type', 'Integer'];
57 $tests[] = ['addressee', 'null'];
58 $tests[] = ['activity_status', 'Integer'];
63 * Test Returning DataType of Option Group
66 * @dataProvider optionGroupTests
68 public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
69 $dataType = CRM_Admin_Form_Options
::getOptionGroupDataType($optionGroup);
70 if ($expectedDataType == 'null') {
71 $this->assertNull($dataType);
74 $this->assertEquals($dataType, $expectedDataType);
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>'];
86 * @dataProvider emailAddressTests
88 public function testSanitizeFromEmailAddress($dirty, $clean) {
89 $form = new CRM_Admin_Form_Options();
90 $actual = $form->sanitizeFromEmailAddress($dirty);
91 $this->assertEquals($actual, $clean);