Merge pull request #11965 from colemanw/CRM-21855
[civicrm-core.git] / tests / phpunit / api / v3 / StatusPreferenceTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
41 public function setUp() {
42 $this->_apiversion = 3;
43 parent::setUp();
44 $this->useTransaction(TRUE);
45 $this->_params = array(
46 'name' => 'test_check',
47 'domain_id' => 1,
48 'hush_until' => '20151212',
49 'ignore_severity' => 4,
50 'check_info' => NULL,
51 );
52 }
53
54 public function testCreateStatusPreference() {
55 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
56 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
57 $id = $result['id'];
58 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
59 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
60
61 $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id']));
62 }
63
64 public function testDeleteStatusPreference() {
65 // create one
66 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
67
68 $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
69 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
70
71 $get = $this->callAPISuccess('StatusPreference', 'get', array(
72 'id' => $create['id'],
73 ));
74 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
75 }
76
77 /**
78 * Test a get with empty params.
79 */
80 public function testStatusPreferenceGetEmptyParams() {
81 $result = $this->callAPISuccess('StatusPreference', 'Get', array());
82 }
83
84 /**
85 * Test a StatusPreference get.
86 */
87 public function testStatusPreferenceGet() {
88 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
89 $id = $statusPreference['id'];
90 $params = array(
91 'id' => $id,
92 );
93 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__);
94 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__);
95 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__);
96 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__);
97 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
98 }
99
100 /**
101 * Ensure you can't create a StatusPref with ignore_severity > 7.
102 */
103 public function testCreateInvalidMinimumReportSeverity() {
104 $this->_params['ignore_severity'] = 45;
105 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
106 }
107
108 /**
109 * Test creating a severity by name, not integer.
110 */
111 public function testCreateSeverityByName() {
112 // Any permutation of uppercase/lowercase should work.
113 $this->_params['ignore_severity'] = 'cRItical';
114 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
115 $id = $result['id'];
116 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
117 }
118
119 /**
120 * Test creating an invalid severity by name.
121 */
122 public function testCreateSeverityWithInvalidName() {
123 $this->_params['ignore_severity'] = 'wdsadasdarning';
124 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
125 }
126
127 }