Commit | Line | Data |
---|---|---|
7e460124 J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
7e460124 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | ||
40 | ||
41 | public function setUp() { | |
42 | $this->_apiversion = 3; | |
43 | parent::setUp(); | |
44 | $this->useTransaction(TRUE); | |
45 | $this->_params = array( | |
46 | 'name' => 'test_check', | |
09f73c5c | 47 | 'domain_id' => 1, |
7e460124 | 48 | 'hush_until' => '20151212', |
a24a0be0 | 49 | 'ignore_severity' => 4, |
7e460124 J |
50 | 'check_info' => NULL, |
51 | ); | |
52 | } | |
53 | ||
54 | public function testCreateStatusPreference() { | |
55 | $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__); | |
56 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); | |
09f73c5c J |
57 | $id = $result['id']; |
58 | $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__); | |
a24a0be0 | 59 | $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
7e460124 J |
60 | |
61 | $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id'])); | |
62 | } | |
63 | ||
64 | public function testDeleteStatusPreference() { | |
09f73c5c | 65 | // create one |
7e460124 J |
66 | $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params); |
67 | ||
68 | $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); | |
69 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
70 | ||
71 | $get = $this->callAPISuccess('StatusPreference', 'get', array( | |
72 | 'id' => $create['id'], | |
73 | )); | |
74 | $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__); | |
75 | } | |
76 | ||
09f73c5c J |
77 | /** |
78 | * Test a get with empty params. | |
79 | */ | |
80 | public function testStatusPreferenceGetEmptyParams() { | |
81 | $result = $this->callAPISuccess('StatusPreference', 'Get', array()); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Test a StatusPreference get. | |
86 | */ | |
87 | public function testStatusPreferenceGet() { | |
88 | $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); | |
89 | $id = $statusPreference['id']; | |
90 | $params = array( | |
91 | 'id' => $id, | |
92 | ); | |
93 | $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__); | |
94 | $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__); | |
95 | $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__); | |
96 | $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__); | |
a24a0be0 | 97 | $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
09f73c5c J |
98 | } |
99 | ||
748d9d7f | 100 | /** |
a24a0be0 | 101 | * Ensure you can't create a StatusPref with ignore_severity > 7. |
748d9d7f J |
102 | */ |
103 | public function testCreateInvalidMinimumReportSeverity() { | |
a24a0be0 | 104 | $this->_params['ignore_severity'] = 45; |
748d9d7f J |
105 | $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params); |
106 | } | |
107 | ||
2bd410d6 J |
108 | /** |
109 | * Test creating a severity by name, not integer. | |
110 | */ | |
111 | public function testCreateSeverityByName() { | |
112 | // Any permutation of uppercase/lowercase should work. | |
a24a0be0 | 113 | $this->_params['ignore_severity'] = 'cRItical'; |
2bd410d6 J |
114 | $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__); |
115 | $id = $result['id']; | |
a24a0be0 | 116 | $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__); |
2bd410d6 J |
117 | } |
118 | ||
119 | /** | |
120 | * Test creating an invalid severity by name. | |
121 | */ | |
122 | public function testCreateSeverityWithInvalidName() { | |
a24a0be0 | 123 | $this->_params['ignore_severity'] = 'wdsadasdarning'; |
2bd410d6 J |
124 | $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params); |
125 | } | |
126 | ||
7e460124 | 127 | } |