6 abstract class LogFormatterTestCase
extends MediaWikiLangTestCase
{
8 public function doTestLogFormatter( $row, $extra ) {
9 RequestContext
::resetMain();
10 $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
12 $formatter = LogFormatter
::newFromRow( $row );
16 self
::removeSomeHtml( $formatter->getActionText() ),
17 'Action text is equal to expected text'
20 $this->assertSame( // ensure types and array key order
22 self
::removeApiMetaData( $formatter->formatParametersForApi() ),
23 'Api log params is equal to expected array'
27 protected function isLegacy( $extra ) {
28 return isset( $extra['legacy'] ) && $extra['legacy'];
31 protected function expandDatabaseRow( $data, $legacy ) {
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'] )
47 : LogEntryBase
::makeParamBlob( $data['params'] ),
48 'log_deleted' => $data['deleted'] ??
0,
52 private static function removeSomeHtml( $html ) {
53 $html = str_replace( '"', '"', $html );
54 $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
55 return trim( strip_tags( $html ) );
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 );