Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-10-01-19-08-00
[civicrm-core.git] / tests / phpunit / api / v3 / CustomSearchTest.php
CommitLineData
6a488035
TO
1<?php
2
3require_once 'CiviTest/CiviUnitTestCase.php';
4
aba1cd8b
EM
5/**
6 * Class api_v3_CustomSearchTest
7 */
6a488035
TO
8class api_v3_CustomSearchTest extends CiviUnitTestCase {
9 protected $_apiversion;
b7c9bc4c 10
6a488035
TO
11 function setUp() {
12 $this->_apiversion = 3;
13 parent::setUp();
14 }
15
16 function tearDown() {}
17
18 public function testCustomSearch() {
fc928539 19 $result = $this->callAPISuccess('CustomSearch', 'create', array(
6a488035
TO
20 'label' => 'Invalid, overwritten',
21 'description' => 'Longish description of the example search form',
22 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
23 ));
e310e129 24 $this->assertAPISuccess($result);
6a488035
TO
25 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
26 $entityId = $result['id'];
27 $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__);
28 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
29 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
30 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
0201b57f 31 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
6a488035
TO
32 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
33 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
34
35 // deactivate
fc928539 36 $result = $this->callAPISuccess('CustomSearch', 'create', array(
6a488035
TO
37 'id' => $entityId,
38 'is_active' => 0,
39 ));
fc928539 40
6a488035
TO
41 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
42 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
43 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
44 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
0201b57f 45 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
6a488035
TO
46 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
47 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
48
49 // activate
fc928539 50 $result = $this->callAPISuccess('CustomSearch', 'create', array(
6a488035
TO
51 'id' => $entityId,
52 'is_active' => 1,
53 ));
fc928539 54
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"
0201b57f 59 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
6a488035
TO
60 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
61 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
62
fc928539 63 $result = $this->callAPISuccess('CustomSearch', 'delete', array(
6a488035
TO
64 'id' => $entityId,
65 ));
6a488035
TO
66 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
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 }
72}