Merge pull request #13926 from pradpnayak/NoticeErrorProfile
[civicrm-core.git] / tests / phpunit / api / v3 / SystemTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 /**
29 * Test class for System API - civicrm_system_*
30 *
31 * @package CiviCRM
32 * @group headless
33 */
34 class api_v3_SystemTest extends CiviUnitTestCase {
35
36 const TEST_CACHE_GROUP = 'SystemTest';
37 const TEST_CACHE_PATH = 'api/v3/system';
38
39 /**
40 * Sets up the fixture, for example, opens a network connection.
41 *
42 * This method is called before a test is executed.
43 */
44 protected function setUp() {
45 parent::setUp();
46 $this->useTransaction(TRUE);
47 }
48
49 /**
50 * Test system flush.
51 */
52 public function testFlush() {
53 // Note: this operation actually flushes several different caches; we don't
54 // check all of them -- just enough to make sure that the API is doing
55 // something
56
57 $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
58
59 $data = 'abc';
60 CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH);
61
62 $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
63
64 $params = array();
65 $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush');
66
67 $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
68 }
69
70 /**
71 * Test system log function.
72 */
73 public function testSystemLog() {
74 $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas'));
75 $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
76 'sequential' => 1,
77 'message' => array('LIKE' => '%Chris%'),
78 ));
79 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
80 $this->assertEquals($result['level'], 'info');
81 }
82
83 /**
84 * Test system log function.
85 */
86 public function testSystemLogNoLevel() {
87 $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert'));
88 $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
89 'sequential' => 1,
90 'message' => array('LIKE' => '%Chris%'),
91 ));
92 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
93 $this->assertEquals($result['level'], 'alert');
94 }
95
96 public function testSystemGet() {
97 $result = $this->callAPISuccess('system', 'get', array());
98 $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']);
99 $this->assertEquals('UnitTests', $result['values'][0]['uf']);
100 }
101
102 }