summaryrefslogtreecommitdiff
blob: 29670ff761abb7401855be97462f48393f4361e2 (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
89
90
91
92
93
94
95
96
97
98
99
<?php

class EchoTargetPageTest extends MediaWikiTestCase {

	public function testCreate() {
		$this->assertNull(
			EchoTargetPage::create(
				User::newFromId( 0 ),
				$this->mockTitle( 1 ),
				$this->mockEchoEvent()
			)
		);

		$this->assertNull(
			EchoTargetPage::create(
				User::newFromId( 1 ),
				$this->mockTitle( 0 ),
				$this->mockEchoEvent()
			)
		);

		$this->assertNull(
			EchoTargetPage::create(
				User::newFromId( 0 ),
				$this->mockTitle( 0 ),
				$this->mockEchoEvent()
			)
		);

		$this->assertInstanceOf(
			'EchoTargetPage',
			EchoTargetPage::create(
				User::newFromId( 1 ),
				$this->mockTitle( 1 ),
				$this->mockEchoEvent()
			)
		);
	}

	public function testNewFromRow() {
		$row = (object) array (
			'etp_user' => 1,
			'etp_page' => 2,
			'etp_event' => 3
		);
		$obj = EchoTargetPage::newFromRow( $row );
		$this->assertInstanceOf( 'EchoTargetPage', $obj );
		return $obj;
	}

	/**
	 * @expectedException MWException
	 */
	public function testNewFromRowWithException() {
		$row = (object) array (
			'etp_page' => 2,
			'etp_event' => 3
		);
		$this->assertInstanceOf( 'EchoTargetPage', EchoTargetPage::newFromRow( $row ) );
	}

	/**
	 * @depends testNewFromRow
	 */
	public function testToDbArray( $obj ) {
		$row = $obj->toDbArray();
		$this->assertTrue( is_array( $row ) );
		$this->assertArrayHasKey( 'etp_user', $row );
		$this->assertArrayHasKey( 'etp_page', $row );
		$this->assertArrayHasKey( 'etp_event', $row );
	}

	/**
	 * Mock object of Title
	 */
	protected function mockTitle( $pageId ) {
		$event = $this->getMockBuilder( 'Title' )
			->disableOriginalConstructor()
			->getMock();
		$event->expects( $this->any() )
			->method( 'getArticleID' )
			->will( $this->returnValue( $pageId ) );
		return $event;
	}

	/**
	 * Mock object of EchoEvent
	 */
	protected function mockEchoEvent( $eventId = 1 ) {
		$event = $this->getMockBuilder( 'EchoEvent' )
			->disableOriginalConstructor()
			->getMock();
		$event->expects( $this->any() )
			->method( 'getId' )
			->will( $this->returnValue( $eventId ) );
		return $event;
	}

}