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