MediaWiki  1.30.2
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_namespace' => isset( $data['namespace'] ) ? $data['namespace'] : NS_MAIN,
40  'log_title' => isset( $data['title'] ) ? $data['title'] : 'Main_Page',
41  'log_page' => isset( $data['page'] ) ? $data['page'] : 0,
42  'log_comment_text' => isset( $data['comment'] ) ? $data['comment'] : '',
43  'log_comment_data' => null,
44  'log_params' => $legacy
45  ? LogPage::makeParamBlob( $data['params'] )
46  : LogEntryBase::makeParamBlob( $data['params'] ),
47  'log_deleted' => isset( $data['deleted'] ) ? $data['deleted'] : 0,
48  ];
49  }
50 
51  private static function removeSomeHtml( $html ) {
52  $html = str_replace( '&quot;', '"', $html );
53  $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
54  return trim( strip_tags( $html ) );
55  }
56 
57  private static function removeApiMetaData( $val ) {
58  if ( is_array( $val ) ) {
59  unset( $val['_element'] );
60  unset( $val['_type'] );
61  foreach ( $val as $key => $value ) {
62  $val[$key] = self::removeApiMetaData( $value );
63  }
64  }
65  return $val;
66  }
67 }
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
NS_MAIN
const NS_MAIN
Definition: Defines.php:65
LogFormatterTestCase
Definition: LogFormatterTestCase.php:6
$html
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:1965
LogFormatter\newFromRow
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Definition: LogFormatter.php:76
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2069
LogFormatterTestCase\isLegacy
isLegacy( $extra)
Definition: LogFormatterTestCase.php:27
RequestContext\resetMain
static resetMain()
Resets singleton returned by getMain().
Definition: RequestContext.php:496
$value
$value
Definition: styleTest.css.php:45
LogPage\makeParamBlob
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogPage.php:409
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
LogFormatterTestCase\doTestLogFormatter
doTestLogFormatter( $row, $extra)
Definition: LogFormatterTestCase.php:8
LogEntryBase\makeParamBlob
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogEntry.php:142
LogFormatterTestCase\removeApiMetaData
static removeApiMetaData( $val)
Definition: LogFormatterTestCase.php:57
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LogFormatterTestCase\expandDatabaseRow
expandDatabaseRow( $data, $legacy)
Definition: LogFormatterTestCase.php:31
LogFormatterTestCase\removeSomeHtml
static removeSomeHtml( $html)
Definition: LogFormatterTestCase.php:51