2022-03-23 22:41:16 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-22 15:31:00 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Test;
|
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
2022-11-13 07:48:43 +00:00
|
|
|
use MediaWiki\Extension\Notifications\UnreadWikis;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2024-02-22 15:31:00 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2022-03-23 22:41:16 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for unread wiki database access
|
|
|
|
*
|
|
|
|
* @group Database
|
2022-11-13 07:48:43 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\UnreadWikis
|
2022-03-23 22:41:16 +00:00
|
|
|
*/
|
|
|
|
class UnreadWikisTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
public function testUpdateCount() {
|
2022-11-13 07:48:43 +00:00
|
|
|
$unread = TestingAccessWrapper::newFromObject( new UnreadWikis( 1 ) );
|
2022-11-12 07:19:00 +00:00
|
|
|
$unread->dbFactory = $this->mockDbFactory( $this->db );
|
2022-03-23 22:41:16 +00:00
|
|
|
$unread->updateCount(
|
|
|
|
'foobar',
|
|
|
|
2,
|
|
|
|
new MWTimestamp( '20220322222222' ),
|
|
|
|
3,
|
|
|
|
new MWTimestamp( '20220322222223' )
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
[
|
|
|
|
'foobar' => [
|
|
|
|
'alert' => [ 'count' => '2', 'ts' => '20220322222222' ],
|
|
|
|
'message' => [ 'count' => '3', 'ts' => '20220322222223' ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
$unread->getUnreadCounts()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateCountFalse() {
|
2022-11-13 07:48:43 +00:00
|
|
|
$unread = TestingAccessWrapper::newFromObject( new UnreadWikis( 1 ) );
|
2022-11-12 07:19:00 +00:00
|
|
|
$unread->dbFactory = $this->mockDbFactory( $this->db );
|
2022-03-23 22:41:16 +00:00
|
|
|
$unread->updateCount(
|
|
|
|
'foobar',
|
|
|
|
3,
|
|
|
|
false,
|
|
|
|
4,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
[
|
|
|
|
'foobar' => [
|
|
|
|
'alert' => [ 'count' => '3', 'ts' => '00000000000000' ],
|
|
|
|
'message' => [ 'count' => '4', 'ts' => '00000000000000' ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
$unread->getUnreadCounts()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-12 07:19:00 +00:00
|
|
|
* Mock object of DbFactory
|
2022-03-23 22:41:16 +00:00
|
|
|
* @param \Wikimedia\Rdbms\IDatabase $db
|
2022-11-12 07:19:00 +00:00
|
|
|
* @return DbFactory
|
2022-03-23 22:41:16 +00:00
|
|
|
*/
|
2022-11-12 07:19:00 +00:00
|
|
|
protected function mockDbFactory( $db ) {
|
|
|
|
$dbFactory = $this->createMock( DbFactory::class );
|
2022-03-23 22:41:16 +00:00
|
|
|
$dbFactory->expects( $this->any() )
|
|
|
|
->method( 'getSharedDb' )
|
2022-11-12 07:19:00 +00:00
|
|
|
->willReturn( $db );
|
2022-03-23 22:41:16 +00:00
|
|
|
|
|
|
|
return $dbFactory;
|
|
|
|
}
|
|
|
|
}
|