Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
b6708aeb | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; |
29 | ||
30 | /** | |
31 | * Test class for System API - civicrm_system_* | |
32 | * | |
42bf9336 | 33 | * @package CiviCRM |
6a488035 TO |
34 | */ |
35 | class api_v3_SystemTest extends CiviUnitTestCase { | |
36 | ||
37 | const TEST_CACHE_GROUP = 'SystemTest'; | |
38 | const TEST_CACHE_PATH = 'api/v3/system'; | |
b7c9bc4c | 39 | |
6a488035 TO |
40 | /** |
41 | * Sets up the fixture, for example, opens a network connection. | |
fe482240 | 42 | * |
6a488035 | 43 | * This method is called before a test is executed. |
6a488035 TO |
44 | */ |
45 | protected function setUp() { | |
46 | parent::setUp(); | |
131cdce7 | 47 | $this->useTransaction(TRUE); |
61ef23bd | 48 | } |
6a488035 | 49 | |
6a488035 | 50 | /** |
eceb18cc | 51 | * Test system flush. |
6a488035 TO |
52 | */ |
53 | public function testFlush() { | |
54 | // Note: this operation actually flushes several different caches; we don't | |
55 | // check all of them -- just enough to make sure that the API is doing | |
56 | // something | |
b6708aeb | 57 | |
6a488035 | 58 | $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); |
b6708aeb | 59 | |
6a488035 TO |
60 | $data = 'abc'; |
61 | CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH); | |
b6708aeb | 62 | |
6a488035 TO |
63 | $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); |
64 | ||
7fbb4198 | 65 | $params = array(); |
a828d7b8 | 66 | $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush'); |
b6708aeb | 67 | |
6a488035 TO |
68 | $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); |
69 | } | |
e2bef985 | 70 | |
71 | /** | |
eceb18cc | 72 | * Test system log function. |
e2bef985 | 73 | */ |
00be9182 | 74 | public function testSystemLog() { |
e2bef985 | 75 | $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas')); |
42bf9336 | 76 | $result = $this->callAPISuccess('SystemLog', 'getsingle', array( |
92915c55 TO |
77 | 'sequential' => 1, |
78 | 'message' => array('LIKE' => '%Chris%'), | |
79 | )); | |
e2bef985 | 80 | $this->assertEquals($result['message'], 'We wish you a merry Christmas'); |
81 | $this->assertEquals($result['level'], 'info'); | |
82 | } | |
61ef23bd EM |
83 | |
84 | /** | |
eceb18cc | 85 | * Test system log function. |
61ef23bd | 86 | */ |
00be9182 | 87 | public function testSystemLogNoLevel() { |
42bf9336 | 88 | $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert')); |
89 | $result = $this->callAPISuccess('SystemLog', 'getsingle', array( | |
90 | 'sequential' => 1, | |
21dfd5f5 | 91 | 'message' => array('LIKE' => '%Chris%'), |
42bf9336 | 92 | )); |
61ef23bd | 93 | $this->assertEquals($result['message'], 'We wish you a merry Christmas'); |
4a41780f | 94 | $this->assertEquals($result['level'], 'alert'); |
61ef23bd | 95 | } |
42bf9336 | 96 | |
00be9182 | 97 | public function testSystemGet() { |
91f1889e TO |
98 | $result = $this->callAPISuccess('system', 'get', array()); |
99 | $this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']); | |
100 | $this->assertEquals('UnitTests', $result['values'][0]['uf']); | |
101 | } | |
96025800 | 102 | |
6a488035 | 103 | } |