ignore system_log in update single test as updating logs doesn't make sense
[civicrm-core.git] / tests / phpunit / api / v3 / SystemTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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 */
28
29 /*
30 +--------------------------------------------------------------------+
31 | CiviCRM version 4.5 |
32 +--------------------------------------------------------------------+
33 | Copyright CiviCRM LLC (c) 2004-2014 |
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
55 require_once 'CiviTest/CiviUnitTestCase.php';
56
57 /**
58 * Test class for System API - civicrm_system_*
59 *
60 * @package CiviCRM
61 */
62 class api_v3_SystemTest extends CiviUnitTestCase {
63
64 const TEST_CACHE_GROUP = 'SystemTest';
65 const TEST_CACHE_PATH = 'api/v3/system';
66
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 */
91 protected function tearDown() {
92 $this->quickCleanup(array('civicrm_system_log'));
93 }
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
104
105 $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
106
107 $data = 'abc';
108 CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH);
109
110 $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
111
112 $params = array();
113 $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush', 'flush');
114
115 $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
116 }
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 }
127
128 /**
129 * Test system log function
130 */
131 function testSystemLogNoLevel() {
132 $this->callAPISuccess('system', 'log', array( 'message' => 'We wish you a merry Christmas'));
133 $result = $this->callAPISuccess('SystemLog', 'getsingle', array('sequential' => 1, 'message' => array('LIKE' => '%Chris%')));
134 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
135 $this->assertEquals($result['level'], 'info');
136 $this->callAPISuccess('system_log', 'create', array('message' => 'msg'));
137 }
138 }