aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/includes/api/ApiDeleteTest.php14
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php12
-rw-r--r--tests/phpunit/includes/api/ApiMoveTest.php6
-rw-r--r--tests/phpunit/includes/api/ApiProtectTest.php5
-rw-r--r--tests/phpunit/includes/api/ApiRollbackTest.php2
-rw-r--r--tests/phpunit/includes/api/ApiSetNotificationTimestampIntegrationTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiUndeleteTest.php5
-rw-r--r--tests/phpunit/includes/api/ApiUploadTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryInfoTest.php6
-rw-r--r--tests/phpunit/integration/includes/api/ApiWatchlistTraitTest.php (renamed from tests/phpunit/unit/includes/api/ApiWatchlistTraitTest.php)9
10 files changed, 39 insertions, 25 deletions
diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php b/tests/phpunit/includes/api/ApiDeleteTest.php
index af34dfecef5c..aff430215fda 100644
--- a/tests/phpunit/includes/api/ApiDeleteTest.php
+++ b/tests/phpunit/includes/api/ApiDeleteTest.php
@@ -192,10 +192,11 @@ class ApiDeleteTest extends ApiTestCase {
public function testDeleteWatch() {
$name = 'Help:' . ucfirst( __FUNCTION__ );
$user = self::$users['sysop']->getUser();
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
$this->editPage( $name, 'Some text' );
$this->assertTrue( Title::newFromText( $name )->exists() );
- $this->assertFalse( $user->isWatched( Title::newFromText( $name ) ) );
+ $this->assertFalse( $watchlistManager->isWatched( $user, Title::newFromText( $name ) ) );
$this->doApiRequestWithToken( [
'action' => 'delete',
@@ -206,8 +207,8 @@ class ApiDeleteTest extends ApiTestCase {
$title = Title::newFromText( $name );
$this->assertFalse( $title->exists() );
- $this->assertTrue( $user->isWatched( $title ) );
- $this->assertTrue( $user->isTempWatched( $title ) );
+ $this->assertTrue( $watchlistManager->isWatched( $user, $title ) );
+ $this->assertTrue( $watchlistManager->isTempWatched( $user, $title ) );
}
public function testDeleteUnwatch() {
@@ -216,8 +217,9 @@ class ApiDeleteTest extends ApiTestCase {
$this->editPage( $name, 'Some text' );
$this->assertTrue( Title::newFromText( $name )->exists() );
- $user->addWatch( Title::newFromText( $name ) );
- $this->assertTrue( $user->isWatched( Title::newFromText( $name ) ) );
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
+ $watchlistManager->addWatch( $user, Title::newFromText( $name ) );
+ $this->assertTrue( $watchlistManager->isWatched( $user, Title::newFromText( $name ) ) );
$this->doApiRequestWithToken( [
'action' => 'delete',
@@ -226,6 +228,6 @@ class ApiDeleteTest extends ApiTestCase {
] );
$this->assertFalse( Title::newFromText( $name )->exists() );
- $this->assertFalse( $user->isWatched( Title::newFromText( $name ) ) );
+ $this->assertFalse( $watchlistManager->isWatched( $user, Title::newFromText( $name ) ) );
}
}
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 7b40f044b3cf..0f4694f2fc29 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -1347,6 +1347,7 @@ class ApiEditPageTest extends ApiTestCase {
public function testEditWatch() {
$name = 'Help:' . ucfirst( __FUNCTION__ );
$user = self::$users['sysop']->getUser();
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
$this->doApiRequestWithToken( [
'action' => 'edit',
@@ -1358,8 +1359,8 @@ class ApiEditPageTest extends ApiTestCase {
$title = Title::newFromText( $name );
$this->assertTrue( $title->exists() );
- $this->assertTrue( $user->isWatched( $title ) );
- $this->assertTrue( $user->isTempWatched( $title ) );
+ $this->assertTrue( $watchlistManager->isWatched( $user, $title ) );
+ $this->assertTrue( $watchlistManager->isTempWatched( $user, $title ) );
}
public function testEditUnwatch() {
@@ -1367,10 +1368,11 @@ class ApiEditPageTest extends ApiTestCase {
$user = self::$users['sysop']->getUser();
$titleObj = Title::newFromText( $name );
- $user->addWatch( $titleObj );
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
+ $watchlistManager->addWatch( $user, $titleObj );
$this->assertFalse( $titleObj->exists() );
- $this->assertTrue( $user->isWatched( $titleObj ) );
+ $this->assertTrue( $watchlistManager->isWatched( $user, $titleObj ) );
$this->doApiRequestWithToken( [
'action' => 'edit',
@@ -1380,7 +1382,7 @@ class ApiEditPageTest extends ApiTestCase {
] );
$this->assertTrue( $titleObj->exists() );
- $this->assertFalse( $user->isWatched( $titleObj ) );
+ $this->assertFalse( $watchlistManager->isWatched( $user, $titleObj ) );
}
public function testEditWithTag() {
diff --git a/tests/phpunit/includes/api/ApiMoveTest.php b/tests/phpunit/includes/api/ApiMoveTest.php
index b82214eb3666..4f879917870d 100644
--- a/tests/phpunit/includes/api/ApiMoveTest.php
+++ b/tests/phpunit/includes/api/ApiMoveTest.php
@@ -128,8 +128,10 @@ class ApiMoveTest extends ApiTestCase {
$title = Title::newFromText( $name );
$title2 = Title::newFromText( "$name 2" );
- $this->assertTrue( $this->getTestSysop()->getUser()->isTempWatched( $title ) );
- $this->assertTrue( $this->getTestSysop()->getUser()->isTempWatched( $title2 ) );
+ $user = $this->getTestSysop()->getUser();
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
+ $this->assertTrue( $watchlistManager->isTempWatched( $user, $title ) );
+ $this->assertTrue( $watchlistManager->isTempWatched( $user, $title2 ) );
}
public function testMoveWithWatchUnchanged(): void {
diff --git a/tests/phpunit/includes/api/ApiProtectTest.php b/tests/phpunit/includes/api/ApiProtectTest.php
index 021d38de3510..02d91b47fe2e 100644
--- a/tests/phpunit/includes/api/ApiProtectTest.php
+++ b/tests/phpunit/includes/api/ApiProtectTest.php
@@ -44,6 +44,9 @@ class ApiProtectTest extends ApiTestCase {
$this->assertArrayHasKey( 'protect', $apiResult );
$this->assertSame( $name, $apiResult['protect']['title'] );
$this->assertTrue( $title->isProtected( 'edit' ) );
- $this->assertTrue( $this->getTestSysop()->getUser()->isTempWatched( $title ) );
+ $this->assertTrue( $this->getServiceContainer()->getWatchlistManager()->isTempWatched(
+ $this->getTestSysop()->getUser(),
+ $title
+ ) );
}
}
diff --git a/tests/phpunit/includes/api/ApiRollbackTest.php b/tests/phpunit/includes/api/ApiRollbackTest.php
index 3eb7ce09deda..e0126cc0e77d 100644
--- a/tests/phpunit/includes/api/ApiRollbackTest.php
+++ b/tests/phpunit/includes/api/ApiRollbackTest.php
@@ -65,6 +65,6 @@ class ApiRollbackTest extends ApiTestCase {
$this->assertSame( $name, $apiResult['rollback']['title'] );
// And that the page was temporarily watched.
- $this->assertTrue( $sysop->isTempWatched( $title ) );
+ $this->assertTrue( $this->getServiceContainer()->getWatchlistManager()->isTempWatched( $sysop, $title ) );
}
}
diff --git a/tests/phpunit/includes/api/ApiSetNotificationTimestampIntegrationTest.php b/tests/phpunit/includes/api/ApiSetNotificationTimestampIntegrationTest.php
index c60a7d8fc977..867d178a5476 100644
--- a/tests/phpunit/includes/api/ApiSetNotificationTimestampIntegrationTest.php
+++ b/tests/phpunit/includes/api/ApiSetNotificationTimestampIntegrationTest.php
@@ -24,7 +24,8 @@ class ApiSetNotificationTimestampIntegrationTest extends ApiTestCase {
$user = $this->getTestUser()->getUser();
$page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
- $user->addWatch( $page->getTitle() );
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
+ $watchlistManager->addWatch( $user, $page->getTitle() );
$result = $this->doApiRequestWithToken(
[
diff --git a/tests/phpunit/includes/api/ApiUndeleteTest.php b/tests/phpunit/includes/api/ApiUndeleteTest.php
index bd05b191d3b0..5623c6e16bad 100644
--- a/tests/phpunit/includes/api/ApiUndeleteTest.php
+++ b/tests/phpunit/includes/api/ApiUndeleteTest.php
@@ -30,6 +30,7 @@ class ApiUndeleteTest extends ApiTestCase {
$name = ucfirst( __FUNCTION__ );
$title = Title::newFromText( $name );
$sysop = $this->getTestSysop()->getUser();
+ $watchlistManager = $this->getServiceContainer()->getWatchlistManager();
// Create page.
$this->editPage( $name, 'Test' );
@@ -42,7 +43,7 @@ class ApiUndeleteTest extends ApiTestCase {
// For good measure.
$this->assertFalse( $title->exists() );
- $this->assertFalse( $sysop->isWatched( $title ) );
+ $this->assertFalse( $watchlistManager->isWatched( $sysop, $title ) );
// Restore page, and watch with expiry.
$this->doApiRequestWithToken( [
@@ -53,6 +54,6 @@ class ApiUndeleteTest extends ApiTestCase {
] );
$this->assertTrue( $title->exists() );
- $this->assertTrue( $sysop->isTempWatched( $title ) );
+ $this->assertTrue( $watchlistManager->isTempWatched( $sysop, $title ) );
}
}
diff --git a/tests/phpunit/includes/api/ApiUploadTest.php b/tests/phpunit/includes/api/ApiUploadTest.php
index a22db11edf86..89f26a59424e 100644
--- a/tests/phpunit/includes/api/ApiUploadTest.php
+++ b/tests/phpunit/includes/api/ApiUploadTest.php
@@ -75,7 +75,7 @@ class ApiUploadTest extends ApiUploadTestCase {
$this->assertEquals( 'Success', $result['upload']['result'] );
$this->assertSame( filesize( $filePath ), (int)$result['upload']['imageinfo']['size'] );
$this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
- $this->assertTrue( $user->isTempWatched( $title ) );
+ $this->assertTrue( $this->getServiceContainer()->getWatchlistManager()->isTempWatched( $user, $title ) );
}
public function testUploadZeroLength() {
diff --git a/tests/phpunit/includes/api/query/ApiQueryInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryInfoTest.php
index 958986a36fea..3ff7864460cb 100644
--- a/tests/phpunit/includes/api/query/ApiQueryInfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryInfoTest.php
@@ -39,14 +39,12 @@ class ApiQueryInfoTest extends ApiTestCase {
$title = $page->getTitle();
$user = $this->getTestUser()->getUser();
RequestContext::getMain()->setUser( $user );
- WatchAction::doWatch(
- $title,
+ $this->getServiceContainer()->getWatchlistManager()->addWatch(
$user,
- User::CHECK_USER_RIGHTS,
+ $title,
// 3 months later
'2011-04-01T00:00:00Z'
);
- $watchItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
list( $data ) = $this->doApiRequest( [
'action' => 'query',
diff --git a/tests/phpunit/unit/includes/api/ApiWatchlistTraitTest.php b/tests/phpunit/integration/includes/api/ApiWatchlistTraitTest.php
index a2341169bf8f..a20c0fb5990f 100644
--- a/tests/phpunit/unit/includes/api/ApiWatchlistTraitTest.php
+++ b/tests/phpunit/integration/includes/api/ApiWatchlistTraitTest.php
@@ -1,12 +1,13 @@
<?php
+use MediaWiki\Watchlist\WatchlistManager;
use Wikimedia\TestingAccessWrapper;
/**
* @group API
* @covers ApiWatchlistTrait
*/
-class ApiWatchlistTraitTest extends MediaWikiUnitTestCase {
+class ApiWatchlistTraitTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideWatchlistValue
@@ -17,7 +18,6 @@ class ApiWatchlistTraitTest extends MediaWikiUnitTestCase {
// TODO we don't currently test any of the logic that depends on if the title exists
$user = $this->createMock( User::class );
$user->method( 'isBot' )->willReturn( $isBot );
- $user->method( 'isWatched' )->willReturn( $isWatched );
$user->method( 'getBoolOption' )->willReturnCallback(
function ( $optionName ) use ( $setOption ) {
if ( $optionName === 'watchdefault' ) {
@@ -28,6 +28,11 @@ class ApiWatchlistTraitTest extends MediaWikiUnitTestCase {
}
);
+ $watchlistManager = $this->createMock( WatchlistManager::class );
+ $watchlistManager->method( 'isWatchable' )->willReturn( true );
+ $watchlistManager->method( 'isWatchedIgnoringRights' )->willReturn( $isWatched );
+ $this->setService( 'WatchlistManager', $watchlistManager );
+
$title = $this->createMock( Title::class );
$title->method( 'exists' )->willReturn( true );