CRM-15855 - Allow mailings to be saved (but not sent) without name+subject.
[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
00be9182 11 public function setUp() {
6a488035
TO
12 $this->_apiversion = 3;
13 parent::setUp();
bdd3d762 14 $this->useTransaction(TRUE);
6a488035
TO
15 }
16
6a488035 17 public function testCustomSearch() {
fc928539 18 $result = $this->callAPISuccess('CustomSearch', 'create', array(
6a488035
TO
19 'label' => 'Invalid, overwritten',
20 'description' => 'Longish description of the example search form',
21 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
22 ));
e310e129 23 $this->assertAPISuccess($result);
6a488035
TO
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"
0201b57f 30 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
6a488035
TO
31 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
32 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
33
34 // deactivate
fc928539 35 $result = $this->callAPISuccess('CustomSearch', 'create', array(
6a488035
TO
36 'id' => $entityId,
37 'is_active' => 0,
38 ));
fc928539 39
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"
0201b57f 44 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
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
fc928539 49 $result = $this->callAPISuccess('CustomSearch', 'create', array(
6a488035
TO
50 'id' => $entityId,
51 'is_active' => 1,
52 ));
fc928539 53
6a488035
TO
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"
0201b57f 58 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
6a488035
TO
59 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
60 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
61
fc928539 62 $result = $this->callAPISuccess('CustomSearch', 'delete', array(
6a488035
TO
63 'id' => $entityId,
64 ));
6a488035
TO
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 }
96025800 71
6a488035 72}