MediaWiki REL1_33
LogFormatterTestCase.php
Go to the documentation of this file.
1<?php
2
7
8 public function doTestLogFormatter( $row, $extra ) {
9 RequestContext::resetMain();
10 $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
11
12 $formatter = LogFormatter::newFromRow( $row );
13
14 $this->assertEquals(
15 $extra['text'],
16 self::removeSomeHtml( $formatter->getActionText() ),
17 'Action text is equal to expected text'
18 );
19
20 $this->assertSame( // ensure types and array key order
21 $extra['api'],
22 self::removeApiMetaData( $formatter->formatParametersForApi() ),
23 'Api log params is equal to expected array'
24 );
25 }
26
27 protected function isLegacy( $extra ) {
28 return isset( $extra['legacy'] ) && $extra['legacy'];
29 }
30
31 protected function expandDatabaseRow( $data, $legacy ) {
32 return [
33 // no log_id because no insert in database
34 'log_type' => $data['type'],
35 'log_action' => $data['action'],
36 'log_timestamp' => $data['timestamp'] ?? wfTimestampNow(),
37 'log_user' => $data['user'] ?? 0,
38 'log_user_text' => $data['user_text'] ?? 'User',
39 'log_actor' => $data['actor'] ?? 0,
40 'log_namespace' => $data['namespace'] ?? NS_MAIN,
41 'log_title' => $data['title'] ?? 'Main_Page',
42 'log_page' => $data['page'] ?? 0,
43 'log_comment_text' => $data['comment'] ?? '',
44 'log_comment_data' => null,
45 'log_params' => $legacy
46 ? LogPage::makeParamBlob( $data['params'] )
48 'log_deleted' => $data['deleted'] ?? 0,
49 ];
50 }
51
52 private static function removeSomeHtml( $html ) {
53 $html = str_replace( '&quot;', '"', $html );
54 $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
55 return trim( strip_tags( $html ) );
56 }
57
58 private static function removeApiMetaData( $val ) {
59 if ( is_array( $val ) ) {
60 unset( $val['_element'] );
61 unset( $val['_type'] );
62 foreach ( $val as $key => $value ) {
63 $val[$key] = self::removeApiMetaData( $value );
64 }
65 }
66 return $val;
67 }
68}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogEntry.php:146
doTestLogFormatter( $row, $extra)
expandDatabaseRow( $data, $legacy)
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogPage.php:413
Base class that store and restore the Language objects.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2011
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
const NS_MAIN
Definition Defines.php:73