mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-04 12:18:30 +00:00
db79d76d83
Notably: any() is the default anyway. It doesn't really make the tests more specific or better readable when we repeat it all the time. Change-Id: I56d201bfce454587b00015b7208f313dd8ed9624
87 lines
1.7 KiB
PHP
87 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers \EchoTargetPage
|
|
*/
|
|
class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
|
|
|
public function testCreate() {
|
|
$this->assertNull(
|
|
EchoTargetPage::create(
|
|
$this->mockTitle( 0 ),
|
|
$this->mockEchoEvent()
|
|
)
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
|
EchoTargetPage::class,
|
|
EchoTargetPage::create(
|
|
$this->mockTitle( 1 ),
|
|
$this->mockEchoEvent()
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return EchoTargetPage
|
|
*/
|
|
public function testNewFromRow() {
|
|
$row = (object)[
|
|
'etp_page' => 2,
|
|
'etp_event' => 3
|
|
];
|
|
$obj = EchoTargetPage::newFromRow( $row );
|
|
$this->assertInstanceOf( EchoTargetPage::class, $obj );
|
|
|
|
return $obj;
|
|
}
|
|
|
|
public function testNewFromRowWithException() {
|
|
$row = (object)[
|
|
'etp_event' => 3
|
|
];
|
|
$this->expectException( MWException::class );
|
|
EchoTargetPage::newFromRow( $row );
|
|
}
|
|
|
|
/**
|
|
* @depends testNewFromRow
|
|
*/
|
|
public function testToDbArray( EchoTargetPage $obj ) {
|
|
$row = $obj->toDbArray();
|
|
$this->assertIsArray( $row );
|
|
|
|
// 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 );
|
|
|
|
$this->assertArrayHasKey( 'etp_page', $row );
|
|
$this->assertArrayHasKey( 'etp_event', $row );
|
|
}
|
|
|
|
/**
|
|
* @param int $pageId
|
|
* @return Title
|
|
*/
|
|
protected function mockTitle( $pageId ) {
|
|
$event = $this->createMock( Title::class );
|
|
$event->method( 'getArticleID' )
|
|
->willReturn( $pageId );
|
|
|
|
return $event;
|
|
}
|
|
|
|
/**
|
|
* @param int $eventId
|
|
* @return EchoEvent
|
|
*/
|
|
protected function mockEchoEvent( $eventId = 1 ) {
|
|
$event = $this->createMock( EchoEvent::class );
|
|
$event->method( 'getId' )
|
|
->willReturn( $eventId );
|
|
|
|
return $event;
|
|
}
|
|
|
|
}
|