Merge pull request #15666 from revati90/shared_address
[civicrm-core.git] / tests / phpunit / api / v3 / StatusPreferenceTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class api_v3_StatusPreferenceTest
30 *
31 * @package CiviCRM_APIv3
32 * @group headless
33 */
34 class api_v3_StatusPreferenceTest extends CiviUnitTestCase {
35 protected $_apiversion;
36 protected $_contactID;
37 protected $_locationType;
38 protected $_params;
39
40 public function setUp() {
41 $this->_apiversion = 3;
42 parent::setUp();
43 $this->useTransaction(TRUE);
44 $this->_params = [
45 'name' => 'test_check',
46 'domain_id' => 1,
47 'hush_until' => '20151212',
48 'ignore_severity' => 4,
49 'check_info' => NULL,
50 ];
51 }
52
53 public function testCreateStatusPreference() {
54 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
55 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
56 $id = $result['id'];
57 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
58 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
59
60 $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
61 }
62
63 public function testDeleteStatusPreference() {
64 // create one
65 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
66
67 $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
68 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
69
70 $get = $this->callAPISuccess('StatusPreference', 'get', [
71 'id' => $create['id'],
72 ]);
73 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
74 }
75
76 /**
77 * Test a get with empty params.
78 */
79 public function testStatusPreferenceGetEmptyParams() {
80 $result = $this->callAPISuccess('StatusPreference', 'Get', []);
81 }
82
83 /**
84 * Test a StatusPreference get.
85 */
86 public function testStatusPreferenceGet() {
87 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
88 $id = $statusPreference['id'];
89 $params = [
90 'id' => $id,
91 ];
92 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__);
93 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__);
94 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__);
95 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__);
96 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
97 }
98
99 /**
100 * Ensure you can't create a StatusPref with ignore_severity > 7.
101 */
102 public function testCreateInvalidMinimumReportSeverity() {
103 $this->_params['ignore_severity'] = 45;
104 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
105 }
106
107 /**
108 * Test creating a severity by name, not integer.
109 */
110 public function testCreateSeverityByName() {
111 // Any permutation of uppercase/lowercase should work.
112 $this->_params['ignore_severity'] = 'cRItical';
113 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
114 $id = $result['id'];
115 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
116 }
117
118 /**
119 * Test creating an invalid severity by name.
120 */
121 public function testCreateSeverityWithInvalidName() {
122 $this->_params['ignore_severity'] = 'wdsadasdarning';
123 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
124 }
125
126 }