Fixed spacing
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / TestRecentChangesHelper.php
1 <?php
2
3 /**
4 * Helper for generating test recent changes entries.
5 *
6 * @licence GNU GPL v2+
7 * @author Katie Filbert < aude.wiki@gmail.com >
8 */
9 class TestRecentChangesHelper {
10
11 public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
12 $timestamp, $counter, $watchingUsers
13 ) {
14
15 $attribs = array_merge(
16 $this->getDefaultAttributes( $titleText, $timestamp ),
17 array(
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( $logType, User $user, $titleText, $timestamp, $counter,
30 $watchingUsers
31 ) {
32 $attribs = array_merge(
33 $this->getDefaultAttributes( $titleText, $timestamp ),
34 array(
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' => $logType,
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 array(
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
75 $attribs = array_merge(
76 $this->getDefaultAttributes( $titleText, $timestamp ),
77 array(
78 'rc_user' => $user->getId(),
79 'rc_user_text' => $user->getName(),
80 'rc_this_oldid' => $thisid,
81 'rc_last_oldid' => $lastid,
82 'rc_cur_id' => $curid,
83 'rc_type' => 1,
84 'rc_bot' => 1,
85 'rc_source' => 'mw.new'
86 )
87 );
88
89 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
90 }
91
92 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
93 $change = new RecentChange();
94 $change->setAttribs( $attribs );
95 $change->counter = $counter;
96 $change->numberofWatchingusers = $watchingUsers;
97
98 return $change;
99 }
100
101 private function getDefaultAttributes( $titleText, $timestamp ) {
102 return array(
103 'rc_id' => 545,
104 'rc_user' => 0,
105 'rc_user_text' => '127.0.0.1',
106 'rc_ip' => '127.0.0.1',
107 'rc_title' => $titleText,
108 'rc_namespace' => 0,
109 'rc_timestamp' => $timestamp,
110 'rc_old_len' => 212,
111 'rc_new_len' => 188,
112 'rc_comment' => '',
113 'rc_minor' => 0,
114 'rc_bot' => 0,
115 'rc_type' => 0,
116 'rc_patrolled' => 1,
117 'rc_deleted' => 0,
118 'rc_logid' => 0,
119 'rc_log_type' => null,
120 'rc_log_action' => '',
121 'rc_params' => '',
122 'rc_source' => 'mw.edit'
123 );
124 }
125
126 public function getTestContext( User $user ) {
127 $context = new RequestContext();
128 $context->setLanguage( Language::factory( 'en' ) );
129
130 $context->setUser( $user );
131
132 return $context;
133 }
134 }