3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
13 * Test class for System API - civicrm_system_*
18 class api_v3_SystemTest
extends CiviUnitTestCase
{
20 const TEST_CACHE_GROUP
= 'SystemTest';
21 const TEST_CACHE_PATH
= 'api/v3/system';
24 * Sets up the fixture, for example, opens a network connection.
26 * This method is called before a test is executed.
28 protected function setUp() {
30 $this->useTransaction(TRUE);
36 public function testFlush() {
37 // Note: this operation actually flushes several different caches; we don't
38 // check all of them -- just enough to make sure that the API is doing
41 $this->assertTrue(NULL === Civi
::cache()->get(CRM_Utils_Cache
::cleanKey(self
::TEST_CACHE_PATH
)));
44 Civi
::cache()->set(CRM_Utils_Cache
::cleanKey(self
::TEST_CACHE_PATH
), $data);
46 $this->assertEquals('abc', Civi
::cache()->get(CRM_Utils_Cache
::cleanKey(self
::TEST_CACHE_PATH
)));
49 $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__
, __FILE__
, "Flush all system caches", 'Flush');
51 $this->assertTrue(NULL === Civi
::cache()->get(CRM_Utils_Cache
::cleanKey(self
::TEST_CACHE_PATH
)));
55 * Test system log function.
57 public function testSystemLog() {
58 $this->callAPISuccess('system', 'log', ['level' => 'info', 'message' => 'We wish you a merry Christmas']);
59 $result = $this->callAPISuccess('SystemLog', 'getsingle', [
61 'message' => ['LIKE' => '%Chris%'],
63 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
64 $this->assertEquals($result['level'], 'info');
68 * Test system log function.
70 public function testSystemLogNoLevel() {
71 $this->callAPISuccess('system', 'log', ['message' => 'We wish you a merry Christmas', 'level' => 'alert']);
72 $result = $this->callAPISuccess('SystemLog', 'getsingle', [
74 'message' => ['LIKE' => '%Chris%'],
76 $this->assertEquals($result['message'], 'We wish you a merry Christmas');
77 $this->assertEquals($result['level'], 'alert');
80 public function testSystemGet() {
81 $result = $this->callAPISuccess('system', 'get', []);
82 $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']);
83 $this->assertEquals('UnitTests', $result['values'][0]['uf']);
87 * @throws \CRM_Core_Exception
89 public function testSystemUTFMB8Conversion() {
90 $this->callAPISuccess('System', 'utf8conversion', []);
91 $table = CRM_Core_DAO
::executeQuery('SHOW CREATE TABLE civicrm_contact');
93 $this->assertStringEndsWith('DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC', $table->Create_Table
);
95 $this->callAPISuccess('System', 'utf8conversion', ['is_revert' => 1]);
96 $table = CRM_Core_DAO
::executeQuery('SHOW CREATE TABLE civicrm_contact');
98 $this->assertStringEndsWith('DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC', $table->Create_Table
);