wiki.techinc.nl/tests/phpunit/includes/logging/LogFormatterTestCase.php
umherirrender d6961552b3 Migrate protect log to new log system
This localize the protect type, level and expiry on Special:Log/protect.
To allow i18n there are some details stored in the log params of new log
items, these details also shown on API output.
The details cannot get from the old existing data, because there are
containing L10n strings therefore i18n works only for new items.
In the api and for IRC the old description text is still stored in the
log params for backward compatibility.

This allows use of gender on Special:Log. Old messages are kept for use
in IRC. Tests already exists to ensure an unchanged IRC message.

Bug: T47988
Change-Id: I3bb85c61b857972e66c99c499d7d785c88cafb25
2015-09-25 17:07:50 +02:00

66 lines
2.1 KiB
PHP

<?php
/**
* @since 1.26
*/
abstract class LogFormatterTestCase extends MediaWikiLangTestCase {
public function doTestLogFormatter( $row, $extra ) {
RequestContext::resetMain();
$row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
$formatter = LogFormatter::newFromRow( $row );
$this->assertEquals(
$extra['text'],
self::removeSomeHtml( $formatter->getActionText() ),
'Action text is equal to expected text'
);
$this->assertSame( // ensure types and array key order
$extra['api'],
self::removeApiMetaData( $formatter->formatParametersForApi() ),
'Api log params is equal to expected array'
);
}
protected function isLegacy( $extra ) {
return isset( $extra['legacy'] ) && $extra['legacy'];
}
protected function expandDatabaseRow( $data, $legacy ) {
return array(
// no log_id because no insert in database
'log_type' => $data['type'],
'log_action' => $data['action'],
'log_timestamp' => isset( $data['timestamp'] ) ? $data['timestamp'] : wfTimestampNow(),
'log_user' => isset( $data['user'] ) ? $data['user'] : 0,
'log_user_text' => isset( $data['user_text'] ) ? $data['user_text'] : 'User',
'log_namespace' => isset( $data['namespace'] ) ? $data['namespace'] : NS_MAIN,
'log_title' => isset( $data['title'] ) ? $data['title'] : 'Main_Page',
'log_page' => isset( $data['page'] ) ? $data['page'] : 0,
'log_comment' => isset( $data['comment'] ) ? $data['comment'] : '',
'log_params' => $legacy
? LogPage::makeParamBlob( $data['params'] )
: LogEntryBase::makeParamBlob( $data['params'] ),
'log_deleted' => isset( $data['deleted'] ) ? $data['deleted'] : 0,
);
}
private static function removeSomeHtml( $html ) {
$html = str_replace( '&quot;', '"', $html );
$html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
return trim( preg_replace( '/<(a|span)[^>]*>([^<]*)<\/\1>/', '$2', $html ) );
}
private static function removeApiMetaData( $val ) {
if ( is_array( $val ) ) {
unset( $val['_element'] );
unset( $val['_type'] );
foreach ( $val as $key => $value ) {
$val[$key] = self::removeApiMetaData( $value );
}
}
return $val;
}
}