3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class api_v3_StatusPreferenceTest
15 * @package CiviCRM_APIv3
18 class api_v3_StatusPreferenceTest
extends CiviUnitTestCase
{
19 protected $_apiversion;
20 protected $_contactID;
21 protected $_locationType;
24 public function setUp() {
25 $this->_apiversion
= 3;
27 $this->useTransaction(TRUE);
29 'name' => 'test_check',
31 'hush_until' => '20151212',
32 'ignore_severity' => 4,
37 public function testCreateStatusPreference() {
38 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
39 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
41 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__
);
42 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
44 $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
47 public function testDeleteStatusPreference() {
49 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params
);
51 $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
52 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
54 $get = $this->callAPISuccess('StatusPreference', 'get', [
55 'id' => $create['id'],
57 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__
);
61 * Test a get with empty params.
63 public function testStatusPreferenceGetEmptyParams() {
64 $result = $this->callAPISuccess('StatusPreference', 'Get', []);
68 * Test a StatusPreference get.
70 public function testStatusPreferenceGet() {
71 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params
);
72 $id = $statusPreference['id'];
76 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__
, __FILE__
);
77 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__
);
78 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__
);
79 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__
);
80 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
84 * Ensure you can't create a StatusPref with ignore_severity > 7.
86 public function testCreateInvalidMinimumReportSeverity() {
87 $this->_params
['ignore_severity'] = 45;
88 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params
);
92 * Test creating a severity by name, not integer.
94 public function testCreateSeverityByName() {
95 // Any permutation of uppercase/lowercase should work.
96 $this->_params
['ignore_severity'] = 'cRItical';
97 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
99 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
103 * Test creating an invalid severity by name.
105 public function testCreateSeverityWithInvalidName() {
106 $this->_params
['ignore_severity'] = 'wdsadasdarning';
107 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params
);