[NFC] CRM-19033 improve standardisation of tests
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / CustomGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 * Class CRM_Core_BAO_CustomGroupTest
30 * @group headless
31 */
32 class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase {
33
34 public function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Test getTree().
40 */
41 public function testGetTree() {
42 $customGroup = $this->CustomGroupCreate();
43 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
44 $result = CRM_Core_BAO_CustomGroup::getTree('Individual', NULL, $customGroup['id']);
45 $this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']);
46 $this->customGroupDelete($customGroup['id']);
47 }
48
49 /**
50 * Test calling getTree with contact subtype data.
51 *
52 * Note that the function seems to support a range of formats so 3 are tested. Yay for
53 * inconsistency.
54 */
55 public function testGetTreeContactSubType() {
56 $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
57 $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
58 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
59 $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
60 $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
61 $result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big_Bank' . CRM_Core_DAO::VALUE_SEPARATOR);
62 $this->assertEquals($result1, $result);
63 $result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, 'Big_Bank');
64 $this->assertEquals($result1, $result);
65 try {
66 CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Small Kind Bank'));
67 }
68 catch (CRM_Core_Exception $e) {
69 $this->customGroupDelete($customGroup['id']);
70 $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
71 return;
72 }
73 $this->fail('There is no such thing as a small kind bank');
74 }
75
76 /**
77 * Test calling getTree for a custom field extending a renamed contact type.
78 */
79 public function testGetTreeContactSubTypeForNameChangedContactType() {
80 $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
81 CRM_Core_DAO::executeQuery('UPDATE civicrm_contact_type SET label = "boo" WHERE name = "Organization"');
82 $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
83 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
84 $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
85 $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
86 $this->customGroupDelete($customGroup['id']);
87 $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
88 }
89
90 /**
91 * Test calling getTree for a custom field extending a disabled contact type.
92 */
93 public function testGetTreeContactSubTypeForDisabledChangedContactType() {
94 $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
95 $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
96 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
97 $this->callAPISuccess('ContactType', 'create', array('id' => $contactType['id'], 'is_active' => 0));
98 $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
99 $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
100 $this->customGroupDelete($customGroup['id']);
101 $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
102 }
103
104 public function testGetTreetContactSubTypeForMultipleSubTypes() {
105 $contactType1 = $this->callApiSuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
106 $contactType2 = $this->callAPISuccess('ContactType', 'create', array('name' => 'Small Bank', 'label' => 'smallee', 'parent_id' => 'Organization'));
107 $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank', 'Small_Bank')));
108 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
109 $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big_Bank' . CRM_Core_DAO::VALUE_SEPARATOR . 'Small_Bank' . CRM_Core_DAO::VALUE_SEPARATOR);
110 $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
111 $this->customGroupDelete($customGroup['id']);
112 $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType1['id']));
113 $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType2['id']));
114 }
115
116 /**
117 * Test calling getTree with contact subtype data.
118 *
119 * Note that the function seems to support a range of formats so 3 are tested. Yay for
120 * inconsistency.
121 */
122 public function testGetTreeCampaignSubType() {
123 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
124 $this->campaignCreate();
125 $this->campaignCreate();
126 $customGroup = $this->CustomGroupCreate(array(
127 'extends' => 'Campaign',
128 'extends_entity_column_value' => "{$sep}1{$sep}2{$sep}",
129 ));
130 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
131 $result1 = CRM_Core_BAO_CustomGroup::getTree('Campaign', NULL, NULL, NULL, '\ 11\ 12\ 1');
132 $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
133 $this->customGroupDelete($customGroup['id']);
134 }
135
136 /**
137 * Test calling getTree with contact subtype data.
138 */
139 public function testGetTreeActivitySubType() {
140 $customGroup = $this->CustomGroupCreate(array('extends' => 'Activity', 'extends_entity_column_value' => 1));
141 $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
142 $result = CRM_Core_BAO_CustomGroup::getTree('Activity', NULL, NULL, NULL, 1);
143 $this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']);
144 $this->customGroupDelete($customGroup['id']);
145 }
146
147 /**
148 * Test retrieve() with Empty Params.
149 */
150 public function testRetrieveEmptyParams() {
151 $params = array();
152 $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
153 $this->assertNull($customGroup, 'Check that no custom Group is retreived');
154 }
155
156 /**
157 * Test retrieve() with Inalid Params
158 */
159 public function testRetrieveInvalidParams() {
160 $params = array('id' => 99);
161 $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
162 $this->assertNull($customGroup, 'Check that no custom Group is retreived');
163 }
164
165 /**
166 * Test retrieve()
167 */
168 public function testRetrieve() {
169 $customGrouptitle = 'My Custom Group';
170 $groupParams = array(
171 'title' => $customGrouptitle,
172 'name' => 'My_Custom_Group',
173 'style' => 'Tab',
174 'extends' => 'Individual',
175 'help_pre' => 'Custom Group Help Pre',
176 'help_post' => 'Custom Group Help Post',
177 'is_active' => 1,
178 'collapse_display' => 1,
179 'weight' => 2,
180 'version' => 3,
181 );
182
183 $customGroup = Custom::createGroup($groupParams);
184 $customGroupId = $customGroup->id;
185
186 $params = array('id' => $customGroupId);
187 $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
188 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
189 'Database check for custom group record.'
190 );
191
192 $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
193 //check retieve values
194 unset($groupParams['version']);
195 $this->assertAttributesEquals($groupParams, $dafaults);
196
197 //cleanup DB by deleting customGroup
198 Custom::deleteGroup($customGroup);
199 }
200
201 /**
202 * Test setIsActive()
203 */
204 public function testSetIsActive() {
205 $customGrouptitle = 'My Custom Group';
206 $groupParams = array(
207 'title' => $customGrouptitle,
208 'name' => 'my_custom_group',
209 'style' => 'Tab',
210 'extends' => 'Individual',
211 'is_active' => 0,
212 'version' => 3,
213 );
214
215 $customGroup = Custom::createGroup($groupParams);
216 $customGroupId = $customGroup->id;
217
218 //update is_active
219 $result = CRM_Core_BAO_CustomGroup::setIsActive($customGroupId, TRUE);
220
221 //check for object update
222 $this->assertEquals(TRUE, $result);
223 //check for is_active
224 $this->assertDBCompareValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'is_active', 'id', 1,
225 'Database check for custom group is_active field.'
226 );
227 //cleanup DB by deleting customGroup
228 Custom::deleteGroup($customGroup);
229 }
230
231 /**
232 * Test getGroupDetail() with Empty Params
233 */
234 public function testGetGroupDetailEmptyParams() {
235 $customGroupId = array();
236 $customGroup = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId);
237 $this->assertTrue(empty($customGroup), 'Check that no custom Group details is retreived');
238 }
239
240 /**
241 * Test getGroupDetail() with Inalid Params
242 */
243 public function testGetGroupDetailInvalidParams() {
244 $customGroupId = 99;
245 $customGroup = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId);
246 $this->assertTrue(empty($customGroup), 'Check that no custom Group details is retreived');
247 }
248
249 /**
250 * Test getGroupDetail()
251 */
252 public function testGetGroupDetail() {
253 $customGrouptitle = 'My Custom Group';
254 $groupParams = array(
255 'title' => $customGrouptitle,
256 'name' => 'My_Custom_Group',
257 'extends' => 'Individual',
258 'help_pre' => 'Custom Group Help Pre',
259 'help_post' => 'Custom Group Help Post',
260 'is_active' => 1,
261 'collapse_display' => 1,
262 'version' => 3,
263 );
264
265 $customGroup = Custom::createGroup($groupParams);
266 $customGroupId = $customGroup->id;
267
268 $fieldParams = array(
269 'custom_group_id' => $customGroupId,
270 'label' => 'Test Custom Field',
271 'html_type' => 'Text',
272 'data_type' => 'String',
273 'is_required' => 1,
274 'is_searchable' => 0,
275 'is_active' => 1,
276 'version' => 3,
277 );
278
279 $customField = Custom::createField($fieldParams);
280 $customFieldId = $customField->id;
281
282 $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId);
283 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
284 'Database check for custom group record.'
285 );
286 //check retieve values of custom group
287 unset($groupParams['is_active']);
288 unset($groupParams['title']);
289 unset($groupParams['version']);
290 $this->assertAttributesEquals($groupParams, $groupTree[$customGroupId]);
291
292 //check retieve values of custom field
293 unset($fieldParams['is_active']);
294 unset($fieldParams['custom_group_id']);
295 unset($fieldParams['version']);
296 $this->assertAttributesEquals($fieldParams, $groupTree[$customGroupId]['fields'][$customFieldId], " in line " . __LINE__);
297
298 //cleanup DB by deleting customGroup
299 Custom::deleteField($customField);
300 Custom::deleteGroup($customGroup);
301 }
302
303 /**
304 * Test getTitle() with Invalid Params()
305 */
306 public function testGetTitleWithInvalidParams() {
307 $params = 99;
308 $customGroupTitle = CRM_Core_BAO_CustomGroup::getTitle($params);
309
310 $this->assertNull($customGroupTitle, 'Check that no custom Group Title is retreived');
311 }
312
313 /**
314 * Test getTitle()
315 */
316 public function testGetTitle() {
317 $customGrouptitle = 'My Custom Group';
318 $groupParams = array(
319 'title' => $customGrouptitle,
320 'name' => 'my_custom_group',
321 'style' => 'Tab',
322 'extends' => 'Individual',
323 'is_active' => 0,
324 'version' => 3,
325 );
326
327 $customGroup = Custom::createGroup($groupParams);
328 $customGroupId = $customGroup->id;
329
330 //get the custom group title
331 $title = CRM_Core_BAO_CustomGroup::getTitle($customGroupId);
332
333 //check for object update
334 $this->assertEquals($customGrouptitle, $title);
335
336 //cleanup DB by deleting customGroup
337 Custom::deleteGroup($customGroup);
338 }
339
340 /**
341 * Test deleteGroup()
342 */
343 public function testDeleteGroup() {
344 $customGrouptitle = 'My Custom Group';
345 $groupParams = array(
346 'title' => $customGrouptitle,
347 'name' => 'my_custom_group',
348 'style' => 'Tab',
349 'extends' => 'Individual',
350 'is_active' => 1,
351 'version' => 3,
352 );
353
354 $customGroup = Custom::createGroup($groupParams);
355
356 $customGroupId = $customGroup->id;
357
358 //get the custom group title
359 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
360 'Database check for custom group record.'
361 );
362 //check for group title
363 $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
364
365 //delete the group
366 $isDelete = CRM_Core_BAO_CustomGroup::deleteGroup($customGroup);
367
368 //check for delete
369 $this->assertEquals(TRUE, $isDelete);
370
371 //check the DB
372 $this->assertDBNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
373 'Database check for custom group record.'
374 );
375 }
376
377 /**
378 * Test createTable()
379 */
380 public function testCreateTable() {
381 $customGrouptitle = 'My Custom Group';
382 $groupParams = array(
383 'title' => $customGrouptitle,
384 'name' => 'my_custom_group',
385 'style' => 'Tab',
386 'extends' => 'Individual',
387 'is_active' => 1,
388 'version' => 3,
389 );
390
391 $customGroupBAO = new CRM_Core_BAO_CustomGroup();
392 $customGroupBAO->copyValues($groupParams);
393 $customGroup = $customGroupBAO->save();
394 $tableName = 'civicrm_value_test_group_' . $customGroup->id;
395 $customGroup->table_name = $tableName;
396 $customGroup = $customGroupBAO->save();
397 $customTable = CRM_Core_BAO_CustomGroup::createTable($customGroup);
398 $customGroupId = $customGroup->id;
399
400 //check db for custom group.
401 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
402 'Database check for custom group record.'
403 );
404 //check for custom group table name
405 $this->assertDBCompareValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name', 'id',
406 $tableName, 'Database check for custom group table name.'
407 );
408
409 //check for group title
410 $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
411
412 //cleanup DB by deleting customGroup
413 Custom::deleteGroup($customGroup);
414 }
415
416 /**
417 * Test checkCustomField()
418 */
419 public function testCheckCustomField() {
420 $customGroupTitle = 'My Custom Group';
421 $groupParams = array(
422 'title' => $customGroupTitle,
423 'name' => 'my_custom_group',
424 'extends' => 'Individual',
425 'help_pre' => 'Custom Group Help Pre',
426 'help_post' => 'Custom Group Help Post',
427 'is_active' => 1,
428 'collapse_display' => 1,
429 'version' => 3,
430 );
431
432 $customGroup = Custom::createGroup($groupParams);
433 $this->assertNotNull($customGroup->id, 'pre-requisite group not created successfully');
434 $customGroupId = $customGroup->id;
435
436 $customFieldLabel = 'Test Custom Field';
437 $fieldParams = array(
438 'custom_group_id' => $customGroupId,
439 'label' => $customFieldLabel,
440 'html_type' => 'Text',
441 'data_type' => 'String',
442 'is_required' => 1,
443 'is_searchable' => 0,
444 'is_active' => 1,
445 'version' => 3,
446 );
447
448 $customField = Custom::createField($fieldParams);
449 $this->assertNotNull($customField->id, 'pre-requisite field not created successfully');
450
451 $customFieldId = $customField->id;
452
453 //check db for custom group
454 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
455 'Database check for custom group record.'
456 );
457 $this->assertEquals($customGroupTitle, $dbCustomGroupTitle);
458
459 //check db for custom field
460 $dbCustomFieldLabel = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldId, 'label', 'id',
461 'Database check for custom field record.'
462 );
463 $this->assertEquals($customFieldLabel, $dbCustomFieldLabel);
464
465 //check the custom field type.
466 $params = array('Individual');
467 $usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
468 $this->assertEquals(FALSE, $usedFor);
469
470 $params = array('Contribution', 'Membership', 'Participant');
471 $usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
472 $this->assertEquals(TRUE, $usedFor);
473
474 //cleanup DB by deleting customGroup
475 Custom::deleteField($customField);
476 Custom::deleteGroup($customGroup);
477 }
478
479 /**
480 * Test getActiveGroups() with Invalid Params()
481 */
482 public function testGetActiveGroupsWithInvalidParams() {
483 $contactId = $this->individualCreate();
484 $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups('ABC', 'civicrm/contact/view/cd', $contactId);
485 $this->assertEquals(empty($activeGroups), TRUE, 'Check that Emprt params are retreived');
486 }
487
488 public function testGetActiveGroups() {
489 $contactId = $this->individualCreate();
490 $customGrouptitle = 'Test Custom Group';
491 $groupParams = array(
492 'title' => $customGrouptitle,
493 'name' => 'test_custom_group',
494 'style' => 'Tab',
495 'extends' => 'Individual',
496 'weight' => 10,
497 'is_active' => 1,
498 'version' => 3,
499 );
500
501 $customGroup = Custom::createGroup($groupParams);
502 $activeGroup = CRM_Core_BAO_CustomGroup::getActiveGroups('Individual', 'civicrm/contact/view/cd', $contactId);
503 foreach ($activeGroup as $key => $value) {
504 if ($value['id'] == $customGroup->id) {
505 $this->assertEquals($value['path'], 'civicrm/contact/view/cd');
506 $this->assertEquals($value['title'], $customGrouptitle);
507 $query = 'reset=1&gid=' . $customGroup->id . '&cid=' . $contactId;
508 $this->assertEquals($value['query'], $query);
509 }
510 }
511
512 Custom::deleteGroup($customGroup);
513 $this->contactDelete($contactId);
514 }
515
516 /**
517 * Test create()
518 */
519 public function testCreate() {
520 $params = array(
521 'title' => 'Test_Group_1',
522 'name' => 'test_group_1',
523 'extends' => array(0 => 'Individual', 1 => array()),
524 'weight' => 4,
525 'collapse_display' => 1,
526 'style' => 'Inline',
527 'help_pre' => 'This is Pre Help For Test Group 1',
528 'help_post' => 'This is Post Help For Test Group 1',
529 'is_active' => 1,
530 'version' => 3,
531 );
532 $customGroup = CRM_Core_BAO_CustomGroup::create($params);
533
534 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'title', 'id',
535 'Database check for custom group record.'
536 );
537 $this->assertEquals($params['title'], $dbCustomGroupTitle);
538
539 $dbCustomGroupTableName = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'table_name', 'id',
540 'Database check for custom group record.'
541 );
542 $this->assertEquals(strtolower("civicrm_value_{$params['name']}_{$customGroup->id}"), $dbCustomGroupTableName,
543 "The table name should be suffixed with '_ID' unless specified.");
544
545 Custom::deleteGroup($customGroup);
546 }
547
548 /**
549 * Test create() given a table_name
550 */
551 public function testCreateTableName() {
552 $params = array(
553 'title' => 'Test_Group_2',
554 'name' => 'test_group_2',
555 'table_name' => 'test_otherTableName',
556 'extends' => array(0 => 'Individual', 1 => array()),
557 'weight' => 4,
558 'collapse_display' => 1,
559 'style' => 'Inline',
560 'help_pre' => 'This is Pre Help For Test Group 1',
561 'help_post' => 'This is Post Help For Test Group 1',
562 'is_active' => 1,
563 'version' => 3,
564 );
565 $customGroup = CRM_Core_BAO_CustomGroup::create($params);
566
567 $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'title', 'id',
568 'Database check for custom group record.'
569 );
570 $this->assertEquals($params['title'], $dbCustomGroupTitle);
571
572 $dbCustomGroupTableName = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'table_name', 'id',
573 'Database check for custom group record.'
574 );
575 $this->assertEquals($params['table_name'], $dbCustomGroupTableName);
576
577 Custom::deleteGroup($customGroup);
578 }
579
580 /**
581 * Test isGroupEmpty()
582 */
583 public function testIsGroupEmpty() {
584 $customGrouptitle = 'Test Custom Group';
585 $groupParams = array(
586 'title' => $customGrouptitle,
587 'name' => 'test_custom_group',
588 'style' => 'Tab',
589 'extends' => 'Individual',
590 'weight' => 10,
591 'is_active' => 1,
592 'version' => 3,
593 );
594
595 $customGroup = Custom::createGroup($groupParams);
596 $customGroupId = $customGroup->id;
597 $isEmptyGroup = CRM_Core_BAO_CustomGroup::isGroupEmpty($customGroupId);
598
599 $this->assertEquals($isEmptyGroup, TRUE, 'Check that custom Group is Empty.');
600 Custom::deleteGroup($customGroup);
601 }
602
603 /**
604 * Test getGroupTitles() with Invalid Params()
605 */
606 public function testgetGroupTitlesWithInvalidParams() {
607 $params = array(99);
608 $groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params);
609 $this->assertTrue(empty($groupTitles), 'Check that no titles are recieved');
610 }
611
612 /**
613 * Test getGroupTitles()
614 */
615 public function testgetGroupTitles() {
616 $customGrouptitle = 'Test Custom Group';
617 $groupParams = array(
618 'title' => $customGrouptitle,
619 'name' => 'test_custom_group',
620 'style' => 'Tab',
621 'extends' => 'Individual',
622 'weight' => 10,
623 'is_active' => 1,
624 'version' => 3,
625 );
626
627 $customGroup = Custom::createGroup($groupParams);
628
629 $customGroupId = $customGroup->id;
630
631 $customFieldLabel = 'Test Custom Field';
632 $fieldParams = array(
633 'custom_group_id' => $customGroupId,
634 'label' => $customFieldLabel,
635 'html_type' => 'Text',
636 'data_type' => 'String',
637 'is_required' => 1,
638 'is_searchable' => 0,
639 'is_active' => 1,
640 'version' => 3,
641 );
642
643 $customField = Custom::createField($fieldParams);
644 $customFieldId = $customField->id;
645
646 $params = array($customFieldId);
647
648 $groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params);
649
650 $this->assertEquals($groupTitles[$customFieldId]['groupTitle'], 'Test Custom Group', 'Check Group Title.');
651 Custom::deleteGroup($customGroup);
652 }
653
654 }