Merge "resources: Provide jquery.i18n (v1.0.3)"
[lhc/web/wiklou.git] / tests / phpunit / includes / debug / logger / LegacyLoggerTest.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Logger;
22
23 use MediaWikiTestCase;
24 use Psr\Log\LogLevel;
25
26 class LegacyLoggerTest extends MediaWikiTestCase {
27
28 /**
29 * @covers LegacyLogger::interpolate
30 * @dataProvider provideInterpolate
31 */
32 public function testInterpolate( $message, $context, $expect ) {
33 $this->assertEquals(
34 $expect, LegacyLogger::interpolate( $message, $context ) );
35 }
36
37 public function provideInterpolate() {
38 $e = new \Exception( 'boom!' );
39 $d = new \DateTime();
40 return array(
41 array(
42 'no-op',
43 array(),
44 'no-op',
45 ),
46 array(
47 'Hello {world}!',
48 array(
49 'world' => 'World',
50 ),
51 'Hello World!',
52 ),
53 array(
54 '{greeting} {user}',
55 array(
56 'greeting' => 'Goodnight',
57 'user' => 'Moon',
58 ),
59 'Goodnight Moon',
60 ),
61 array(
62 'Oops {key_not_set}',
63 array(),
64 'Oops {key_not_set}',
65 ),
66 array(
67 '{ not interpolated }',
68 array(
69 'not interpolated' => 'This should NOT show up in the message',
70 ),
71 '{ not interpolated }',
72 ),
73 array(
74 '{null}',
75 array(
76 'null' => null,
77 ),
78 '[Null]',
79 ),
80 array(
81 '{bool}',
82 array(
83 'bool' => true,
84 ),
85 'true',
86 ),
87 array(
88 '{array}',
89 array(
90 'array' => array( 1, 2, 3 ),
91 ),
92 '[Array(3)]',
93 ),
94 array(
95 '{exception}',
96 array(
97 'exception' => $e,
98 ),
99 '[Exception ' . get_class( $e ) . '( ' .
100 $e->getFile() . ':' . $e->getLine() . ') ' .
101 $e->getMessage() . ']',
102 ),
103 array(
104 '{datetime}',
105 array(
106 'datetime' => $d,
107 ),
108 $d->format( 'c' ),
109 ),
110 array(
111 '{object}',
112 array(
113 'object' => new \stdClass,
114 ),
115 '[Object stdClass]',
116 ),
117 );
118 }
119
120 /**
121 * @covers LegacyLogger::shouldEmit
122 * @dataProvider provideShouldEmit
123 */
124 public function testShouldEmit( $level, $config, $expected ) {
125 $this->setMwGlobals( 'wgDebugLogGroups', array( 'fakechannel' => $config ) );
126 $this->assertEquals(
127 $expected,
128 LegacyLogger::shouldEmit( 'fakechannel', 'some message', $level, array() )
129 );
130 }
131
132 public static function provideShouldEmit() {
133 $dest = array( 'destination' => 'foobar' );
134 $tests = array(
135 array(
136 LogLevel::DEBUG,
137 $dest,
138 true
139 ),
140 array(
141 LogLevel::WARNING,
142 $dest + array( 'level' => LogLevel::INFO ),
143 true,
144 ),
145 array(
146 LogLevel::INFO,
147 $dest + array( 'level' => LogLevel::CRITICAL ),
148 false,
149 ),
150 );
151
152 if ( class_exists( '\Monolog\Logger' ) ) {
153 $tests[] = array(
154 \Monolog\Logger::INFO,
155 $dest + array( 'level' => LogLevel::INFO ),
156 true,
157 );
158 $tests[] = array(
159 \Monolog\Logger::WARNING,
160 $dest + array( 'level' => LogLevel::EMERGENCY ),
161 false,
162 );
163 }
164
165 return $tests;
166 }
167
168 }