4 * Class api_v3_CustomSearchTest
7 class api_v3_CustomSearchTest
extends CiviUnitTestCase
{
8 protected $_apiversion;
10 public function setUp(): void
{
11 $this->_apiversion
= 3;
13 $this->useTransaction(TRUE);
16 public function testCustomSearch() {
17 $result = $this->callAPISuccess('CustomSearch', 'create', [
18 'label' => 'Invalid, overwritten',
19 'description' => 'Longish description of the example search form',
20 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
22 $this->assertAPISuccess($result);
23 $this->assertEquals(1, $result['count']);
24 $entityId = $result['id'];
25 $this->assertTrue(is_numeric($entityId));
26 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
27 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
28 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
29 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
30 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
31 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
34 $result = $this->callAPISuccess('CustomSearch', 'create', [
39 $this->assertEquals(1, $result['count']);
40 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
41 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
42 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
43 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
44 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
45 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
48 $result = $this->callAPISuccess('CustomSearch', 'create', [
53 $this->assertEquals(1, $result['count']);
54 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
55 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
56 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
57 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
58 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
59 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
60 $check = $this->callAPISuccess('CustomSearch', 'get', ['id' => $entityId]);
61 if (!empty($check['count'])) {
62 $result = $this->callAPISuccess('CustomSearch', 'delete', [
66 $this->assertEquals(1, $result['count']);
67 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
68 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
69 OR label = "CRM_Contact_Form_Search_Custom_Examplez"