3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class api_v3_StatusPreferenceTest
31 * @package CiviCRM_APIv3
34 class api_v3_StatusPreferenceTest
extends CiviUnitTestCase
{
35 protected $_apiversion;
36 protected $_contactID;
37 protected $_locationType;
41 public function setUp() {
42 $this->_apiversion
= 3;
44 $this->useTransaction(TRUE);
45 $this->_params
= array(
46 'name' => 'test_check',
48 'hush_until' => '20151212',
49 'ignore_severity' => 4,
54 public function testCreateStatusPreference() {
55 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
56 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
58 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__
);
59 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
61 $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id']));
64 public function testDeleteStatusPreference() {
66 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params
);
68 $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__
, __FILE__
);
69 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
71 $get = $this->callAPISuccess('StatusPreference', 'get', array(
72 'id' => $create['id'],
74 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__
);
78 * Test a get with empty params.
80 public function testStatusPreferenceGetEmptyParams() {
81 $result = $this->callAPISuccess('StatusPreference', 'Get', array());
85 * Test a StatusPreference get.
87 public function testStatusPreferenceGet() {
88 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params
);
89 $id = $statusPreference['id'];
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__
);
101 * Ensure you can't create a StatusPref with ignore_severity > 7.
103 public function testCreateInvalidMinimumReportSeverity() {
104 $this->_params
['ignore_severity'] = 45;
105 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params
);
109 * Test creating a severity by name, not integer.
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__
);
116 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
120 * Test creating an invalid severity by name.
122 public function testCreateSeverityWithInvalidName() {
123 $this->_params
['ignore_severity'] = 'wdsadasdarning';
124 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params
);