Merge pull request #17706 from demeritcowboy/mysql-ssl-alt
[civicrm-core.git] / tests / phpunit / api / v3 / StatusPreferenceTest.php
CommitLineData
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 */
18class api_v3_StatusPreferenceTest extends CiviUnitTestCase {
19 protected $_apiversion;
20 protected $_contactID;
21 protected $_locationType;
22 protected $_params;
23
7e460124
J
24 public function setUp() {
25 $this->_apiversion = 3;
26 parent::setUp();
27 $this->useTransaction(TRUE);
9099cab3 28 $this->_params = [
7e460124 29 'name' => 'test_check',
09f73c5c 30 'domain_id' => 1,
7e460124 31 'hush_until' => '20151212',
a24a0be0 32 'ignore_severity' => 4,
7e460124 33 'check_info' => NULL,
9099cab3 34 ];
7e460124
J
35 }
36
37 public function testCreateStatusPreference() {
38 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
39 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
09f73c5c
J
40 $id = $result['id'];
41 $this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
a24a0be0 42 $this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
7e460124 43
9099cab3 44 $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
7e460124
J
45 }
46
47 public function testDeleteStatusPreference() {
09f73c5c 48 // create one
7e460124
J
49 $create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
50
9099cab3 51 $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
7e460124
J
52 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
53
9099cab3 54 $get = $this->callAPISuccess('StatusPreference', 'get', [
7e460124 55 'id' => $create['id'],
9099cab3 56 ]);
7e460124
J
57 $this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
58 }
59
09f73c5c
J
60 /**
61 * Test a get with empty params.
62 */
63 public function testStatusPreferenceGetEmptyParams() {
9099cab3 64 $result = $this->callAPISuccess('StatusPreference', 'Get', []);
09f73c5c
J
65 }
66
67 /**
68 * Test a StatusPreference get.
69 */
70 public function testStatusPreferenceGet() {
71 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
72 $id = $statusPreference['id'];
9099cab3 73 $params = [
09f73c5c 74 'id' => $id,
9099cab3 75 ];
09f73c5c
J
76 $result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__);
77 $this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__);
78 $this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__);
79 $this->assertEquals('2015-12-12', $result['values'][$id]['hush_until'], 'In line ' . __LINE__);
a24a0be0 80 $this->assertEquals($statusPreference['values'][$id]['ignore_severity'], $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
09f73c5c
J
81 }
82
748d9d7f 83 /**
a24a0be0 84 * Ensure you can't create a StatusPref with ignore_severity > 7.
748d9d7f
J
85 */
86 public function testCreateInvalidMinimumReportSeverity() {
a24a0be0 87 $this->_params['ignore_severity'] = 45;
748d9d7f
J
88 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
89 }
90
2bd410d6
J
91 /**
92 * Test creating a severity by name, not integer.
93 */
94 public function testCreateSeverityByName() {
95 // Any permutation of uppercase/lowercase should work.
a24a0be0 96 $this->_params['ignore_severity'] = 'cRItical';
2bd410d6
J
97 $result = $this->callAPIAndDocument('StatusPreference', 'create', $this->_params, __FUNCTION__, __FILE__);
98 $id = $result['id'];
a24a0be0 99 $this->assertEquals(5, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
2bd410d6
J
100 }
101
102 /**
103 * Test creating an invalid severity by name.
104 */
105 public function testCreateSeverityWithInvalidName() {
a24a0be0 106 $this->_params['ignore_severity'] = 'wdsadasdarning';
2bd410d6
J
107 $result = $this->callAPIFailure('StatusPreference', 'create', $this->_params);
108 }
109
7e460124 110}