-
-
Notifications
You must be signed in to change notification settings - Fork 827
/
Copy pathCustomSearchTest.php
73 lines (65 loc) · 2.8 KB
/
CustomSearchTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Class api_v3_CustomSearchTest
* @group headless
*/
class api_v3_CustomSearchTest extends CiviUnitTestCase {
protected $_apiversion;
public function setUp(): void {
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction(TRUE);
}
public function testCustomSearch(): void {
$result = $this->callAPISuccess('CustomSearch', 'create', [
'label' => 'Invalid, overwritten',
'description' => 'Longish description of the example search form',
'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$entityId = $result['id'];
$this->assertTrue(is_numeric($entityId));
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
AND label = "CRM_Contact_Form_Search_Custom_Examplez"
AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
$this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
// deactivate
$result = $this->callAPISuccess('CustomSearch', 'create', [
'id' => $entityId,
'is_active' => 0,
]);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
AND label = "CRM_Contact_Form_Search_Custom_Examplez"
AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
$this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
// activate
$result = $this->callAPISuccess('CustomSearch', 'create', [
'id' => $entityId,
'is_active' => 1,
]);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
AND label = "CRM_Contact_Form_Search_Custom_Examplez"
AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
$this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
$check = $this->callAPISuccess('CustomSearch', 'get', ['id' => $entityId]);
if (!empty($check['count'])) {
$result = $this->callAPISuccess('CustomSearch', 'delete', [
'id' => $entityId,
]);
}
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
OR label = "CRM_Contact_Form_Search_Custom_Examplez"
');
}
}