Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / logging / LogFormatterTestCase.php
blobc289839b49823dfad8f6f27957ae54d2fda3225a
1 <?php
3 /**
4 * @since 1.26
5 */
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 );
14 $this->assertEquals(
15 $extra['text'],
16 self::removeSomeHtml( $formatter->getActionText() ),
17 'Action text is equal to expected text'
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'
27 protected function isLegacy( $extra ) {
28 return isset( $extra['legacy'] ) && $extra['legacy'];
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' => isset( $data['comment'] ) ? $data['comment'] : '',
43 'log_params' => $legacy
44 ? LogPage::makeParamBlob( $data['params'] )
45 : LogEntryBase::makeParamBlob( $data['params'] ),
46 'log_deleted' => isset( $data['deleted'] ) ? $data['deleted'] : 0,
50 private static function removeSomeHtml( $html ) {
51 $html = str_replace( '&quot;', '"', $html );
52 $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
53 return trim( strip_tags( $html ) );
56 private static function removeApiMetaData( $val ) {
57 if ( is_array( $val ) ) {
58 unset( $val['_element'] );
59 unset( $val['_type'] );
60 foreach ( $val as $key => $value ) {
61 $val[$key] = self::removeApiMetaData( $value );
64 return $val;