2016-02-01 11:53:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Addshore
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
|
|
|
|
*
|
|
|
|
|
* @covers WatchedItemStore
|
|
|
|
|
*/
|
|
|
|
|
class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
self::$users['WatchedItemStoreIntegrationTestUser']
|
|
|
|
|
= new TestUser( 'WatchedItemStoreIntegrationTestUser' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getUser() {
|
|
|
|
|
return self::$users['WatchedItemStoreIntegrationTestUser']->getUser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWatchAndUnWatchItem() {
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
$title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
|
|
|
|
|
$store = WatchedItemStore::getDefaultInstance();
|
|
|
|
|
// Cleanup after previous tests
|
|
|
|
|
$store->removeWatch( $user, $title );
|
2016-01-26 20:12:37 +00:00
|
|
|
$initialWatchers = $store->countWatchers( $title );
|
2016-02-01 11:53:01 +00:00
|
|
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
$store->isWatched( $user, $title ),
|
|
|
|
|
'Page should not initially be watched'
|
|
|
|
|
);
|
2016-01-26 20:12:37 +00:00
|
|
|
|
2016-02-01 11:53:01 +00:00
|
|
|
$store->addWatch( $user, $title );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$store->isWatched( $user, $title ),
|
|
|
|
|
'Page should be watched'
|
|
|
|
|
);
|
2016-01-26 20:12:37 +00:00
|
|
|
$this->assertEquals( $initialWatchers + 1, $store->countWatchers( $title ) );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$initialWatchers + 1,
|
|
|
|
|
$store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers + 1 ] ],
|
|
|
|
|
$store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 1 ] )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
|
|
|
|
|
$store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 2 ] )
|
|
|
|
|
);
|
|
|
|
|
|
2016-02-01 11:53:01 +00:00
|
|
|
$store->removeWatch( $user, $title );
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
$store->isWatched( $user, $title ),
|
|
|
|
|
'Page should be unwatched'
|
|
|
|
|
);
|
2016-01-26 20:12:37 +00:00
|
|
|
$this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$initialWatchers,
|
|
|
|
|
$store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
|
|
|
|
|
);
|
2016-02-01 11:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-05 12:14:13 +00:00
|
|
|
public function testUpdateAndResetNotificationTimestamp() {
|
2016-02-01 11:53:01 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
$otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
|
|
|
|
|
$title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
|
|
|
|
|
$store = WatchedItemStore::getDefaultInstance();
|
|
|
|
|
$store->addWatch( $user, $title );
|
2016-02-05 12:14:13 +00:00
|
|
|
$this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
|
2016-02-05 12:04:58 +00:00
|
|
|
$initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
|
2016-02-05 12:14:13 +00:00
|
|
|
|
|
|
|
|
$store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'20150202010101',
|
|
|
|
|
$store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
|
|
|
|
|
);
|
2016-02-05 12:04:58 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$initialVisitingWatchers - 1,
|
|
|
|
|
$store->countVisitingWatchers( $title, '20150202020202' )
|
|
|
|
|
);
|
2016-02-01 11:53:01 +00:00
|
|
|
|
|
|
|
|
$this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
|
2016-03-10 13:07:35 +00:00
|
|
|
$this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
|
2016-02-05 12:04:58 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$initialVisitingWatchers,
|
|
|
|
|
$store->countVisitingWatchers( $title, '20150202020202' )
|
|
|
|
|
);
|
2016-02-01 11:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDuplicateAllAssociatedEntries() {
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
$titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
|
|
|
|
|
$titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
|
|
|
|
|
$store = WatchedItemStore::getDefaultInstance();
|
|
|
|
|
$store->addWatch( $user, $titleOld->getSubjectPage() );
|
|
|
|
|
$store->addWatch( $user, $titleOld->getTalkPage() );
|
|
|
|
|
// Cleanup after previous tests
|
|
|
|
|
$store->removeWatch( $user, $titleNew->getSubjectPage() );
|
|
|
|
|
$store->removeWatch( $user, $titleNew->getTalkPage() );
|
|
|
|
|
|
|
|
|
|
$store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
|
|
|
|
|
$this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
|
|
|
|
|
$this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
|
|
|
|
|
$this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|