Merge pull request #7642 from totten/master-wp-path
[civicrm-core.git] / tests / phpunit / api / v3 / StatusPreferenceTest.php
CommitLineData
7e460124
J
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
7e460124
J
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
28
29require_once 'CiviTest/CiviUnitTestCase.php';
30
31
32/**
33 * Class api_v3_StatusPreferenceTest
34 *
35 * @package CiviCRM_APIv3
36 */
37class api_v3_StatusPreferenceTest extends CiviUnitTestCase {
38 protected $_apiversion;
39 protected $_contactID;
40 protected $_locationType;
41 protected $_params;
42
43
44 public function setUp() {
45 $this->_apiversion = 3;
46 parent::setUp();
47 $this->useTransaction(TRUE);
48 $this->_params = array(
49 'name' => 'test_check',
09f73c5c 50 'domain_id' => 1,
7e460124 51 'hush_until' => '20151212',
a24a0be0 52 'ignore_severity' => 4,
7e460124
J
53 'check_info' => NULL,
54 );
55 }
56
57 public function testCreateStatusPreference() {
58 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
59 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
09f73c5c
J
60 $id = $result['id'];
61 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
a24a0be0 62 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
7e460124
J
63
64 $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id']));
65 }
66
67 public function testDeleteStatusPreference() {
09f73c5c 68 // create one
7e460124
J
69 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
70
71 $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
72 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
73
74 $get = $this->callAPISuccess('StatusPreference', 'get', array(
75 'id' => $create['id'],
76 ));
77 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
78 }
79
09f73c5c
J
80 /**
81 * Test a get with empty params.
82 */
83 public function testStatusPreferenceGetEmptyParams() {
84 $result = $this->callAPISuccess('StatusPreference', 'Get', array());
85 }
86
87 /**
88 * Test a StatusPreference get.
89 */
90 public function testStatusPreferenceGet() {
91 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
92 $id = $statusPreference['id'];
93 $params = array(
94 'id' => $id,
95 );
96 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__);
97 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__);
98 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__);
99 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__);
a24a0be0 100 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
09f73c5c
J
101 }
102
748d9d7f 103 /**
a24a0be0 104 * Ensure you can't create a StatusPref with ignore_severity > 7.
748d9d7f
J
105 */
106 public function testCreateInvalidMinimumReportSeverity() {
a24a0be0 107 $this->_params['ignore_severity'] = 45;
748d9d7f
J
108 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
109 }
110
2bd410d6
J
111 /**
112 * Test creating a severity by name, not integer.
113 */
114 public function testCreateSeverityByName() {
115 // Any permutation of uppercase/lowercase should work.
a24a0be0 116 $this->_params['ignore_severity'] = 'cRItical';
2bd410d6
J
117 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
118 $id = $result['id'];
a24a0be0 119 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
2bd410d6
J
120 }
121
122 /**
123 * Test creating an invalid severity by name.
124 */
125 public function testCreateSeverityWithInvalidName() {
a24a0be0 126 $this->_params['ignore_severity'] = 'wdsadasdarning';
2bd410d6
J
127 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
128 }
129
7e460124 130}