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 $_contactID;
20 protected $_locationType;
23 public function setUp(): void
{
25 $this->useTransaction(TRUE);
27 'name' => 'test_check',
29 'hush_until' => '20151212',
30 'ignore_severity' => 4,
36 * @dataProvider versionThreeAndFour
38 public function testCreateStatusPreference($version) {
39 $this->_apiversion
= $version;
40 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
41 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
43 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__
);
44 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
46 $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
50 * @dataProvider versionThreeAndFour
52 public function testDeleteStatusPreference($version) {
53 $this->_apiversion
= $version;
55 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params
);
57 $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
58 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
60 $get = $this->callAPISuccess('StatusPreference', 'get', [
61 'id' => $create['id'],
63 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__
);
67 * Test a get with empty params.
68 * @dataProvider versionThreeAndFour
70 public function testStatusPreferenceGetEmptyParams($version) {
71 $this->_apiversion
= $version;
72 $result = $this->callAPISuccess('StatusPreference', 'Get', []);
76 * Test a StatusPreference get.
77 * @dataProvider versionThreeAndFour
79 public function testStatusPreferenceGet($version) {
80 $this->_apiversion
= $version;
81 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params
);
82 $id = $statusPreference['id'];
86 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__
, __FILE__
);
87 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__
);
88 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__
);
89 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__
);
90 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
94 * Ensure you can't create a StatusPref with ignore_severity > 7.
95 * @dataProvider versionThreeAndFour
97 public function testCreateInvalidMinimumReportSeverity($version) {
98 $this->_apiversion
= $version;
99 $this->_params
['ignore_severity'] = 45;
100 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params
);
104 * Test creating a severity by name, not integer.
105 * @dataProvider versionThreeAndFour
107 public function testCreateSeverityByName($version) {
108 $this->_apiversion
= $version;
109 // Any permutation of uppercase/lowercase should work.
110 $this->_params
['ignore_severity'] = 'cRItical';
111 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
113 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__
);
117 * Test creating an invalid severity by name.
118 * @dataProvider versionThreeAndFour
120 public function testCreateSeverityWithInvalidName($version) {
121 $this->_apiversion
= $version;
122 $this->_params
['ignore_severity'] = 'wdsadasdarning';
123 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params
);