| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Test; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\DbFactory; |
| 6 |
use MediaWiki\Extension\Notifications\UnreadWikis; |
| 7 |
use MediaWiki\Utils\MWTimestamp; |
| 8 |
use MediaWikiIntegrationTestCase; |
| 9 |
use Wikimedia\TestingAccessWrapper; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class UnreadWikisTest extends MediaWikiIntegrationTestCase { |
| 18 |
|
| 19 |
public function testUpdateCount() { |
| 20 |
$unread = TestingAccessWrapper::newFromObject( new UnreadWikis( 1 ) ); |
| 21 |
$unread->dbFactory = $this->mockDbFactory( $this->db ); |
| 22 |
$unread->updateCount( |
| 23 |
'foobar', |
| 24 |
2, |
| 25 |
new MWTimestamp( '20220322222222' ), |
| 26 |
3, |
| 27 |
new MWTimestamp( '20220322222223' ) |
| 28 |
); |
| 29 |
$this->assertSame( |
| 30 |
[ |
| 31 |
'foobar' => [ |
| 32 |
'alert' => [ 'count' => '2', 'ts' => '20220322222222' ], |
| 33 |
'message' => [ 'count' => '3', 'ts' => '20220322222223' ], |
| 34 |
] |
| 35 |
], |
| 36 |
$unread->getUnreadCounts() |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
public function testUpdateCountFalse() { |
| 41 |
$unread = TestingAccessWrapper::newFromObject( new UnreadWikis( 1 ) ); |
| 42 |
$unread->dbFactory = $this->mockDbFactory( $this->db ); |
| 43 |
$unread->updateCount( |
| 44 |
'foobar', |
| 45 |
3, |
| 46 |
false, |
| 47 |
4, |
| 48 |
false |
| 49 |
); |
| 50 |
$this->assertSame( |
| 51 |
[ |
| 52 |
'foobar' => [ |
| 53 |
'alert' => [ 'count' => '3', 'ts' => '00000000000000' ], |
| 54 |
'message' => [ 'count' => '4', 'ts' => '00000000000000' ], |
| 55 |
] |
| 56 |
], |
| 57 |
$unread->getUnreadCounts() |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
protected function mockDbFactory( $db ) { |
| 67 |
$dbFactory = $this->createMock( DbFactory::class ); |
| 68 |
$dbFactory->expects( $this->any() ) |
| 69 |
->method( 'getSharedDb' ) |
| 70 |
->willReturn( $db ); |
| 71 |
|
| 72 |
return $dbFactory; |
| 73 |
} |
| 74 |
} |