Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / StatusPreferenceTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class api_v3_StatusPreferenceTest
14 *
15 * @package CiviCRM_APIv3
16 * @group headless
17 */
18 class api_v3_StatusPreferenceTest extends CiviUnitTestCase {
19 protected $_apiversion;
20 protected $_contactID;
21 protected $_locationType;
22 protected $_params;
23
24 public function setUp() {
25 $this->_apiversion = 3;
26 parent::setUp();
27 $this->useTransaction(TRUE);
28 $this->_params = [
29 'name' => 'test_check',
30 'domain_id' => 1,
31 'hush_until' => '20151212',
32 'ignore_severity' => 4,
33 'check_info' => NULL,
34 ];
35 }
36
37 public function testCreateStatusPreference() {
38 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
39 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
40 $id = $result['id'];
41 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
42 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
43
44 $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
45 }
46
47 public function testDeleteStatusPreference() {
48 // create one
49 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
50
51 $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
52 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
53
54 $get = $this->callAPISuccess('StatusPreference', 'get', [
55 'id' => $create['id'],
56 ]);
57 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
58 }
59
60 /**
61 * Test a get with empty params.
62 */
63 public function testStatusPreferenceGetEmptyParams() {
64 $result = $this->callAPISuccess('StatusPreference', 'Get', []);
65 }
66
67 /**
68 * Test a StatusPreference get.
69 */
70 public function testStatusPreferenceGet() {
71 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
72 $id = $statusPreference['id'];
73 $params = [
74 'id' => $id,
75 ];
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__);
81 }
82
83 /**
84 * Ensure you can't create a StatusPref with ignore_severity > 7.
85 */
86 public function testCreateInvalidMinimumReportSeverity() {
87 $this->_params['ignore_severity'] = 45;
88 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
89 }
90
91 /**
92 * Test creating a severity by name, not integer.
93 */
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__);
98 $id = $result['id'];
99 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
100 }
101
102 /**
103 * Test creating an invalid severity by name.
104 */
105 public function testCreateSeverityWithInvalidName() {
106 $this->_params['ignore_severity'] = 'wdsadasdarning';
107 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
108 }
109
110 }