2013-11-26 11:56:17 +00:00
|
|
|
<?php
|
2014-03-12 17:08:40 +00:00
|
|
|
|
2013-11-26 11:56:17 +00:00
|
|
|
/**
|
|
|
|
|
* @covers RCCacheEntryFactory
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
|
|
|
|
*
|
|
|
|
|
* @licence GNU GPL v2+
|
|
|
|
|
* @author Katie Filbert < aude.wiki@gmail.com >
|
|
|
|
|
*/
|
|
|
|
|
class RCCacheEntryFactoryTest extends MediaWikiLangTestCase {
|
2014-07-25 07:30:09 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var TestRecentChangesHelper
|
|
|
|
|
*/
|
|
|
|
|
private $testRecentChangesHelper;
|
|
|
|
|
|
|
|
|
|
public function __construct( $name = null, array $data = array(), $dataName = '' ) {
|
|
|
|
|
parent::__construct( $name, $data, $dataName );
|
|
|
|
|
|
|
|
|
|
$this->testRecentChangesHelper = new TestRecentChangesHelper();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 11:56:17 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgArticlePath' => '/wiki/$1'
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider editChangeProvider
|
|
|
|
|
*/
|
2014-03-12 17:08:40 +00:00
|
|
|
public function testNewFromRecentChange( $expected, $context, $messages,
|
|
|
|
|
$recentChange, $watched
|
|
|
|
|
) {
|
2013-11-26 11:56:17 +00:00
|
|
|
$cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
|
|
|
|
|
$cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
|
|
|
|
|
$this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
|
2014-03-12 17:08:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers,
|
|
|
|
|
'watching users'
|
|
|
|
|
);
|
2013-11-26 11:56:17 +00:00
|
|
|
$this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
|
|
|
|
|
|
2014-07-25 07:30:09 +00:00
|
|
|
$this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
|
2013-11-26 11:56:17 +00:00
|
|
|
$this->assertTitleLink( 'Xyz', $cacheEntry );
|
|
|
|
|
|
|
|
|
|
$this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink, 'cur link' );
|
|
|
|
|
$this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink, 'prev link' );
|
|
|
|
|
$this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink, 'diff link' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function editChangeProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
array(
|
|
|
|
|
'title' => 'Xyz',
|
2014-07-25 07:30:09 +00:00
|
|
|
'user' => 'TestRecentChangesUser',
|
2013-11-26 11:56:17 +00:00
|
|
|
'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
|
|
|
|
|
'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
|
|
|
|
|
'timestamp' => '21:21',
|
|
|
|
|
'numberofWatchingusers' => 0,
|
|
|
|
|
'unpatrolled' => false
|
|
|
|
|
),
|
|
|
|
|
$this->getContext(),
|
|
|
|
|
$this->getMessages(),
|
2014-07-25 07:30:09 +00:00
|
|
|
$this->testRecentChangesHelper->makeEditRecentChange(
|
2014-07-25 13:05:39 +00:00
|
|
|
$this->getTestUser(),
|
2013-11-26 11:56:17 +00:00
|
|
|
'Xyz',
|
|
|
|
|
5, // curid
|
|
|
|
|
191, // thisid
|
|
|
|
|
190, // lastid
|
|
|
|
|
'20131103212153',
|
|
|
|
|
0, // counter
|
|
|
|
|
0 // number of watching users
|
|
|
|
|
),
|
2014-07-25 07:36:54 +00:00
|
|
|
false
|
2013-11-26 11:56:17 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider deleteChangeProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
|
|
|
|
|
$cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
|
|
|
|
|
$cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
|
|
|
|
|
$this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
|
2014-03-12 17:08:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected['numberofWatchingusers'],
|
|
|
|
|
$cacheEntry->numberofWatchingusers, 'watching users'
|
|
|
|
|
);
|
2013-11-26 11:56:17 +00:00
|
|
|
$this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
|
|
|
|
|
|
|
|
|
|
$this->assertDeleteLogLink( $cacheEntry );
|
2014-07-25 07:30:09 +00:00
|
|
|
$this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
|
2013-11-26 11:56:17 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
|
|
|
|
|
$this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
|
|
|
|
|
$this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteChangeProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
array(
|
|
|
|
|
'title' => 'Abc',
|
2014-07-25 07:30:09 +00:00
|
|
|
'user' => 'TestRecentChangesUser',
|
2013-11-26 11:56:17 +00:00
|
|
|
'timestamp' => '21:21',
|
|
|
|
|
'numberofWatchingusers' => 0,
|
|
|
|
|
'unpatrolled' => false
|
|
|
|
|
),
|
|
|
|
|
$this->getContext(),
|
|
|
|
|
$this->getMessages(),
|
2014-07-25 07:30:09 +00:00
|
|
|
$this->testRecentChangesHelper->makeLogRecentChange(
|
2014-07-25 13:05:39 +00:00
|
|
|
'delete',
|
|
|
|
|
$this->getTestUser(),
|
2013-11-26 11:56:17 +00:00
|
|
|
'Abc',
|
|
|
|
|
'20131103212153',
|
|
|
|
|
0, // counter
|
|
|
|
|
0 // number of watching users
|
|
|
|
|
),
|
2014-07-25 07:36:54 +00:00
|
|
|
false
|
2013-11-26 11:56:17 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider revUserDeleteProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testNewForRevUserDeleteChange( $expected, $context, $messages,
|
|
|
|
|
$recentChange, $watched
|
|
|
|
|
) {
|
|
|
|
|
$cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
|
|
|
|
|
$cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
|
|
|
|
|
$this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
|
2014-03-12 17:08:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected['numberofWatchingusers'],
|
|
|
|
|
$cacheEntry->numberofWatchingusers, 'watching users'
|
|
|
|
|
);
|
2013-11-26 11:56:17 +00:00
|
|
|
$this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
|
|
|
|
|
|
|
|
|
|
$this->assertRevDel( $cacheEntry );
|
|
|
|
|
$this->assertTitleLink( 'Zzz', $cacheEntry );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
|
|
|
|
|
$this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
|
|
|
|
|
$this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function revUserDeleteProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
array(
|
|
|
|
|
'title' => 'Zzz',
|
2014-07-25 07:30:09 +00:00
|
|
|
'user' => 'TestRecentChangesUser',
|
2013-11-26 11:56:17 +00:00
|
|
|
'diff' => '',
|
|
|
|
|
'cur' => '',
|
|
|
|
|
'timestamp' => '21:21',
|
|
|
|
|
'numberofWatchingusers' => 0,
|
|
|
|
|
'unpatrolled' => false
|
|
|
|
|
),
|
|
|
|
|
$this->getContext(),
|
|
|
|
|
$this->getMessages(),
|
2014-07-25 07:30:09 +00:00
|
|
|
$this->testRecentChangesHelper->makeDeletedEditRecentChange(
|
2014-07-25 13:05:39 +00:00
|
|
|
$this->getTestUser(),
|
2013-11-26 11:56:17 +00:00
|
|
|
'Zzz',
|
|
|
|
|
'20131103212153',
|
|
|
|
|
191, // thisid
|
|
|
|
|
190, // lastid
|
|
|
|
|
'20131103212153',
|
|
|
|
|
0, // counter
|
|
|
|
|
0 // number of watching users
|
|
|
|
|
),
|
2014-07-25 07:36:54 +00:00
|
|
|
false
|
2013-11-26 11:56:17 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertUserLinks( $user, $cacheEntry ) {
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'a',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'class' => 'new mw-userlink'
|
|
|
|
|
),
|
|
|
|
|
'content' => $user
|
|
|
|
|
),
|
|
|
|
|
$cacheEntry->userlink,
|
|
|
|
|
'verify user link'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'span',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'class' => 'mw-usertoollinks'
|
|
|
|
|
),
|
|
|
|
|
'child' => array(
|
|
|
|
|
'tag' => 'a',
|
|
|
|
|
'content' => 'Talk',
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
$cacheEntry->usertalklink,
|
|
|
|
|
'verify user talk link'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'span',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'class' => 'mw-usertoollinks'
|
|
|
|
|
),
|
|
|
|
|
'child' => array(
|
|
|
|
|
'tag' => 'a',
|
|
|
|
|
'content' => 'contribs',
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
$cacheEntry->usertalklink,
|
|
|
|
|
'verify user tool links'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertDeleteLogLink( $cacheEntry ) {
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'a',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'href' => '/wiki/Special:Log/delete',
|
|
|
|
|
'title' => 'Special:Log/delete'
|
|
|
|
|
),
|
|
|
|
|
'content' => 'Deletion log'
|
|
|
|
|
),
|
|
|
|
|
$cacheEntry->link,
|
|
|
|
|
'verify deletion log link'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertRevDel( $cacheEntry ) {
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'span',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'class' => 'history-deleted'
|
|
|
|
|
),
|
|
|
|
|
'content' => '(username removed)'
|
|
|
|
|
),
|
|
|
|
|
$cacheEntry->userlink,
|
|
|
|
|
'verify user link for change with deleted revision and user'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertTitleLink( $title, $cacheEntry ) {
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'a',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'href' => '/wiki/' . $title,
|
|
|
|
|
'title' => $title
|
|
|
|
|
),
|
|
|
|
|
'content' => $title
|
|
|
|
|
),
|
|
|
|
|
$cacheEntry->link,
|
|
|
|
|
'verify title link'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertQueryLink( $content, $params, $link ) {
|
|
|
|
|
$this->assertTag(
|
|
|
|
|
array(
|
|
|
|
|
'tag' => 'a',
|
|
|
|
|
'content' => $content
|
|
|
|
|
),
|
|
|
|
|
$link,
|
|
|
|
|
'assert query link element'
|
|
|
|
|
);
|
|
|
|
|
|
2014-03-12 17:08:40 +00:00
|
|
|
foreach ( $params as $key => $value ) {
|
2013-11-26 11:56:17 +00:00
|
|
|
$this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getMessages() {
|
|
|
|
|
return array(
|
|
|
|
|
'cur' => 'cur',
|
|
|
|
|
'diff' => 'diff',
|
|
|
|
|
'hist' => 'hist',
|
|
|
|
|
'enhancedrc-history' => 'history',
|
|
|
|
|
'last' => 'prev',
|
|
|
|
|
'blocklink' => 'block',
|
|
|
|
|
'history' => 'Page history',
|
|
|
|
|
'semicolon-separator' => '; ',
|
|
|
|
|
'pipe-separator' => ' | '
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 13:05:39 +00:00
|
|
|
private function getTestUser() {
|
|
|
|
|
$user = User::newFromName( 'TestRecentChangesUser' );
|
|
|
|
|
|
|
|
|
|
if ( !$user->getId() ) {
|
|
|
|
|
$user->addToDatabase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 11:56:17 +00:00
|
|
|
private function getContext() {
|
2014-07-25 13:05:39 +00:00
|
|
|
$user = $this->getTestUser();
|
|
|
|
|
$context = $this->testRecentChangesHelper->getTestContext( $user );
|
2013-11-26 11:56:17 +00:00
|
|
|
|
2014-07-25 07:30:09 +00:00
|
|
|
$title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
|
2013-11-26 11:56:17 +00:00
|
|
|
$context->setTitle( $title );
|
|
|
|
|
|
|
|
|
|
return $context;
|
|
|
|
|
}
|
|
|
|
|
}
|