Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / TestRecentChangesHelper.php
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4
5 /**
6 * Helper for generating test recent changes entries.
7 *
8 * @author Katie Filbert < aude.wiki@gmail.com >
9 */
10 class TestRecentChangesHelper {
11
12 public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
13 $timestamp, $counter, $watchingUsers
14 ) {
15 $attribs = array_merge(
16 $this->getDefaultAttributes( $titleText, $timestamp ),
17 [
18 'rc_user' => $user->getId(),
19 'rc_user_text' => $user->getName(),
20 'rc_this_oldid' => $thisid,
21 'rc_last_oldid' => $lastid,
22 'rc_cur_id' => $curid
23 ]
24 );
25
26 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
27 }
28
29 public function makeLogRecentChange(
30 $logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers
31 ) {
32 $attribs = array_merge(
33 $this->getDefaultAttributes( $titleText, $timestamp ),
34 [
35 'rc_cur_id' => 0,
36 'rc_user' => $user->getId(),
37 'rc_user_text' => $user->getName(),
38 'rc_this_oldid' => 0,
39 'rc_last_oldid' => 0,
40 'rc_old_len' => null,
41 'rc_new_len' => null,
42 'rc_type' => 3,
43 'rc_logid' => 25,
44 'rc_log_type' => $logType,
45 'rc_log_action' => $logAction,
46 'rc_source' => 'mw.log'
47 ]
48 );
49
50 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
51 }
52
53 public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid,
54 $thisid, $lastid, $counter, $watchingUsers
55 ) {
56 $attribs = array_merge(
57 $this->getDefaultAttributes( $titleText, $timestamp ),
58 [
59 'rc_user' => $user->getId(),
60 'rc_user_text' => $user->getName(),
61 'rc_deleted' => 5,
62 'rc_cur_id' => $curid,
63 'rc_this_oldid' => $thisid,
64 'rc_last_oldid' => $lastid
65 ]
66 );
67
68 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
69 }
70
71 public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
72 $timestamp, $counter, $watchingUsers
73 ) {
74 $attribs = array_merge(
75 $this->getDefaultAttributes( $titleText, $timestamp ),
76 [
77 'rc_user' => $user->getId(),
78 'rc_user_text' => $user->getName(),
79 'rc_this_oldid' => $thisid,
80 'rc_last_oldid' => $lastid,
81 'rc_cur_id' => $curid,
82 'rc_type' => 1,
83 'rc_bot' => 1,
84 'rc_source' => 'mw.new'
85 ]
86 );
87
88 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
89 }
90
91 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
92 $change = new RecentChange();
93 $change->setAttribs( $attribs );
94 $change->counter = $counter;
95 $change->numberofWatchingusers = $watchingUsers;
96
97 return $change;
98 }
99
100 public function getCacheEntry( $recentChange ) {
101 $rcCacheFactory = new RCCacheEntryFactory(
102 new RequestContext(),
103 [ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
104 MediaWikiServices::getInstance()->getLinkRenderer()
105 );
106 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
107 }
108
109 public function makeCategorizationRecentChange(
110 User $user, $titleText, $curid, $thisid, $lastid, $timestamp
111 ) {
112 $attribs = array_merge(
113 $this->getDefaultAttributes( $titleText, $timestamp ),
114 [
115 'rc_type' => RC_CATEGORIZE,
116 'rc_user' => $user->getId(),
117 'rc_user_text' => $user->getName(),
118 'rc_this_oldid' => $thisid,
119 'rc_last_oldid' => $lastid,
120 'rc_cur_id' => $curid,
121 'rc_comment' => '[[:Testpage]] added to category',
122 'rc_comment_text' => '[[:Testpage]] added to category',
123 'rc_comment_data' => null,
124 'rc_old_len' => 0,
125 'rc_new_len' => 0,
126 ]
127 );
128
129 return $this->makeRecentChange( $attribs, 0, 0 );
130 }
131
132 private function getDefaultAttributes( $titleText, $timestamp ) {
133 return [
134 'rc_id' => 545,
135 'rc_user' => 0,
136 'rc_user_text' => '127.0.0.1',
137 'rc_ip' => '127.0.0.1',
138 'rc_title' => $titleText,
139 'rc_namespace' => 0,
140 'rc_timestamp' => $timestamp,
141 'rc_old_len' => 212,
142 'rc_new_len' => 188,
143 'rc_comment' => '',
144 'rc_comment_text' => '',
145 'rc_comment_data' => null,
146 'rc_minor' => 0,
147 'rc_bot' => 0,
148 'rc_type' => 0,
149 'rc_patrolled' => 1,
150 'rc_deleted' => 0,
151 'rc_logid' => 0,
152 'rc_log_type' => null,
153 'rc_log_action' => '',
154 'rc_params' => '',
155 'rc_source' => 'mw.edit'
156 ];
157 }
158
159 public function getTestContext( User $user ) {
160 $context = new RequestContext();
161 $context->setLanguage( 'en' );
162
163 $context->setUser( $user );
164
165 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
166 $context->setTitle( $title );
167
168 return $context;
169 }
170 }