Fix token subscriber to format the display of the custom tokens
[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 $_contactID;
20 protected $_locationType;
21 protected $_params;
22
23 public function setUp() {
24 parent::setUp();
25 $this->useTransaction(TRUE);
26 $this->_params = [
27 'name' => 'test_check',
28 'domain_id' => 1,
29 'hush_until' => '20151212',
30 'ignore_severity' => 4,
31 'check_info' => NULL,
32 ];
33 }
34
35 /**
36 * @dataProvider versionThreeAndFour
37 */
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__);
42 $id = $result['id'];
43 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
44 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
45
46 $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
47 }
48
49 /**
50 * @dataProvider versionThreeAndFour
51 */
52 public function testDeleteStatusPreference($version) {
53 $this->_apiversion = $version;
54 // create one
55 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
56
57 $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
58 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
59
60 $get = $this->callAPISuccess('StatusPreference', 'get', [
61 'id' => $create['id'],
62 ]);
63 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
64 }
65
66 /**
67 * Test a get with empty params.
68 * @dataProvider versionThreeAndFour
69 */
70 public function testStatusPreferenceGetEmptyParams($version) {
71 $this->_apiversion = $version;
72 $result = $this->callAPISuccess('StatusPreference', 'Get', []);
73 }
74
75 /**
76 * Test a StatusPreference get.
77 * @dataProvider versionThreeAndFour
78 */
79 public function testStatusPreferenceGet($version) {
80 $this->_apiversion = $version;
81 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
82 $id = $statusPreference['id'];
83 $params = [
84 'id' => $id,
85 ];
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__);
91 }
92
93 /**
94 * Ensure you can't create a StatusPref with ignore_severity > 7.
95 * @dataProvider versionThreeAndFour
96 */
97 public function testCreateInvalidMinimumReportSeverity($version) {
98 $this->_apiversion = $version;
99 $this->_params['ignore_severity'] = 45;
100 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
101 }
102
103 /**
104 * Test creating a severity by name, not integer.
105 * @dataProvider versionThreeAndFour
106 */
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__);
112 $id = $result['id'];
113 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
114 }
115
116 /**
117 * Test creating an invalid severity by name.
118 * @dataProvider versionThreeAndFour
119 */
120 public function testCreateSeverityWithInvalidName($version) {
121 $this->_apiversion = $version;
122 $this->_params['ignore_severity'] = 'wdsadasdarning';
123 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
124 }
125
126 }