2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EchoTargetPageTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function testCreate() {
|
|
|
|
$this->assertNull(
|
|
|
|
EchoTargetPage::create(
|
|
|
|
$this->mockTitle( 0 ),
|
|
|
|
$this->mockEchoEvent()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
'EchoTargetPage',
|
|
|
|
EchoTargetPage::create(
|
|
|
|
$this->mockTitle( 1 ),
|
|
|
|
$this->mockEchoEvent()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
$this->assertInstanceOf( 'EchoTargetPage', $obj );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException MWException
|
|
|
|
*/
|
|
|
|
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
|
|
|
];
|
2014-08-06 00:16:10 +00:00
|
|
|
$this->assertInstanceOf( 'EchoTargetPage', EchoTargetPage::newFromRow( $row ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testNewFromRow
|
|
|
|
*/
|
|
|
|
public function testToDbArray( $obj ) {
|
|
|
|
$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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock object of Title
|
|
|
|
*/
|
|
|
|
protected function mockTitle( $pageId ) {
|
|
|
|
$event = $this->getMockBuilder( 'Title' )
|
|
|
|
->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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|