mediawiki-extensions-Echo/tests/phpunit/UnreadWikisTest.php
Umherirrender c650698ac5 Call IDatabase::timestamp before inserting echo_unread_wikis
The default timestamp of 00000000000000 cannot represent as timestamp,
because it gets a negative timestamp -00011130000000

This is needed for proper cross-RDBMS support

This reapply a change from I46206e0b3a687dff3168a81cf0020e669133e876,
reverted with I1c8c409b7820512b3e31246a7f3d8c1cf4db209c.

Bug: T244898
Change-Id: I109b783de0a8d60ccb161b280ce5fa09e145017b
2022-04-11 23:12:02 +00:00

71 lines
1.6 KiB
PHP

<?php
use Wikimedia\TestingAccessWrapper;
/**
* Tests for unread wiki database access
*
* @group Database
* @covers \EchoUnreadWikis
*/
class UnreadWikisTest extends MediaWikiIntegrationTestCase {
public function testUpdateCount() {
$unread = TestingAccessWrapper::newFromObject( new EchoUnreadWikis( 1 ) );
$unread->dbFactory = $this->mockMWEchoDbFactory( $this->db );
$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() {
$unread = TestingAccessWrapper::newFromObject( new EchoUnreadWikis( 1 ) );
$unread->dbFactory = $this->mockMWEchoDbFactory( $this->db );
$unread->updateCount(
'foobar',
3,
false,
4,
false
);
$this->assertSame(
[
'foobar' => [
'alert' => [ 'count' => '3', 'ts' => '00000000000000' ],
'message' => [ 'count' => '4', 'ts' => '00000000000000' ],
]
],
$unread->getUnreadCounts()
);
}
/**
* Mock object of MWEchoDbFactory
* @param \Wikimedia\Rdbms\IDatabase $db
* @return MWEchoDbFactory
*/
protected function mockMWEchoDbFactory( $db ) {
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
->disableOriginalConstructor()
->getMock();
$dbFactory->expects( $this->any() )
->method( 'getSharedDb' )
->will( $this->returnValue( $db ) );
return $dbFactory;
}
}