phpcs - Fix error, "CONST keyword must be lowercase; expected const but found CONST"
[civicrm-core.git] / tests / phpunit / CRM / Contact / BAO / GroupTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
29require_once 'CiviTest/CiviUnitTestCase.php';
30
31/**
32 * Test class for CRM_Contact_BAO_Group BAO
33 *
34 * @package CiviCRM
35 */
36class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase {
37
38 /**
39 * Sets up the fixture, for example, opens a network connection.
40 * This method is called before a test is executed.
41 *
42 * @access protected
43 */
44 protected function setUp() {
45 parent::setUp();
46 }
47
48 /**
49 * Tears down the fixture, for example, closes a network connection.
50 * This method is called after a test is executed.
51 *
52 * @access protected
53 */
959528d2
EM
54 protected function tearDown() {
55 $this->quickCleanup(array('civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search'));
56 }
6a488035
TO
57
58 /**
100fef9d 59 * Test case for add( )
6a488035
TO
60 */
61 function testAddSimple() {
62
63 $checkParams = $params = array(
64 'title' => 'Group Uno',
65 'description' => 'Group One',
66 'visibility' => 'User and User Admin Only',
67 'is_active' => 1,
68 );
69
70 $group = CRM_Contact_BAO_Group::create($params);
71
72 $this->assertDBCompareValues(
73 'CRM_Contact_DAO_Group',
74 array('id' => $group->id),
75 $checkParams
76 );
77 }
78
79 function testAddSmart() {
80
81 $checkParams = $params = array(
82 'title' => 'Group Dos',
83 'description' => 'Group Two',
84 'visibility' => 'User and User Admin Only',
85 'is_active' => 1,
86 'formValues' => array('sort_name' => 'Adams'),
87 );
88
89 $group = CRM_Contact_BAO_Group::createSmartGroup($params);
90
91 unset($checkParams['formValues']);
92 $this->assertDBCompareValues(
93 'CRM_Contact_DAO_Group',
94 array('id' => $group->id),
95 $checkParams
96 );
97 }
959528d2
EM
98
99 /**
100 * Load all sql data sets & return an array of saved searches
101 * @return array
102 */
103 function dataProviderSavedSearch() {
104
105 $this->loadSavedSearches();
106 $results = CRM_Core_DAO::singleValueQuery('SELECT GROUP_CONCAT(id) FROM civicrm_group WHERE saved_search_id IS NOT NULL');
107 return array(explode(',', $results));
108 }
109
110 /**
111 * Load saved search sql files into the DB
112 */
113 function loadSavedSearches() {
114 $dsn = CRM_Core_Config::singleton()->dsn;
115 foreach (glob(dirname(__FILE__) . "/SavedSearchDataSets/*.sql") as $file) {
116 CRM_Utils_File::sourceSQLFile($dsn, $file);
117 }
118 }
119
120 /**
121 * Check we can load smart groups based on config from 'real DBs' without fatal errors - note that we are only testing lack of errors at this stage
122 * @todo - for some reason the data was getting truncated from the group table using dataprovider - would be preferable to get that working
123 * //@notdataProvider dataProviderSavedSearch
124 * //@notparam integer $groupID
125 *
126 * To add to this dataset do
127 *
128 * SET @groupID = x;
129 * SELECT mapping_id FROM civicrm_group g LEFT JOIN civicrm_saved_search s ON saved_search_id = s.id WHERE g.id = @groupID INTO @mappingID;
130
131 * SELECT * FROM civicrm_mapping WHERE id = @mappingID;
132 * SELECT * FROM civicrm_mapping_field WHERE mapping_id = @mappingID;
133 * SELECT * FROM civicrm_saved_search WHERE mapping_id = @mappingID;
134 * SELECT g.* FROM civicrm_saved_search s LEFT JOIN civicrm_group g ON g.saved_search_id = s.id WHERE mapping_id = @mappingID;
135 *
a455be55 136 * Copy the output to a single sql file and place in the SavedSearchDataSets folder - use the group number as the prefix.
959528d2
EM
137 * Try to keep as much of the real world irregular glory as you can! Don't change the table ids to be number 1 as this can hide errors
138 */
139 function testGroupData() {
140 $groups = $this->dataProviderSavedSearch();
141 foreach ($groups[0] as $groupID) {
142 $group = new CRM_Contact_BAO_Group();
143 $group->id = $groupID;
144 $group->find(TRUE);
a455be55 145
959528d2
EM
146 CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
147 }
148 }
6a488035
TO
149}
150