3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Test class for System API - civicrm_system_*
35 class api_v3_SystemTest
extends CiviUnitTestCase
{
37 const TEST_CACHE_GROUP
= 'SystemTest';
38 const TEST_CACHE_PATH
= 'api/v3/system';
43 * Initialize configuration
45 function __construct() {
46 parent
::__construct();
50 * Sets up the fixture, for example, opens a network connection.
51 * This method is called before a test is executed.
55 protected function setUp() {
60 * Tears down the fixture, for example, closes a network connection.
61 * This method is called after a test is executed.
65 protected function tearDown() {
66 $this->quickCleanup(array('civicrm_system_log'));
69 ///////////////// civicrm_domain_get methods
74 public function testFlush() {
75 // Note: this operation actually flushes several different caches; we don't
76 // check all of them -- just enough to make sure that the API is doing
79 $this->assertTrue(NULL === CRM_Core_BAO_Cache
::getItem(self
::TEST_CACHE_GROUP
, self
::TEST_CACHE_PATH
));
82 CRM_Core_BAO_Cache
::setItem($data, self
::TEST_CACHE_GROUP
, self
::TEST_CACHE_PATH
);
84 $this->assertEquals('abc', CRM_Core_BAO_Cache
::getItem(self
::TEST_CACHE_GROUP
, self
::TEST_CACHE_PATH
));
87 $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__
, __FILE__
, "Flush all system caches", 'Flush', 'flush');
89 $this->assertTrue(NULL === CRM_Core_BAO_Cache
::getItem(self
::TEST_CACHE_GROUP
, self
::TEST_CACHE_PATH
));
93 * Test system log function
95 function testSystemLog() {
96 $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas'));
97 $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
99 'message' => array('LIKE' => '%Chris%')
101 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
102 $this->assertEquals($result['level'], 'info');
106 * Test system log function
108 function testSystemLogNoLevel() {
109 $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert'));
110 $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
112 'message' => array('LIKE' => '%Chris%')
114 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
115 $this->assertEquals($result['level'], 'alert');
118 function testSystemGet() {
119 $result = $this->callAPISuccess('system', 'get', array());
120 $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']);
121 $this->assertEquals('UnitTests', $result['values'][0]['uf']);