Merge "Remove $wgAllowMicroDataAttributes and $wgAllowRdfaAttributes"
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreIntegrationTest.php
1 <?php
2
3 /**
4 * @author Addshore
5 *
6 * @group Database
7 *
8 * @covers WatchedItemStore
9 */
10 class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
11
12 public function setUp() {
13 parent::setUp();
14 self::$users['WatchedItemStoreIntegrationTestUser']
15 = new TestUser( 'WatchedItemStoreIntegrationTestUser' );
16 }
17
18 private function getUser() {
19 return self::$users['WatchedItemStoreIntegrationTestUser']->getUser();
20 }
21
22 public function testWatchAndUnWatchItem() {
23 $user = $this->getUser();
24 $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
25 $store = WatchedItemStore::getDefaultInstance();
26 // Cleanup after previous tests
27 $store->removeWatch( $user, $title );
28 $initialWatchers = $store->countWatchers( $title );
29 $initialUserWatchedItems = $store->countWatchedItems( $user );
30
31 $this->assertFalse(
32 $store->isWatched( $user, $title ),
33 'Page should not initially be watched'
34 );
35
36 $store->addWatch( $user, $title );
37 $this->assertTrue(
38 $store->isWatched( $user, $title ),
39 'Page should be watched'
40 );
41 $this->assertEquals( $initialUserWatchedItems + 1, $store->countWatchedItems( $user ) );
42 $this->assertEquals( $initialWatchers + 1, $store->countWatchers( $title ) );
43 $this->assertEquals(
44 $initialWatchers + 1,
45 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
46 );
47 $this->assertEquals(
48 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers + 1 ] ],
49 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 1 ] )
50 );
51 $this->assertEquals(
52 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
53 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 2 ] )
54 );
55
56 $store->removeWatch( $user, $title );
57 $this->assertFalse(
58 $store->isWatched( $user, $title ),
59 'Page should be unwatched'
60 );
61 $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
62 $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
63 $this->assertEquals(
64 $initialWatchers,
65 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
66 );
67 }
68
69 public function testUpdateAndResetNotificationTimestamp() {
70 $user = $this->getUser();
71 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
72 $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
73 $store = WatchedItemStore::getDefaultInstance();
74 $store->addWatch( $user, $title );
75 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
76 $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
77 $initialUnreadNotifications = $store->countUnreadNotifications( $user );
78
79 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
80 $this->assertEquals(
81 '20150202010101',
82 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
83 );
84 $this->assertEquals(
85 $initialVisitingWatchers - 1,
86 $store->countVisitingWatchers( $title, '20150202020202' )
87 );
88 $this->assertEquals(
89 $initialVisitingWatchers - 1,
90 $store->countVisitingWatchersMultiple(
91 [ [ $title, '20150202020202' ] ]
92 )[$title->getNamespace()][$title->getDBkey()]
93 );
94 $this->assertEquals(
95 $initialUnreadNotifications + 1,
96 $store->countUnreadNotifications( $user )
97 );
98 $this->assertSame(
99 true,
100 $store->countUnreadNotifications( $user, $initialUnreadNotifications + 1 )
101 );
102
103 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
104 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
105 $this->assertEquals(
106 $initialVisitingWatchers,
107 $store->countVisitingWatchers( $title, '20150202020202' )
108 );
109 $this->assertEquals(
110 $initialVisitingWatchers,
111 $store->countVisitingWatchersMultiple(
112 [ [ $title, '20150202020202' ] ]
113 )[$title->getNamespace()][$title->getDBkey()]
114 );
115 $this->assertEquals(
116 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialVisitingWatchers ] ],
117 $store->countVisitingWatchersMultiple(
118 [ [ $title, '20150202020202' ] ], $initialVisitingWatchers
119 )
120 );
121 $this->assertEquals(
122 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
123 $store->countVisitingWatchersMultiple(
124 [ [ $title, '20150202020202' ] ], $initialVisitingWatchers + 1
125 )
126 );
127 }
128
129 public function testDuplicateAllAssociatedEntries() {
130 $user = $this->getUser();
131 $titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
132 $titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
133 $store = WatchedItemStore::getDefaultInstance();
134 $store->addWatch( $user, $titleOld->getSubjectPage() );
135 $store->addWatch( $user, $titleOld->getTalkPage() );
136 // Cleanup after previous tests
137 $store->removeWatch( $user, $titleNew->getSubjectPage() );
138 $store->removeWatch( $user, $titleNew->getTalkPage() );
139
140 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
141
142 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
143 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
144 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
145 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );
146 }
147
148 }