2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-22 15:31:00 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Test\Unit;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
|
|
|
use MediaWiki\Extension\Notifications\Model\TargetPage;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2024-02-22 15:31:00 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
2022-11-02 21:34:17 +00:00
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\Model\TargetPage
|
2018-01-24 00:31:53 +00:00
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
class TargetPageTest extends MediaWikiUnitTestCase {
|
2014-08-06 00:16:10 +00:00
|
|
|
|
|
|
|
public function testCreate() {
|
|
|
|
$this->assertNull(
|
2022-11-02 21:34:17 +00:00
|
|
|
TargetPage::create(
|
2014-08-06 00:16:10 +00:00
|
|
|
$this->mockTitle( 0 ),
|
|
|
|
$this->mockEchoEvent()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2022-11-02 21:34:17 +00:00
|
|
|
TargetPage::class,
|
|
|
|
TargetPage::create(
|
2014-08-06 00:16:10 +00:00
|
|
|
$this->mockTitle( 1 ),
|
|
|
|
$this->mockEchoEvent()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-19 10:40:12 +00:00
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* @return TargetPage
|
2019-02-19 10:40:12 +00:00
|
|
|
*/
|
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
|
|
|
];
|
2022-11-02 21:34:17 +00:00
|
|
|
$obj = TargetPage::newFromRow( $row );
|
|
|
|
$this->assertInstanceOf( TargetPage::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
|
|
|
];
|
2023-06-09 00:21:09 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
2022-11-02 21:34:17 +00:00
|
|
|
TargetPage::newFromRow( $row );
|
2014-08-06 00:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testNewFromRow
|
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
public function testToDbArray( TargetPage $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
|
2022-11-02 21:34:17 +00:00
|
|
|
* @return Event
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
protected function mockEchoEvent( $eventId = 1 ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'getId' )
|
|
|
|
->willReturn( $eventId );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|