2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
|
|
|
* @covers EchoTargetPage
|
|
|
|
*/
|
2014-08-06 00:16:10 +00:00
|
|
|
class EchoTargetPageTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function testCreate() {
|
|
|
|
$this->assertNull(
|
|
|
|
EchoTargetPage::create(
|
|
|
|
$this->mockTitle( 0 ),
|
|
|
|
$this->mockEchoEvent()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2019-02-19 10:35:54 +00:00
|
|
|
EchoTargetPage::class,
|
2014-08-06 00:16:10 +00:00
|
|
|
EchoTargetPage::create(
|
|
|
|
$this->mockTitle( 1 ),
|
|
|
|
$this->mockEchoEvent()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-19 10:40:12 +00:00
|
|
|
/**
|
|
|
|
* @return EchoTargetPage
|
|
|
|
*/
|
2014-08-06 00:16:10 +00:00
|
|
|
public function testNewFromRow() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$row = (object)[
|
2014-08-06 00:16:10 +00:00
|
|
|
'etp_page' => 2,
|
|
|
|
'etp_event' => 3
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-06 00:16:10 +00:00
|
|
|
$obj = EchoTargetPage::newFromRow( $row );
|
2019-02-19 10:35:54 +00:00
|
|
|
$this->assertInstanceOf( EchoTargetPage::class, $obj );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewFromRowWithException() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$row = (object)[
|
2014-08-06 00:16:10 +00:00
|
|
|
'etp_event' => 3
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2019-02-19 10:39:13 +00:00
|
|
|
$this->expectException( MWException::class );
|
|
|
|
EchoTargetPage::newFromRow( $row );
|
2014-08-06 00:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testNewFromRow
|
|
|
|
*/
|
2019-02-19 10:40:12 +00:00
|
|
|
public function testToDbArray( EchoTargetPage $obj ) {
|
2014-08-06 00:16:10 +00:00
|
|
|
$row = $obj->toDbArray();
|
|
|
|
$this->assertTrue( is_array( $row ) );
|
2016-09-07 17:38:12 +00:00
|
|
|
|
|
|
|
// Not very common to assert that a field does _not_ exist
|
|
|
|
// but since we are explicitly removing it, it seems to make sense.
|
|
|
|
$this->assertArrayNotHasKey( 'etp_user', $row );
|
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
$this->assertArrayHasKey( 'etp_page', $row );
|
|
|
|
$this->assertArrayHasKey( 'etp_event', $row );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 10:40:12 +00:00
|
|
|
* @return Title
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
protected function mockTitle( $pageId ) {
|
2019-02-19 10:35:54 +00:00
|
|
|
$event = $this->getMockBuilder( Title::class )
|
2014-08-06 00:16:10 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$event->expects( $this->any() )
|
|
|
|
->method( 'getArticleID' )
|
|
|
|
->will( $this->returnValue( $pageId ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 10:40:12 +00:00
|
|
|
* @return EchoEvent
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
protected function mockEchoEvent( $eventId = 1 ) {
|
2019-02-19 10:35:54 +00:00
|
|
|
$event = $this->getMockBuilder( EchoEvent::class )
|
2014-08-06 00:16:10 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$event->expects( $this->any() )
|
|
|
|
->method( 'getId' )
|
|
|
|
->will( $this->returnValue( $eventId ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|