Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
aba1cd8b EM |
3 | /** |
4 | * Class api_v3_CustomSearchTest | |
acb109b7 | 5 | * @group headless |
aba1cd8b | 6 | */ |
6a488035 TO |
7 | class api_v3_CustomSearchTest extends CiviUnitTestCase { |
8 | protected $_apiversion; | |
b7c9bc4c | 9 | |
00be9182 | 10 | public function setUp() { |
6a488035 TO |
11 | $this->_apiversion = 3; |
12 | parent::setUp(); | |
bdd3d762 | 13 | $this->useTransaction(TRUE); |
6a488035 TO |
14 | } |
15 | ||
6a488035 | 16 | public function testCustomSearch() { |
9099cab3 | 17 | $result = $this->callAPISuccess('CustomSearch', 'create', [ |
6a488035 TO |
18 | 'label' => 'Invalid, overwritten', |
19 | 'description' => 'Longish description of the example search form', | |
20 | 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez', | |
9099cab3 | 21 | ]); |
e310e129 | 22 | $this->assertAPISuccess($result); |
ba4a1892 | 23 | $this->assertEquals(1, $result['count']); |
6a488035 | 24 | $entityId = $result['id']; |
ba4a1892 | 25 | $this->assertTrue(is_numeric($entityId)); |
6a488035 TO |
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" | |
0201b57f | 29 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") '); |
6a488035 TO |
30 | $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value |
31 | WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"'); | |
32 | ||
33 | // deactivate | |
9099cab3 | 34 | $result = $this->callAPISuccess('CustomSearch', 'create', [ |
6a488035 TO |
35 | 'id' => $entityId, |
36 | 'is_active' => 0, | |
9099cab3 | 37 | ]); |
fc928539 | 38 | |
ba4a1892 | 39 | $this->assertEquals(1, $result['count']); |
6a488035 TO |
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" | |
0201b57f | 43 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") '); |
6a488035 TO |
44 | $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value |
45 | WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"'); | |
46 | ||
47 | // activate | |
9099cab3 | 48 | $result = $this->callAPISuccess('CustomSearch', 'create', [ |
6a488035 TO |
49 | 'id' => $entityId, |
50 | 'is_active' => 1, | |
9099cab3 | 51 | ]); |
fc928539 | 52 | |
ba4a1892 | 53 | $this->assertEquals(1, $result['count']); |
6a488035 TO |
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" | |
0201b57f | 57 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") '); |
6a488035 TO |
58 | $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value |
59 | WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"'); | |
9099cab3 | 60 | $check = $this->callAPISuccess('CustomSearch', 'get', ['id' => $entityId]); |
a60c0bc8 | 61 | if (!empty($check['count'])) { |
9099cab3 | 62 | $result = $this->callAPISuccess('CustomSearch', 'delete', [ |
a60c0bc8 | 63 | 'id' => $entityId, |
9099cab3 | 64 | ]); |
a60c0bc8 | 65 | } |
ba4a1892 | 66 | $this->assertEquals(1, $result['count']); |
6a488035 TO |
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" | |
70 | '); | |
71 | } | |
96025800 | 72 | |
6a488035 | 73 | } |