2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
2019-10-23 10:23:09 +00:00
|
|
|
* @covers \EchoTargetPage
|
2018-01-24 00:31:53 +00:00
|
|
|
*/
|
2019-07-10 20:47:28 +00:00
|
|
|
class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
2014-08-06 00:16:10 +00:00
|
|
|
|
|
|
|
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();
|
2020-08-10 10:54:10 +00:00
|
|
|
$this->assertIsArray( $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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-23 11:54:27 +00:00
|
|
|
* @param int $pageId
|
2019-02-19 10:40:12 +00:00
|
|
|
* @return Title
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
protected function mockTitle( $pageId ) {
|
2022-09-29 13:41:35 +00:00
|
|
|
$event = $this->createMock( Title::class );
|
|
|
|
$event->method( 'getArticleID' )
|
|
|
|
->willReturn( $pageId );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-23 11:54:27 +00:00
|
|
|
* @param int $eventId
|
2019-02-19 10:40:12 +00:00
|
|
|
* @return EchoEvent
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
protected function mockEchoEvent( $eventId = 1 ) {
|
2022-09-29 13:41:35 +00:00
|
|
|
$event = $this->createMock( EchoEvent::class );
|
|
|
|
$event->method( 'getId' )
|
|
|
|
->willReturn( $eventId );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|