Commit | Line | Data |
---|---|---|
7e460124 J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
7e460124 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
7e460124 J |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
7e460124 J |
28 | /** |
29 | * Class api_v3_StatusPreferenceTest | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
acb109b7 | 32 | * @group headless |
7e460124 J |
33 | */ |
34 | class api_v3_StatusPreferenceTest extends CiviUnitTestCase { | |
35 | protected $_apiversion; | |
36 | protected $_contactID; | |
37 | protected $_locationType; | |
38 | protected $_params; | |
39 | ||
7e460124 J |
40 | public function setUp() { |
41 | $this->_apiversion = 3; | |
42 | parent::setUp(); | |
43 | $this->useTransaction(TRUE); | |
9099cab3 | 44 | $this->_params = [ |
7e460124 | 45 | 'name' => 'test_check', |
09f73c5c | 46 | 'domain_id' => 1, |
7e460124 | 47 | 'hush_until' => '20151212', |
a24a0be0 | 48 | 'ignore_severity' => 4, |
7e460124 | 49 | 'check_info' => NULL, |
9099cab3 | 50 | ]; |
7e460124 J |
51 | } |
52 | ||
53 | public function testCreateStatusPreference() { | |
54 | $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__); | |
55 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); | |
09f73c5c J |
56 | $id = $result['id']; |
57 | $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__); | |
a24a0be0 | 58 | $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
7e460124 | 59 | |
9099cab3 | 60 | $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]); |
7e460124 J |
61 | } |
62 | ||
63 | public function testDeleteStatusPreference() { | |
09f73c5c | 64 | // create one |
7e460124 J |
65 | $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params); |
66 | ||
9099cab3 | 67 | $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); |
7e460124 J |
68 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
69 | ||
9099cab3 | 70 | $get = $this->callAPISuccess('StatusPreference', 'get', [ |
7e460124 | 71 | 'id' => $create['id'], |
9099cab3 | 72 | ]); |
7e460124 J |
73 | $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__); |
74 | } | |
75 | ||
09f73c5c J |
76 | /** |
77 | * Test a get with empty params. | |
78 | */ | |
79 | public function testStatusPreferenceGetEmptyParams() { | |
9099cab3 | 80 | $result = $this->callAPISuccess('StatusPreference', 'Get', []); |
09f73c5c J |
81 | } |
82 | ||
83 | /** | |
84 | * Test a StatusPreference get. | |
85 | */ | |
86 | public function testStatusPreferenceGet() { | |
87 | $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); | |
88 | $id = $statusPreference['id']; | |
9099cab3 | 89 | $params = [ |
09f73c5c | 90 | 'id' => $id, |
9099cab3 | 91 | ]; |
09f73c5c J |
92 | $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__); |
93 | $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__); | |
94 | $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__); | |
95 | $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__); | |
a24a0be0 | 96 | $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
09f73c5c J |
97 | } |
98 | ||
748d9d7f | 99 | /** |
a24a0be0 | 100 | * Ensure you can't create a StatusPref with ignore_severity > 7. |
748d9d7f J |
101 | */ |
102 | public function testCreateInvalidMinimumReportSeverity() { | |
a24a0be0 | 103 | $this->_params['ignore_severity'] = 45; |
748d9d7f J |
104 | $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params); |
105 | } | |
106 | ||
2bd410d6 J |
107 | /** |
108 | * Test creating a severity by name, not integer. | |
109 | */ | |
110 | public function testCreateSeverityByName() { | |
111 | // Any permutation of uppercase/lowercase should work. | |
a24a0be0 | 112 | $this->_params['ignore_severity'] = 'cRItical'; |
2bd410d6 J |
113 | $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__); |
114 | $id = $result['id']; | |
a24a0be0 | 115 | $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
2bd410d6 J |
116 | } |
117 | ||
118 | /** | |
119 | * Test creating an invalid severity by name. | |
120 | */ | |
121 | public function testCreateSeverityWithInvalidName() { | |
a24a0be0 | 122 | $this->_params['ignore_severity'] = 'wdsadasdarning'; |
2bd410d6 J |
123 | $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params); |
124 | } | |
125 | ||
7e460124 | 126 | } |