CRM-13072 upgrade Paritipant Payment test classes to pass
[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() {
16 $result = civicrm_api('CustomSearch', 'create', array(
17 'version' => $this->_apiversion,
18 'label' => 'Invalid, overwritten',
19 'description' => 'Longish description of the example search form',
20 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
21 ));
e310e129 22 $this->assertAPISuccess($result);
6a488035
TO
23 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
24 $entityId = $result['id'];
25 $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__);
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"
46a29d7d 29 AND option_group_id = 25');
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
34 $result = civicrm_api('CustomSearch', 'create', array(
35 'version' => $this->_apiversion,
36 'id' => $entityId,
37 'is_active' => 0,
38 ));
e310e129 39 $this->assertAPISuccess($result);
6a488035
TO
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"
46a29d7d 44 AND option_group_id = 25');
6a488035
TO
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 = civicrm_api('CustomSearch', 'create', array(
50 'version' => $this->_apiversion,
51 'id' => $entityId,
52 'is_active' => 1,
53 ));
e310e129 54 $this->assertAPISuccess($result);
6a488035
TO
55 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
56 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
57 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
58 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
46a29d7d 59 AND option_group_id = 25');
6a488035
TO
60 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
61 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
62
63 $result = civicrm_api('CustomSearch', 'delete', array(
64 'version' => $this->_apiversion,
65 'id' => $entityId,
66 ));
e310e129 67 $this->assertAPISuccess($result);
6a488035
TO
68 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
69 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
70 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
71 OR label = "CRM_Contact_Form_Search_Custom_Examplez"
72 ');
73 }
74}