Merge branch 'angular-tests' of https://github.com/giant-rabbit/civicrm-core into...
[civicrm-core.git] / tests / phpunit / api / v3 / CustomSearchTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4
5 /**
6 * Class api_v3_CustomSearchTest
7 */
8 class api_v3_CustomSearchTest extends CiviUnitTestCase {
9 protected $_apiversion;
10
11 public function setUp() {
12 $this->_apiversion = 3;
13 parent::setUp();
14 $this->useTransaction(TRUE);
15 }
16
17 public function testCustomSearch() {
18 $result = $this->callAPISuccess('CustomSearch', 'create', array(
19 'label' => 'Invalid, overwritten',
20 'description' => 'Longish description of the example search form',
21 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
22 ));
23 $this->assertAPISuccess($result);
24 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
25 $entityId = $result['id'];
26 $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__);
27 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
28 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
29 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
30 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
31 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
32 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
33
34 // deactivate
35 $result = $this->callAPISuccess('CustomSearch', 'create', array(
36 'id' => $entityId,
37 'is_active' => 0,
38 ));
39
40 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
41 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
42 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
43 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
44 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
45 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
46 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
47
48 // activate
49 $result = $this->callAPISuccess('CustomSearch', 'create', array(
50 'id' => $entityId,
51 'is_active' => 1,
52 ));
53
54 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
55 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
56 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
57 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
58 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
59 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
60 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
61
62 $result = $this->callAPISuccess('CustomSearch', 'delete', array(
63 'id' => $entityId,
64 ));
65 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
66 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
67 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
68 OR label = "CRM_Contact_Form_Search_Custom_Examplez"
69 ');
70 }
71 }