Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / debug / logger / LegacyLoggerTest.php
blob1b3ce2ca618dbb76c10ee3a7c3a1191e9c655f63
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.
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.
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
18 * @file
21 namespace MediaWiki\Logger;
23 use MediaWikiTestCase;
24 use Psr\Log\LogLevel;
26 class LegacyLoggerTest extends MediaWikiTestCase {
28 /**
29 * @covers LegacyLogger::interpolate
30 * @dataProvider provideInterpolate
32 public function testInterpolate( $message, $context, $expect ) {
33 $this->assertEquals(
34 $expect, LegacyLogger::interpolate( $message, $context ) );
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',
46 array(
47 'Hello {world}!',
48 array(
49 'world' => 'World',
51 'Hello World!',
53 array(
54 '{greeting} {user}',
55 array(
56 'greeting' => 'Goodnight',
57 'user' => 'Moon',
59 'Goodnight Moon',
61 array(
62 'Oops {key_not_set}',
63 array(),
64 'Oops {key_not_set}',
66 array(
67 '{ not interpolated }',
68 array(
69 'not interpolated' => 'This should NOT show up in the message',
71 '{ not interpolated }',
73 array(
74 '{null}',
75 array(
76 'null' => null,
78 '[Null]',
80 array(
81 '{bool}',
82 array(
83 'bool' => true,
85 'true',
87 array(
88 '{float}',
89 array(
90 'float' => 1.23,
92 '1.23',
94 array(
95 '{array}',
96 array(
97 'array' => array( 1, 2, 3 ),
99 '[Array(3)]',
101 array(
102 '{exception}',
103 array(
104 'exception' => $e,
106 '[Exception ' . get_class( $e ) . '( ' .
107 $e->getFile() . ':' . $e->getLine() . ') ' .
108 $e->getMessage() . ']',
110 array(
111 '{datetime}',
112 array(
113 'datetime' => $d,
115 $d->format( 'c' ),
117 array(
118 '{object}',
119 array(
120 'object' => new \stdClass,
122 '[Object stdClass]',
128 * @covers LegacyLogger::shouldEmit
129 * @dataProvider provideShouldEmit
131 public function testShouldEmit( $level, $config, $expected ) {
132 $this->setMwGlobals( 'wgDebugLogGroups', array( 'fakechannel' => $config ) );
133 $this->assertEquals(
134 $expected,
135 LegacyLogger::shouldEmit( 'fakechannel', 'some message', $level, array() )
139 public static function provideShouldEmit() {
140 $dest = array( 'destination' => 'foobar' );
141 $tests = array(
142 array(
143 LogLevel::DEBUG,
144 $dest,
145 true
147 array(
148 LogLevel::WARNING,
149 $dest + array( 'level' => LogLevel::INFO ),
150 true,
152 array(
153 LogLevel::INFO,
154 $dest + array( 'level' => LogLevel::CRITICAL ),
155 false,
159 if ( class_exists( '\Monolog\Logger' ) ) {
160 $tests[] = array(
161 \Monolog\Logger::INFO,
162 $dest + array( 'level' => LogLevel::INFO ),
163 true,
165 $tests[] = array(
166 \Monolog\Logger::WARNING,
167 $dest + array( 'level' => LogLevel::EMERGENCY ),
168 false,
172 return $tests;