2014-08-18 22:49:26 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
2019-10-23 10:23:09 +00:00
|
|
|
* @covers \EchoNotification
|
2018-01-24 00:31:53 +00:00
|
|
|
*/
|
2014-08-18 22:49:26 +00:00
|
|
|
class EchoNotificationTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function testNewFromRow() {
|
|
|
|
$row = $this->mockNotificationRow() + $this->mockEventRow();
|
|
|
|
|
|
|
|
$notif = EchoNotification::newFromRow( (object)$row );
|
2019-02-19 10:35:54 +00:00
|
|
|
$this->assertInstanceOf( EchoNotification::class, $notif );
|
2014-08-18 22:49:26 +00:00
|
|
|
// getReadTimestamp() should return null
|
|
|
|
$this->assertNull( $notif->getReadTimestamp() );
|
|
|
|
$this->assertEquals(
|
|
|
|
$notif->getTimestamp(),
|
|
|
|
wfTimestamp( TS_MW, $row['notification_timestamp'] )
|
|
|
|
);
|
2019-02-19 10:35:54 +00:00
|
|
|
$this->assertInstanceOf( EchoEvent::class, $notif->getEvent() );
|
2015-03-16 15:47:13 +00:00
|
|
|
$this->assertNull( $notif->getTargetPages() );
|
2014-08-18 22:49:26 +00:00
|
|
|
|
|
|
|
// Provide a read timestamp
|
|
|
|
$row['notification_read_timestamp'] = time() + 1000;
|
|
|
|
$notif = EchoNotification::newFromRow( (object)$row );
|
|
|
|
// getReadTimestamp() should return the timestamp in MW format
|
|
|
|
$this->assertEquals(
|
|
|
|
$notif->getReadTimestamp(),
|
|
|
|
wfTimestamp( TS_MW, $row['notification_read_timestamp'] )
|
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$notif = EchoNotification::newFromRow( (object)$row, [
|
2015-03-16 15:47:13 +00:00
|
|
|
EchoTargetPage::newFromRow( (object)$this->mockTargetPageRow() )
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2018-06-17 16:59:03 +00:00
|
|
|
$this->assertNotEmpty( $notif->getTargetPages() );
|
2015-03-16 15:47:13 +00:00
|
|
|
foreach ( $notif->getTargetPages() as $targetPage ) {
|
2019-02-19 10:35:54 +00:00
|
|
|
$this->assertInstanceOf( EchoTargetPage::class, $targetPage );
|
2015-03-16 15:47:13 +00:00
|
|
|
}
|
2014-08-18 22:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewFromRowWithException() {
|
|
|
|
$row = $this->mockNotificationRow();
|
|
|
|
// Provide an invalid event id
|
|
|
|
$row['notification_event'] = -1;
|
2019-02-19 10:39:13 +00:00
|
|
|
$this->expectException( MWException::class );
|
|
|
|
EchoNotification::newFromRow( (object)$row );
|
2014-08-18 22:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock a notification row from database
|
|
|
|
*/
|
|
|
|
protected function mockNotificationRow() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2014-08-18 22:49:26 +00:00
|
|
|
'notification_user' => 1,
|
|
|
|
'notification_event' => 1,
|
|
|
|
'notification_timestamp' => time(),
|
|
|
|
'notification_read_timestamp' => '',
|
|
|
|
'notification_bundle_hash' => 'testhash',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-18 22:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock an event row from database
|
|
|
|
*/
|
|
|
|
protected function mockEventRow() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2014-08-18 22:49:26 +00:00
|
|
|
'event_id' => 1,
|
|
|
|
'event_type' => 'test_event',
|
|
|
|
'event_variant' => '',
|
|
|
|
'event_extra' => '',
|
|
|
|
'event_page_id' => '',
|
|
|
|
'event_agent_id' => '',
|
2016-03-04 19:23:02 +00:00
|
|
|
'event_agent_ip' => '',
|
|
|
|
'event_deleted' => 0,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-18 22:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock a target page row
|
|
|
|
*/
|
|
|
|
protected function mockTargetPageRow() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2014-08-18 22:49:26 +00:00
|
|
|
'etp_page' => 2,
|
|
|
|
'etp_event' => 1
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-18 22:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|