Merge branch 'JohnFF-patch-1'
[civicrm-core.git] / tests / phpunit / api / v3 / SystemTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2
3/*
4 +--------------------------------------------------------------------+
06a1bc01 5| CiviCRM version 4.5 |
b6708aeb 6+--------------------------------------------------------------------+
06a1bc01 7| Copyright CiviCRM LLC (c) 2004-2014 |
b6708aeb 8+--------------------------------------------------------------------+
9| This file is a part of CiviCRM. |
10| |
11| CiviCRM is free software; you can copy, modify, and distribute it |
12| under the terms of the GNU Affero General Public License |
13| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14| |
15| CiviCRM is distributed in the hope that it will be useful, but |
16| WITHOUT ANY WARRANTY; without even the implied warranty of |
17| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18| See the GNU Affero General Public License for more details. |
19| |
20| You should have received a copy of the GNU Affero General Public |
21| License and the CiviCRM Licensing Exception along |
22| with this program; if not, contact CiviCRM LLC |
23| at info[AT]civicrm[DOT]org. If you have questions about the |
24| GNU Affero General Public License or the licensing of CiviCRM, |
25| see the CiviCRM license FAQ at http://civicrm.org/licensing |
26+--------------------------------------------------------------------+
27*/
6a488035
TO
28
29/*
30 +--------------------------------------------------------------------+
06a1bc01 31 | CiviCRM version 4.5 |
6a488035 32 +--------------------------------------------------------------------+
06a1bc01 33 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
34 +--------------------------------------------------------------------+
35 | This file is a part of CiviCRM. |
36 | |
37 | CiviCRM is free software; you can copy, modify, and distribute it |
38 | under the terms of the GNU Affero General Public License |
39 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
40 | |
41 | CiviCRM is distributed in the hope that it will be useful, but |
42 | WITHOUT ANY WARRANTY; without even the implied warranty of |
43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
44 | See the GNU Affero General Public License for more details. |
45 | |
46 | You should have received a copy of the GNU Affero General Public |
47 | License and the CiviCRM Licensing Exception along |
48 | with this program; if not, contact CiviCRM LLC |
49 | at info[AT]civicrm[DOT]org. If you have questions about the |
50 | GNU Affero General Public License or the licensing of CiviCRM, |
51 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
52 +--------------------------------------------------------------------+
53*/
54
55require_once 'CiviTest/CiviUnitTestCase.php';
56
57/**
58 * Test class for System API - civicrm_system_*
59 *
60 * @package CiviCRM
61 */
62class api_v3_SystemTest extends CiviUnitTestCase {
63
64 const TEST_CACHE_GROUP = 'SystemTest';
65 const TEST_CACHE_PATH = 'api/v3/system';
b7c9bc4c 66
6a488035
TO
67 /**
68 * Constructor
69 *
70 * Initialize configuration
71 */ function __construct() {
72 parent::__construct();
73 }
74
75 /**
76 * Sets up the fixture, for example, opens a network connection.
77 * This method is called before a test is executed.
78 *
79 * @access protected
80 */
81 protected function setUp() {
82 parent::setUp();
83 }
84
85 /**
86 * Tears down the fixture, for example, closes a network connection.
87 * This method is called after a test is executed.
88 *
89 * @access protected
90 */
61ef23bd
EM
91 protected function tearDown() {
92 $this->quickCleanup(array('civicrm_system_log'));
93 }
6a488035
TO
94
95 ///////////////// civicrm_domain_get methods
96
97 /**
98 * Test system flush
99 */
100 public function testFlush() {
101 // Note: this operation actually flushes several different caches; we don't
102 // check all of them -- just enough to make sure that the API is doing
103 // something
b6708aeb 104
6a488035 105 $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
b6708aeb 106
6a488035
TO
107 $data = 'abc';
108 CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH);
b6708aeb 109
6a488035
TO
110 $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
111
7fbb4198 112 $params = array();
113 $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush', 'flush');
b6708aeb 114
6a488035
TO
115 $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
116 }
e2bef985 117
118 /**
119 * Test system log function
120 */
121 function testSystemLog() {
122 $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas'));
123 $result = $this->callAPISuccess('SystemLog', 'getsingle', array('sequential' => 1, 'message' => array('LIKE' => '%Chris%')));
124 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
125 $this->assertEquals($result['level'], 'info');
126 }
61ef23bd
EM
127
128 /**
129 * Test system log function
130 */
131 function testSystemLogNoLevel() {
4a41780f 132 $this->callAPISuccess('system', 'log', array( 'message' => 'We wish you a merry Christmas', 'level' => 'alert'));
61ef23bd
EM
133 $result = $this->callAPISuccess('SystemLog', 'getsingle', array('sequential' => 1, 'message' => array('LIKE' => '%Chris%')));
134 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
4a41780f 135 $this->assertEquals($result['level'], 'alert');
61ef23bd 136 }
6a488035 137}