X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWatchedItemUnitTest.php;h=0182eb7fc439598f741d6f5fd3702d5b9131ced8;hb=e4e4236dbe37a08c3fa2dceaea4ff21e7cb70d80;hp=b4eaa765e9c30b4aac3533c83a9f2b536c753445;hpb=4d39e688aaa0c890901f3a5f574363d9aa1ef144;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/WatchedItemUnitTest.php b/tests/phpunit/includes/WatchedItemUnitTest.php index b4eaa765e9..0182eb7fc4 100644 --- a/tests/phpunit/includes/WatchedItemUnitTest.php +++ b/tests/phpunit/includes/WatchedItemUnitTest.php @@ -1,17 +1,35 @@ getMock( User::class ); + $user->expects( $this->any() ) + ->method( 'getId' ) + ->will( $this->returnValue( $id ) ); + $user->expects( $this->any() ) + ->method( 'isAllowed' ) + ->will( $this->returnValue( true ) ); + return $user; + } public function provideUserTitleTimestamp() { + $user = $this->getMockUser( 111 ); return [ - [ User::newFromId( 111 ), Title::newFromText( 'SomeTitle' ), null ], - [ User::newFromId( 111 ), Title::newFromText( 'SomeTitle' ), '20150101010101' ], - [ User::newFromId( 111 ), new TitleValue( 0, 'TVTitle', 'frag' ), '20150101010101' ], + [ $user, Title::newFromText( 'SomeTitle' ), null ], + [ $user, Title::newFromText( 'SomeTitle' ), '20150101010101' ], + [ $user, new TitleValue( 0, 'TVTitle', 'frag' ), '20150101010101' ], ]; } @@ -51,15 +69,13 @@ class WatchedItemUnitTest extends PHPUnit_Framework_TestCase { ->method( 'loadWatchedItem' ) ->with( $user, $linkTarget ) ->will( $this->returnValue( new WatchedItem( $user, $linkTarget, $timestamp ) ) ); - $scopedOverride = WatchedItemStore::overrideDefaultInstance( $store ); + $this->setService( 'WatchedItemStore', $store ); $item = WatchedItem::fromUserTitle( $user, $linkTarget, User::IGNORE_USER_RIGHTS ); $this->assertEquals( $user, $item->getUser() ); $this->assertEquals( $linkTarget, $item->getLinkTarget() ); $this->assertEquals( $timestamp, $item->getNotificationTimestamp() ); - - ScopedCallback::consume( $scopedOverride ); } /** @@ -85,12 +101,10 @@ class WatchedItemUnitTest extends PHPUnit_Framework_TestCase { return true; } ) ); - $scopedOverride = WatchedItemStore::overrideDefaultInstance( $store ); + $this->setService( 'WatchedItemStore', $store ); $item = new WatchedItem( $user, $linkTarget, $timestamp ); $item->resetNotificationTimestamp( $force, $oldid ); - - ScopedCallback::consume( $scopedOverride ); } public function testAddWatch() { @@ -157,17 +171,15 @@ class WatchedItemUnitTest extends PHPUnit_Framework_TestCase { $store->expects( $this->once() ) ->method( 'duplicateAllAssociatedEntries' ) ->with( $oldTitle, $newTitle ); - $scopedOverride = WatchedItemStore::overrideDefaultInstance( $store ); + $this->setService( 'WatchedItemStore', $store ); WatchedItem::duplicateEntries( $oldTitle, $newTitle ); - - ScopedCallback::consume( $scopedOverride ); } public function testBatchAddWatch() { - $itemOne = new WatchedItem( User::newFromId( 1 ), new TitleValue( 0, 'Title1' ), null ); + $itemOne = new WatchedItem( $this->getMockUser( 1 ), new TitleValue( 0, 'Title1' ), null ); $itemTwo = new WatchedItem( - User::newFromId( 3 ), + $this->getMockUser( 3 ), Title::newFromText( 'Title2' ), '20150101010101' ); @@ -193,11 +205,9 @@ class WatchedItemUnitTest extends PHPUnit_Framework_TestCase { $itemTwo->getTitle()->getTalkPage(), ] ); - $scopedOverride = WatchedItemStore::overrideDefaultInstance( $store ); + $this->setService( 'WatchedItemStore', $store ); WatchedItem::batchAddWatch( [ $itemOne, $itemTwo ] ); - - ScopedCallback::consume( $scopedOverride ); } }