Commit | Line | Data |
---|---|---|
7e460124 J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
7e460124 | 5 | | | |
7d61e75f TO |
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 | | |
7e460124 J |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
7e460124 J |
12 | /** |
13 | * Class api_v3_StatusPreferenceTest | |
14 | * | |
15 | * @package CiviCRM_APIv3 | |
acb109b7 | 16 | * @group headless |
7e460124 J |
17 | */ |
18 | class api_v3_StatusPreferenceTest extends CiviUnitTestCase { | |
7e460124 J |
19 | protected $_contactID; |
20 | protected $_locationType; | |
21 | protected $_params; | |
22 | ||
5d345864 | 23 | public function setUp(): void { |
7e460124 J |
24 | parent::setUp(); |
25 | $this->useTransaction(TRUE); | |
9099cab3 | 26 | $this->_params = [ |
7e460124 | 27 | 'name' => 'test_check', |
09f73c5c | 28 | 'domain_id' => 1, |
7e460124 | 29 | 'hush_until' => '20151212', |
a24a0be0 | 30 | 'ignore_severity' => 4, |
7e460124 | 31 | 'check_info' => NULL, |
9099cab3 | 32 | ]; |
7e460124 J |
33 | } |
34 | ||
fab5b18c SL |
35 | /** |
36 | * @dataProvider versionThreeAndFour | |
37 | */ | |
38 | public function testCreateStatusPreference($version) { | |
39 | $this->_apiversion = $version; | |
7e460124 J |
40 | $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__); |
41 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); | |
09f73c5c J |
42 | $id = $result['id']; |
43 | $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__); | |
a24a0be0 | 44 | $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
7e460124 | 45 | |
9099cab3 | 46 | $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]); |
7e460124 J |
47 | } |
48 | ||
fab5b18c SL |
49 | /** |
50 | * @dataProvider versionThreeAndFour | |
51 | */ | |
52 | public function testDeleteStatusPreference($version) { | |
53 | $this->_apiversion = $version; | |
09f73c5c | 54 | // create one |
7e460124 J |
55 | $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params); |
56 | ||
9099cab3 | 57 | $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); |
7e460124 J |
58 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
59 | ||
9099cab3 | 60 | $get = $this->callAPISuccess('StatusPreference', 'get', [ |
7e460124 | 61 | 'id' => $create['id'], |
9099cab3 | 62 | ]); |
7e460124 J |
63 | $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__); |
64 | } | |
65 | ||
09f73c5c J |
66 | /** |
67 | * Test a get with empty params. | |
fab5b18c | 68 | * @dataProvider versionThreeAndFour |
09f73c5c | 69 | */ |
fab5b18c SL |
70 | public function testStatusPreferenceGetEmptyParams($version) { |
71 | $this->_apiversion = $version; | |
9099cab3 | 72 | $result = $this->callAPISuccess('StatusPreference', 'Get', []); |
09f73c5c J |
73 | } |
74 | ||
75 | /** | |
76 | * Test a StatusPreference get. | |
fab5b18c | 77 | * @dataProvider versionThreeAndFour |
09f73c5c | 78 | */ |
fab5b18c SL |
79 | public function testStatusPreferenceGet($version) { |
80 | $this->_apiversion = $version; | |
09f73c5c J |
81 | $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); |
82 | $id = $statusPreference['id']; | |
9099cab3 | 83 | $params = [ |
09f73c5c | 84 | 'id' => $id, |
9099cab3 | 85 | ]; |
09f73c5c J |
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__); | |
a24a0be0 | 90 | $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
09f73c5c J |
91 | } |
92 | ||
748d9d7f | 93 | /** |
a24a0be0 | 94 | * Ensure you can't create a StatusPref with ignore_severity > 7. |
fab5b18c | 95 | * @dataProvider versionThreeAndFour |
748d9d7f | 96 | */ |
fab5b18c SL |
97 | public function testCreateInvalidMinimumReportSeverity($version) { |
98 | $this->_apiversion = $version; | |
a24a0be0 | 99 | $this->_params['ignore_severity'] = 45; |
748d9d7f J |
100 | $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params); |
101 | } | |
102 | ||
2bd410d6 J |
103 | /** |
104 | * Test creating a severity by name, not integer. | |
fab5b18c | 105 | * @dataProvider versionThreeAndFour |
2bd410d6 | 106 | */ |
fab5b18c SL |
107 | public function testCreateSeverityByName($version) { |
108 | $this->_apiversion = $version; | |
2bd410d6 | 109 | // Any permutation of uppercase/lowercase should work. |
a24a0be0 | 110 | $this->_params['ignore_severity'] = 'cRItical'; |
2bd410d6 J |
111 | $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__); |
112 | $id = $result['id']; | |
a24a0be0 | 113 | $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
2bd410d6 J |
114 | } |
115 | ||
116 | /** | |
117 | * Test creating an invalid severity by name. | |
fab5b18c | 118 | * @dataProvider versionThreeAndFour |
2bd410d6 | 119 | */ |
fab5b18c SL |
120 | public function testCreateSeverityWithInvalidName($version) { |
121 | $this->_apiversion = $version; | |
a24a0be0 | 122 | $this->_params['ignore_severity'] = 'wdsadasdarning'; |
2bd410d6 J |
123 | $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params); |
124 | } | |
125 | ||
7e460124 | 126 | } |