Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
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 | * Constructor | |
42 | * | |
43 | * Initialize configuration | |
42bf9336 | 44 | */ |
45 | function __construct() { | |
6a488035 TO |
46 | parent::__construct(); |
47 | } | |
48 | ||
49 | /** | |
50 | * Sets up the fixture, for example, opens a network connection. | |
51 | * This method is called before a test is executed. | |
52 | * | |
53 | * @access protected | |
54 | */ | |
55 | protected function setUp() { | |
56 | parent::setUp(); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Tears down the fixture, for example, closes a network connection. | |
61 | * This method is called after a test is executed. | |
62 | * | |
63 | * @access protected | |
64 | */ | |
61ef23bd EM |
65 | protected function tearDown() { |
66 | $this->quickCleanup(array('civicrm_system_log')); | |
67 | } | |
6a488035 TO |
68 | |
69 | ///////////////// civicrm_domain_get methods | |
70 | ||
71 | /** | |
72 | * Test system flush | |
73 | */ | |
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 | |
77 | // something | |
b6708aeb | 78 | |
6a488035 | 79 | $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); |
b6708aeb | 80 | |
6a488035 TO |
81 | $data = 'abc'; |
82 | CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH); | |
b6708aeb | 83 | |
6a488035 TO |
84 | $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); |
85 | ||
7fbb4198 | 86 | $params = array(); |
87 | $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush', 'flush'); | |
b6708aeb | 88 | |
6a488035 TO |
89 | $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); |
90 | } | |
e2bef985 | 91 | |
92 | /** | |
93 | * Test system log function | |
94 | */ | |
95 | function testSystemLog() { | |
96 | $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas')); | |
42bf9336 | 97 | $result = $this->callAPISuccess('SystemLog', 'getsingle', array( |
98 | 'sequential' => 1, | |
99 | 'message' => array('LIKE' => '%Chris%') | |
100 | )); | |
e2bef985 | 101 | $this->assertEquals($result['message'], 'We wish you a merry Christmas'); |
102 | $this->assertEquals($result['level'], 'info'); | |
103 | } | |
61ef23bd EM |
104 | |
105 | /** | |
106 | * Test system log function | |
107 | */ | |
108 | function testSystemLogNoLevel() { | |
42bf9336 | 109 | $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert')); |
110 | $result = $this->callAPISuccess('SystemLog', 'getsingle', array( | |
111 | 'sequential' => 1, | |
112 | 'message' => array('LIKE' => '%Chris%') | |
113 | )); | |
61ef23bd | 114 | $this->assertEquals($result['message'], 'We wish you a merry Christmas'); |
4a41780f | 115 | $this->assertEquals($result['level'], 'alert'); |
61ef23bd | 116 | } |
42bf9336 | 117 | |
91f1889e TO |
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']); | |
122 | } | |
6a488035 | 123 | } |