mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-01 10:56:44 +00:00
b3c07eedeb
Target page entries used to exist for each user that was notified for an event. They were removed as the notifications were marked as read. Now they remain so that the association between pages and events can be used for moderation regardless of the notifications read status. This patch removes everything about echo_target_page.etp_user from sql and php code. Bug: T143959 Change-Id: Ib57510e6b0e9202a7e035f8ea59955dca8a0b24a
89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
<?php
|
|
|
|
class EchoNotificationTest extends MediaWikiTestCase {
|
|
|
|
public function testNewFromRow() {
|
|
$row = $this->mockNotificationRow() + $this->mockEventRow();
|
|
|
|
$notif = EchoNotification::newFromRow( (object)$row );
|
|
$this->assertInstanceOf( 'EchoNotification', $notif );
|
|
// getReadTimestamp() should return null
|
|
$this->assertNull( $notif->getReadTimestamp() );
|
|
$this->assertEquals(
|
|
$notif->getTimestamp(),
|
|
wfTimestamp( TS_MW, $row['notification_timestamp'] )
|
|
);
|
|
$this->assertInstanceOf( 'EchoEvent', $notif->getEvent() );
|
|
$this->assertNull( $notif->getTargetPages() );
|
|
|
|
// 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'] )
|
|
);
|
|
|
|
$notif = EchoNotification::newFromRow( (object)$row, array(
|
|
EchoTargetPage::newFromRow( (object)$this->mockTargetPageRow() )
|
|
) );
|
|
$this->assertGreaterThan( 0, count( $notif->getTargetPages() ) );
|
|
foreach ( $notif->getTargetPages() as $targetPage ) {
|
|
$this->assertInstanceOf( 'EchoTargetPage', $targetPage );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @expectedException MWException
|
|
*/
|
|
public function testNewFromRowWithException() {
|
|
$row = $this->mockNotificationRow();
|
|
// Provide an invalid event id
|
|
$row['notification_event'] = -1;
|
|
$noitf = EchoNotification::newFromRow( (object)$row );
|
|
}
|
|
|
|
/**
|
|
* Mock a notification row from database
|
|
*/
|
|
protected function mockNotificationRow() {
|
|
return array(
|
|
'notification_user' => 1,
|
|
'notification_event' => 1,
|
|
'notification_timestamp' => time(),
|
|
'notification_read_timestamp' => '',
|
|
'notification_bundle_base' => 1,
|
|
'notification_bundle_hash' => 'testhash',
|
|
'notification_bundle_display_hash' => 'testdisplayhash'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Mock an event row from database
|
|
*/
|
|
protected function mockEventRow() {
|
|
return array(
|
|
'event_id' => 1,
|
|
'event_type' => 'test_event',
|
|
'event_variant' => '',
|
|
'event_extra' => '',
|
|
'event_page_id' => '',
|
|
'event_agent_id' => '',
|
|
'event_agent_ip' => '',
|
|
'event_deleted' => 0,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Mock a target page row
|
|
*/
|
|
protected function mockTargetPageRow() {
|
|
return array(
|
|
'etp_page' => 2,
|
|
'etp_event' => 1
|
|
);
|
|
}
|
|
|
|
}
|