MediaWiki REL1_31
LogFormatterTestCase.php
Go to the documentation of this file.
1<?php
2
7
8 public function doTestLogFormatter( $row, $extra ) {
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' => isset( $data['timestamp'] ) ? $data['timestamp'] : wfTimestampNow(),
37 'log_user' => isset( $data['user'] ) ? $data['user'] : 0,
38 'log_user_text' => isset( $data['user_text'] ) ? $data['user_text'] : 'User',
39 'log_actor' => isset( $data['actor'] ) ? $data['actor'] : 0,
40 'log_namespace' => isset( $data['namespace'] ) ? $data['namespace'] : NS_MAIN,
41 'log_title' => isset( $data['title'] ) ? $data['title'] : 'Main_Page',
42 'log_page' => isset( $data['page'] ) ? $data['page'] : 0,
43 'log_comment_text' => isset( $data['comment'] ) ? $data['comment'] : '',
44 'log_comment_data' => null,
45 'log_params' => $legacy
46 ? LogPage::makeParamBlob( $data['params'] )
47 : LogEntryBase::makeParamBlob( $data['params'] ),
48 'log_deleted' => isset( $data['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}
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogEntry.php:142
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:408
Base class that store and restore the Language objects.
static resetMain()
Resets singleton returned by getMain().
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:2013
const NS_MAIN
Definition Defines.php:74