Merge "Fixes to masterPosWait() for master switchovers"
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreTest.php
1 <?php
2
3 /**
4 * @author Addshore
5 *
6 * @covers WatchedItemStore
7 */
8 class WatchedItemStoreTest extends PHPUnit_Framework_TestCase {
9
10 /**
11 * @return PHPUnit_Framework_MockObject_MockObject|IDatabase
12 */
13 private function getMockDb() {
14 return $this->getMock( 'IDatabase' );
15 }
16
17 /**
18 * @return PHPUnit_Framework_MockObject_MockObject|LoadBalancer
19 */
20 private function getMockLoadBalancer( $mockDb ) {
21 $mock = $this->getMockBuilder( 'LoadBalancer' )
22 ->disableOriginalConstructor()
23 ->getMock();
24 $mock->expects( $this->any() )
25 ->method( 'getConnection' )
26 ->will( $this->returnValue( $mockDb ) );
27 return $mock;
28 }
29
30 private function getFakeRow( $userId, $timestamp ) {
31 $fakeRow = new stdClass();
32 $fakeRow->wl_user = $userId;
33 $fakeRow->wl_notificationtimestamp = $timestamp;
34 return $fakeRow;
35 }
36
37 public function testDuplicateEntry_nothingToDuplicate() {
38 $mockDb = $this->getMockDb();
39 $mockDb->expects( $this->exactly( 1 ) )
40 ->method( 'select' )
41 ->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
42
43 $store = new WatchedItemStore( $this->getMockLoadBalancer( $mockDb ) );
44
45 $store->duplicateEntry(
46 Title::newFromText( 'Old_Title' ),
47 Title::newFromText( 'New_Title' )
48 );
49 }
50
51 public function testDuplicateEntry_somethingToDuplicate() {
52 $fakeRows = [
53 $this->getFakeRow( 1, '20151212010101' ),
54 $this->getFakeRow( 2, null ),
55 ];
56
57 $mockDb = $this->getMockDb();
58 $mockDb->expects( $this->at( 0 ) )
59 ->method( 'select' )
60 ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
61 $mockDb->expects( $this->at( 1 ) )
62 ->method( 'replace' )
63 ->with(
64 'watchlist',
65 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
66 [
67 [
68 'wl_user' => 1,
69 'wl_namespace' => 0,
70 'wl_title' => 'New_Title',
71 'wl_notificationtimestamp' => '20151212010101',
72 ],
73 [
74 'wl_user' => 2,
75 'wl_namespace' => 0,
76 'wl_title' => 'New_Title',
77 'wl_notificationtimestamp' => null,
78 ],
79 ],
80 $this->isType( 'string' )
81 );
82
83 $store = new WatchedItemStore( $this->getMockLoadBalancer( $mockDb ) );
84
85 $store->duplicateEntry(
86 Title::newFromText( 'Old_Title' ),
87 Title::newFromText( 'New_Title' )
88 );
89 }
90
91 }