9341c4c859f03c4f2082bedc80710ec252829637
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / RecentChangeTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class RecentChangeTest extends MediaWikiTestCase {
7 protected $title;
8 protected $target;
9 protected $user;
10 protected $user_comment;
11 protected $context;
12
13 public function setUp() {
14 parent::setUp();
15
16 $this->title = Title::newFromText( 'SomeTitle' );
17 $this->target = Title::newFromText( 'TestTarget' );
18 $this->user = User::newFromName( 'UserName' );
19
20 $this->user_comment = '<User comment about action>';
21 $this->context = RequestContext::newExtraneousContext( $this->title );
22 }
23
24 /**
25 * The testIrcMsgForAction* tests are supposed to cover the hacky
26 * LogFormatter::getIRCActionText / bug 34508
27 *
28 * Third parties bots listen to those messages. They are clever enough
29 * to fetch the i18n messages from the wiki and then analyze the IRC feed
30 * to reverse engineer the $1, $2 messages.
31 * One thing bots can not detect is when MediaWiki change the meaning of
32 * a message like what happened when we deployed 1.19. $1 became the user
33 * performing the action which broke basically all bots around.
34 *
35 * Should cover the following log actions (which are most commonly used by bots):
36 * - block/block
37 * - block/unblock
38 * - block/reblock
39 * - delete/delete
40 * - delete/restore
41 * - newusers/create
42 * - newusers/create2
43 * - newusers/autocreate
44 * - move/move
45 * - move/move_redir
46 * - protect/protect
47 * - protect/modifyprotect
48 * - protect/unprotect
49 * - protect/move_prot
50 * - upload/upload
51 * - merge/merge
52 * - import/upload
53 * - import/interwiki
54 *
55 * As well as the following Auto Edit Summaries:
56 * - blank
57 * - replace
58 * - rollback
59 * - undo
60 */
61
62 /**
63 * @covers RecentChange::parseParams
64 */
65 public function testParseParams() {
66 $params = array(
67 'root' => array(
68 'A' => 1,
69 'B' => 'two'
70 )
71 );
72
73 $this->assertParseParams(
74 $params,
75 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
76 );
77
78 $this->assertParseParams(
79 null,
80 null
81 );
82
83 $this->assertParseParams(
84 null,
85 serialize( false )
86 );
87
88 $this->assertParseParams(
89 null,
90 'not-an-array'
91 );
92 }
93
94 /**
95 * @param array $expectedParseParams
96 * @param string|null $rawRcParams
97 */
98 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
99 $rc = new RecentChange;
100 $rc->setAttribs( array( 'rc_params' => $rawRcParams ) );
101
102 $actualParseParams = $rc->parseParams();
103
104 $this->assertEquals( $expectedParseParams, $actualParseParams );
105 }
106
107 }