Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f TO |
4 | | Copyright CiviCRM LLC. All rights reserved. | |
5 | | | | |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
6a488035 | 11 | |
6a488035 TO |
12 | /** |
13 | * Test class for System API - civicrm_system_* | |
14 | * | |
42bf9336 | 15 | * @package CiviCRM |
acb109b7 | 16 | * @group headless |
6a488035 TO |
17 | */ |
18 | class api_v3_SystemTest extends CiviUnitTestCase { | |
19 | ||
20 | const TEST_CACHE_GROUP = 'SystemTest'; | |
21 | const TEST_CACHE_PATH = 'api/v3/system'; | |
b7c9bc4c | 22 | |
6a488035 TO |
23 | /** |
24 | * Sets up the fixture, for example, opens a network connection. | |
fe482240 | 25 | * |
6a488035 | 26 | * This method is called before a test is executed. |
6a488035 | 27 | */ |
5d345864 | 28 | protected function setUp(): void { |
6a488035 | 29 | parent::setUp(); |
131cdce7 | 30 | $this->useTransaction(TRUE); |
61ef23bd | 31 | } |
6a488035 | 32 | |
6a488035 | 33 | /** |
eceb18cc | 34 | * Test system flush. |
6a488035 TO |
35 | */ |
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 | |
39 | // something | |
b6708aeb | 40 | |
fd5f6b03 | 41 | $this->assertTrue(NULL === Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH))); |
b6708aeb | 42 | |
6a488035 | 43 | $data = 'abc'; |
fd5f6b03 | 44 | Civi::cache()->set(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH), $data); |
b6708aeb | 45 | |
fd5f6b03 | 46 | $this->assertEquals('abc', Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH))); |
6a488035 | 47 | |
9099cab3 | 48 | $params = []; |
a828d7b8 | 49 | $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush'); |
b6708aeb | 50 | |
fd5f6b03 | 51 | $this->assertTrue(NULL === Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH))); |
6a488035 | 52 | } |
e2bef985 | 53 | |
54 | /** | |
eceb18cc | 55 | * Test system log function. |
e2bef985 | 56 | */ |
00be9182 | 57 | public function testSystemLog() { |
9099cab3 CW |
58 | $this->callAPISuccess('system', 'log', ['level' => 'info', 'message' => 'We wish you a merry Christmas']); |
59 | $result = $this->callAPISuccess('SystemLog', 'getsingle', [ | |
92915c55 | 60 | 'sequential' => 1, |
9099cab3 CW |
61 | 'message' => ['LIKE' => '%Chris%'], |
62 | ]); | |
e2bef985 | 63 | $this->assertEquals($result['message'], 'We wish you a merry Christmas'); |
64 | $this->assertEquals($result['level'], 'info'); | |
65 | } | |
61ef23bd EM |
66 | |
67 | /** | |
eceb18cc | 68 | * Test system log function. |
61ef23bd | 69 | */ |
00be9182 | 70 | public function testSystemLogNoLevel() { |
9099cab3 CW |
71 | $this->callAPISuccess('system', 'log', ['message' => 'We wish you a merry Christmas', 'level' => 'alert']); |
72 | $result = $this->callAPISuccess('SystemLog', 'getsingle', [ | |
42bf9336 | 73 | 'sequential' => 1, |
9099cab3 CW |
74 | 'message' => ['LIKE' => '%Chris%'], |
75 | ]); | |
61ef23bd | 76 | $this->assertEquals($result['message'], 'We wish you a merry Christmas'); |
4a41780f | 77 | $this->assertEquals($result['level'], 'alert'); |
61ef23bd | 78 | } |
42bf9336 | 79 | |
00be9182 | 80 | public function testSystemGet() { |
9099cab3 | 81 | $result = $this->callAPISuccess('system', 'get', []); |
91f1889e TO |
82 | $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']); |
83 | $this->assertEquals('UnitTests', $result['values'][0]['uf']); | |
84 | } | |
96025800 | 85 | |
a0a5d4da | 86 | /** |
87 | * @throws \CRM_Core_Exception | |
88 | */ | |
89 | public function testSystemUTFMB8Conversion() { | |
433a9508 SL |
90 | if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), '5.7', '>=')) { |
91 | $this->callAPISuccess('System', 'utf8conversion', []); | |
92 | $table = CRM_Core_DAO::executeQuery('SHOW CREATE TABLE civicrm_contact'); | |
93 | $table->fetch(); | |
94 | $this->assertStringEndsWith('DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC', $table->Create_Table); | |
a0a5d4da | 95 | |
433a9508 SL |
96 | $this->callAPISuccess('System', 'utf8conversion', ['is_revert' => 1]); |
97 | $table = CRM_Core_DAO::executeQuery('SHOW CREATE TABLE civicrm_contact'); | |
98 | $table->fetch(); | |
99 | $this->assertStringEndsWith('DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC', $table->Create_Table); | |
100 | } | |
101 | else { | |
102 | $this->markTestSkipped('MySQL Version does not support ut8mb4 testing'); | |
103 | } | |
a0a5d4da | 104 | } |
105 | ||
6a488035 | 106 | } |