summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/api/ApiSetNotificationTimestampIntegrationTest.php
blob: dacd48f623ff5277a3a9955c5776861fb9eb59e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
use MediaWiki\MediaWikiServices;

/**
 * @author Addshore
 * @covers ApiSetNotificationTimestamp
 * @group API
 * @group medium
 * @group Database
 */
class ApiSetNotificationTimestampIntegrationTest extends ApiTestCase {

	protected function setUp() {
		parent::setUp();
		self::$users[__CLASS__] = new TestUser( __CLASS__ );
	}

	public function testStuff() {
		$user = self::$users[__CLASS__]->getUser();
		$page = WikiPage::factory( Title::newFromText( 'UTPage' ) );

		$user->addWatch( $page->getTitle() );

		$result = $this->doApiRequestWithToken(
			[
				'action' => 'setnotificationtimestamp',
				'timestamp' => '20160101020202',
				'pageids' => $page->getId(),
			],
			null,
			$user
		);

		$this->assertEquals(
			[
				'batchcomplete' => true,
				'setnotificationtimestamp' => [
					[ 'ns' => 0, 'title' => 'UTPage', 'notificationtimestamp' => '2016-01-01T02:02:02Z' ]
				],
			],
			$result[0]
		);

		$watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
		$this->assertEquals(
			$watchedItemStore->getNotificationTimestampsBatch( $user, [ $page->getTitle() ] ),
			[ [ 'UTPage' => '20160101020202' ] ]
		);
	}

}