| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Test\Unit; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 7 |
use MediaWiki\Extension\Notifications\Model\TargetPage; |
| 8 |
use MediaWiki\Title\Title; |
| 9 |
use MediaWikiUnitTestCase; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class TargetPageTest extends MediaWikiUnitTestCase { |
| 15 |
|
| 16 |
public function testCreate() { |
| 17 |
$this->assertNull( |
| 18 |
TargetPage::create( |
| 19 |
$this->mockTitle( 0 ), |
| 20 |
$this->mockEchoEvent() |
| 21 |
) |
| 22 |
); |
| 23 |
|
| 24 |
$this->assertInstanceOf( |
| 25 |
TargetPage::class, |
| 26 |
TargetPage::create( |
| 27 |
$this->mockTitle( 1 ), |
| 28 |
$this->mockEchoEvent() |
| 29 |
) |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function testNewFromRow() { |
| 37 |
$row = (object)[ |
| 38 |
'etp_page' => 2, |
| 39 |
'etp_event' => 3 |
| 40 |
]; |
| 41 |
$obj = TargetPage::newFromRow( $row ); |
| 42 |
$this->assertInstanceOf( TargetPage::class, $obj ); |
| 43 |
|
| 44 |
return $obj; |
| 45 |
} |
| 46 |
|
| 47 |
public function testNewFromRowWithException() { |
| 48 |
$row = (object)[ |
| 49 |
'etp_event' => 3 |
| 50 |
]; |
| 51 |
$this->expectException( InvalidArgumentException::class ); |
| 52 |
TargetPage::newFromRow( $row ); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function testToDbArray( TargetPage $obj ) { |
| 59 |
$row = $obj->toDbArray(); |
| 60 |
$this->assertIsArray( $row ); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
$this->assertArrayNotHasKey( 'etp_user', $row ); |
| 65 |
|
| 66 |
$this->assertArrayHasKey( 'etp_page', $row ); |
| 67 |
$this->assertArrayHasKey( 'etp_event', $row ); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
protected function mockTitle( $pageId ) { |
| 75 |
$event = $this->createMock( Title::class ); |
| 76 |
$event->method( 'getArticleID' ) |
| 77 |
->willReturn( $pageId ); |
| 78 |
|
| 79 |
return $event; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
protected function mockEchoEvent( $eventId = 1 ) { |
| 87 |
$event = $this->createMock( Event::class ); |
| 88 |
$event->method( 'getId' ) |
| 89 |
->willReturn( $eventId ); |
| 90 |
|
| 91 |
return $event; |
| 92 |
} |
| 93 |
|
| 94 |
} |