Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / changes / TestRecentChangesHelper.php
blob2f908feb63bec8d9851961a3ccb0ff857285761e
1 <?php
3 use MediaWiki\MediaWikiServices;
5 /**
6 * Helper for generating test recent changes entries.
8 * @author Katie Filbert < aude.wiki@gmail.com >
9 */
10 class TestRecentChangesHelper {
12 public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
13 $timestamp, $counter, $watchingUsers
14 ) {
16 $attribs = array_merge(
17 $this->getDefaultAttributes( $titleText, $timestamp ),
19 'rc_user' => $user->getId(),
20 'rc_user_text' => $user->getName(),
21 'rc_this_oldid' => $thisid,
22 'rc_last_oldid' => $lastid,
23 'rc_cur_id' => $curid
27 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
30 public function makeLogRecentChange(
31 $logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers
32 ) {
33 $attribs = array_merge(
34 $this->getDefaultAttributes( $titleText, $timestamp ),
36 'rc_cur_id' => 0,
37 'rc_user' => $user->getId(),
38 'rc_user_text' => $user->getName(),
39 'rc_this_oldid' => 0,
40 'rc_last_oldid' => 0,
41 'rc_old_len' => null,
42 'rc_new_len' => null,
43 'rc_type' => 3,
44 'rc_logid' => 25,
45 'rc_log_type' => $logType,
46 'rc_log_action' => $logAction,
47 'rc_source' => 'mw.log'
51 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
54 public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid,
55 $thisid, $lastid, $counter, $watchingUsers
56 ) {
57 $attribs = array_merge(
58 $this->getDefaultAttributes( $titleText, $timestamp ),
60 'rc_user' => $user->getId(),
61 'rc_user_text' => $user->getName(),
62 'rc_deleted' => 5,
63 'rc_cur_id' => $curid,
64 'rc_this_oldid' => $thisid,
65 'rc_last_oldid' => $lastid
69 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
72 public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
73 $timestamp, $counter, $watchingUsers
74 ) {
76 $attribs = array_merge(
77 $this->getDefaultAttributes( $titleText, $timestamp ),
79 'rc_user' => $user->getId(),
80 'rc_user_text' => $user->getName(),
81 'rc_this_oldid' => $thisid,
82 'rc_last_oldid' => $lastid,
83 'rc_cur_id' => $curid,
84 'rc_type' => 1,
85 'rc_bot' => 1,
86 'rc_source' => 'mw.new'
90 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
93 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
94 $change = new RecentChange();
95 $change->setAttribs( $attribs );
96 $change->counter = $counter;
97 $change->numberofWatchingusers = $watchingUsers;
99 return $change;
102 public function getCacheEntry( $recentChange ) {
103 $rcCacheFactory = new RCCacheEntryFactory(
104 new RequestContext(),
105 [ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
106 MediaWikiServices::getInstance()->getLinkRenderer()
108 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
111 public function makeCategorizationRecentChange(
112 User $user, $titleText, $curid, $thisid, $lastid, $timestamp
115 $attribs = array_merge(
116 $this->getDefaultAttributes( $titleText, $timestamp ),
118 'rc_type' => RC_CATEGORIZE,
119 'rc_user' => $user->getId(),
120 'rc_user_text' => $user->getName(),
121 'rc_this_oldid' => $thisid,
122 'rc_last_oldid' => $lastid,
123 'rc_cur_id' => $curid,
124 'rc_comment' => '[[:Testpage]] added to category',
125 'rc_old_len' => 0,
126 'rc_new_len' => 0,
130 return $this->makeRecentChange( $attribs, 0, 0 );
133 private function getDefaultAttributes( $titleText, $timestamp ) {
134 return [
135 'rc_id' => 545,
136 'rc_user' => 0,
137 'rc_user_text' => '127.0.0.1',
138 'rc_ip' => '127.0.0.1',
139 'rc_title' => $titleText,
140 'rc_namespace' => 0,
141 'rc_timestamp' => $timestamp,
142 'rc_old_len' => 212,
143 'rc_new_len' => 188,
144 'rc_comment' => '',
145 'rc_minor' => 0,
146 'rc_bot' => 0,
147 'rc_type' => 0,
148 'rc_patrolled' => 1,
149 'rc_deleted' => 0,
150 'rc_logid' => 0,
151 'rc_log_type' => null,
152 'rc_log_action' => '',
153 'rc_params' => '',
154 'rc_source' => 'mw.edit'
158 public function getTestContext( User $user ) {
159 $context = new RequestContext();
160 $context->setLanguage( 'en' );
162 $context->setUser( $user );
164 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
165 $context->setTitle( $title );
167 return $context;