Merge pull request #7618 from eileenmcnaughton/CRM-17837
[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-2015 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
30
31
32 /**
33 * Class api_v3_StatusPreferenceTest
34 *
35 * @package CiviCRM_APIv3
36 */
37 class api_v3_StatusPreferenceTest extends CiviUnitTestCase {
38 protected $_apiversion;
39 protected $_contactID;
40 protected $_locationType;
41 protected $_params;
42
43
44 public function setUp() {
45 $this->_apiversion = 3;
46 parent::setUp();
47 $this->useTransaction(TRUE);
48 $this->_params = array(
49 'name' => 'test_check',
50 'domain_id' => 1,
51 'hush_until' => '20151212',
52 'ignore_severity' => 4,
53 'check_info' => NULL,
54 );
55 }
56
57 public function testCreateStatusPreference() {
58 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
59 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
60 $id = $result['id'];
61 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
62 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
63
64 $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id']));
65 }
66
67 public function testDeleteStatusPreference() {
68 // create one
69 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
70
71 $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
72 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
73
74 $get = $this->callAPISuccess('StatusPreference', 'get', array(
75 'id' => $create['id'],
76 ));
77 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
78 }
79
80 /**
81 * Test a get with empty params.
82 */
83 public function testStatusPreferenceGetEmptyParams() {
84 $result = $this->callAPISuccess('StatusPreference', 'Get', array());
85 }
86
87 /**
88 * Test a StatusPreference get.
89 */
90 public function testStatusPreferenceGet() {
91 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
92 $id = $statusPreference['id'];
93 $params = array(
94 'id' => $id,
95 );
96 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__);
97 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__);
98 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__);
99 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__);
100 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
101 }
102
103 /**
104 * Ensure you can't create a StatusPref with ignore_severity > 7.
105 */
106 public function testCreateInvalidMinimumReportSeverity() {
107 $this->_params['ignore_severity'] = 45;
108 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
109 }
110
111 /**
112 * Test creating a severity by name, not integer.
113 */
114 public function testCreateSeverityByName() {
115 // Any permutation of uppercase/lowercase should work.
116 $this->_params['ignore_severity'] = 'cRItical';
117 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
118 $id = $result['id'];
119 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
120 }
121
122 /**
123 * Test creating an invalid severity by name.
124 */
125 public function testCreateSeverityWithInvalidName() {
126 $this->_params['ignore_severity'] = 'wdsadasdarning';
127 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
128 }
129
130 }