MessagesGom_deva: Correct syntax in namespace alias
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / TestRecentChangesHelper.php
1 <?php
2 use MediaWiki\Linker\LinkRenderer;
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
16 $attribs = array_merge(
17 $this->getDefaultAttributes( $titleText, $timestamp ),
18 [
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
24 ]
25 );
26
27 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
28 }
29
30 public function makeLogRecentChange(
31 $logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers
32 ) {
33 $attribs = array_merge(
34 $this->getDefaultAttributes( $titleText, $timestamp ),
35 [
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'
48 ]
49 );
50
51 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
52 }
53
54 public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid,
55 $thisid, $lastid, $counter, $watchingUsers
56 ) {
57 $attribs = array_merge(
58 $this->getDefaultAttributes( $titleText, $timestamp ),
59 [
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
66 ]
67 );
68
69 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
70 }
71
72 public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
73 $timestamp, $counter, $watchingUsers
74 ) {
75
76 $attribs = array_merge(
77 $this->getDefaultAttributes( $titleText, $timestamp ),
78 [
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'
87 ]
88 );
89
90 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
91 }
92
93 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
94 $change = new RecentChange();
95 $change->setAttribs( $attribs );
96 $change->counter = $counter;
97 $change->numberofWatchingusers = $watchingUsers;
98
99 return $change;
100 }
101
102 public function getCacheEntry( $recentChange ) {
103 $rcCacheFactory = new RCCacheEntryFactory(
104 new RequestContext(),
105 [ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
106 new LinkRenderer(
107 MediaWikiServices::getInstance()->getTitleFormatter()
108 )
109 );
110 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
111 }
112
113 public function makeCategorizationRecentChange(
114 User $user, $titleText, $curid, $thisid, $lastid, $timestamp
115 ) {
116
117 $attribs = array_merge(
118 $this->getDefaultAttributes( $titleText, $timestamp ),
119 [
120 'rc_type' => RC_CATEGORIZE,
121 'rc_user' => $user->getId(),
122 'rc_user_text' => $user->getName(),
123 'rc_this_oldid' => $thisid,
124 'rc_last_oldid' => $lastid,
125 'rc_cur_id' => $curid,
126 'rc_comment' => '[[:Testpage]] added to category',
127 'rc_old_len' => 0,
128 'rc_new_len' => 0,
129 ]
130 );
131
132 return $this->makeRecentChange( $attribs, 0, 0 );
133 }
134
135 private function getDefaultAttributes( $titleText, $timestamp ) {
136 return [
137 'rc_id' => 545,
138 'rc_user' => 0,
139 'rc_user_text' => '127.0.0.1',
140 'rc_ip' => '127.0.0.1',
141 'rc_title' => $titleText,
142 'rc_namespace' => 0,
143 'rc_timestamp' => $timestamp,
144 'rc_old_len' => 212,
145 'rc_new_len' => 188,
146 'rc_comment' => '',
147 'rc_minor' => 0,
148 'rc_bot' => 0,
149 'rc_type' => 0,
150 'rc_patrolled' => 1,
151 'rc_deleted' => 0,
152 'rc_logid' => 0,
153 'rc_log_type' => null,
154 'rc_log_action' => '',
155 'rc_params' => '',
156 'rc_source' => 'mw.edit'
157 ];
158 }
159
160 public function getTestContext( User $user ) {
161 $context = new RequestContext();
162 $context->setLanguage( 'en' );
163
164 $context->setUser( $user );
165
166 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
167 $context->setTitle( $title );
168
169 return $context;
170 }
171 }