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