Add parameter to API modules to apply change tags to log entries
[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 MediaWikiServices::getInstance()->getLinkRenderer()
107 );
108 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
109 }
110
111 public function makeCategorizationRecentChange(
112 User $user, $titleText, $curid, $thisid, $lastid, $timestamp
113 ) {
114
115 $attribs = array_merge(
116 $this->getDefaultAttributes( $titleText, $timestamp ),
117 [
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,
127 ]
128 );
129
130 return $this->makeRecentChange( $attribs, 0, 0 );
131 }
132
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'
155 ];
156 }
157
158 public function getTestContext( User $user ) {
159 $context = new RequestContext();
160 $context->setLanguage( 'en' );
161
162 $context->setUser( $user );
163
164 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
165 $context->setTitle( $title );
166
167 return $context;
168 }
169 }