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