tests/phpunit - Declare `@group headless`
[civicrm-core.git] / tests / phpunit / api / v3 / CustomSearchTest.php
1 <?php
2
3 /**
4 * Class api_v3_CustomSearchTest
5 * @group headless
6 */
7 class api_v3_CustomSearchTest extends CiviUnitTestCase {
8 protected $_apiversion;
9
10 public function setUp() {
11 $this->_apiversion = 3;
12 parent::setUp();
13 $this->useTransaction(TRUE);
14 }
15
16 public function testCustomSearch() {
17 $result = $this->callAPISuccess('CustomSearch', 'create', array(
18 'label' => 'Invalid, overwritten',
19 'description' => 'Longish description of the example search form',
20 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
21 ));
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"');
32
33 // deactivate
34 $result = $this->callAPISuccess('CustomSearch', 'create', array(
35 'id' => $entityId,
36 'is_active' => 0,
37 ));
38
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"');
46
47 // activate
48 $result = $this->callAPISuccess('CustomSearch', 'create', array(
49 'id' => $entityId,
50 'is_active' => 1,
51 ));
52
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
61 $result = $this->callAPISuccess('CustomSearch', 'delete', array(
62 'id' => $entityId,
63 ));
64 $this->assertEquals(1, $result['count']);
65 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
66 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
67 OR label = "CRM_Contact_Form_Search_Custom_Examplez"
68 ');
69 }
70
71 }