summaryrefslogtreecommitdiff
blob: d6d45c3eec9f1a2522f02ced859b4a748e4b8db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?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, [
			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 [
			'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 [
			'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 [
			'etp_page' => 2,
			'etp_event' => 1
		];
	}

}