mediawiki-extensions-Echo/tests/api/ApiEchoMarkReadTest.php
bsitu ff0784e7da Add support to mark all as read for "sections"
This also updates the way how mark all as read works

Change-Id: Ifb7b1b7b7feb4a5af65c79bb16b91a5a9c70166c
2014-08-13 17:16:19 -07:00

113 lines
2.9 KiB
PHP

<?php
/**
* @group medium
* @group API
* @covers ApiQuery
*/
class ApiEchoMarkReadTest extends ApiTestCase {
protected function setUp() {
parent::setUp();
$this->doLogin();
}
function getTokens() {
return $this->getTokenList( self::$users['sysop'] );
}
public function testMarkReadWithList() {
$tokens = $this->getTokens();
// Grouping by section
$data = $this->doApiRequest( array(
'action' => 'echomarkread',
'notlist' => '121|122|123',
'token' => $tokens['edittoken'] ) );
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'echomarkread', $data[0]['query'] );
$result = $data[0]['query']['echomarkread'];
// General count
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
// Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
// Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'rawcount', $message );
$this->assertArrayHasKey( 'count', $message );
}
public function testMarkReadWithAll() {
$tokens = $this->getTokens();
// Grouping by section
$data = $this->doApiRequest( array(
'action' => 'echomarkread',
'notall' => '1',
'token' => $tokens['edittoken'] ) );
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'echomarkread', $data[0]['query'] );
$result = $data[0]['query']['echomarkread'];
// General count
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
// Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
// Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'rawcount', $message );
$this->assertArrayHasKey( 'count', $message );
}
public function testMarkReadWithSections() {
$tokens = $this->getTokens();
// Grouping by section
$data = $this->doApiRequest( array(
'action' => 'echomarkread',
'sections' => 'alert|message',
'token' => $tokens['edittoken'] ) );
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'echomarkread', $data[0]['query'] );
$result = $data[0]['query']['echomarkread'];
// General count
$this->assertArrayHasKey( 'count', $result );
$this->assertArrayHasKey( 'rawcount', $result );
// Alert
$this->assertArrayHasKey( 'alert', $result );
$alert = $result['alert'];
$this->assertArrayHasKey( 'rawcount', $alert );
$this->assertArrayHasKey( 'count', $alert );
// Message
$this->assertArrayHasKey( 'message', $result );
$message = $result['message'];
$this->assertArrayHasKey( 'rawcount', $message );
$this->assertArrayHasKey( 'count', $message );
}
}