2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
|
|
|
* @covers EchoTargetPageMapper
|
|
|
|
*/
|
2014-08-06 00:16:10 +00:00
|
|
|
class EchoTargetPageMapperTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function provideDataTestInsert() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
[
|
2014-08-06 00:16:10 +00:00
|
|
|
'successful insert with next sequence = 1',
|
2017-09-06 16:47:22 +00:00
|
|
|
[ 'insert' => true, 'insertId' => 2 ],
|
2014-08-06 00:16:10 +00:00
|
|
|
1
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
[
|
2014-08-06 00:16:10 +00:00
|
|
|
'successful insert with insert id = 2',
|
2017-09-06 16:47:22 +00:00
|
|
|
[ 'insert' => true, 'insertId' => 2 ],
|
2014-08-06 00:16:10 +00:00
|
|
|
2
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
];
|
2014-08-06 00:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideDataTestInsert
|
|
|
|
*/
|
|
|
|
public function testInsert( $message, $dbResult, $result ) {
|
|
|
|
$target = $this->mockEchoTargetPage();
|
|
|
|
$targetMapper = new EchoTargetPageMapper( $this->mockMWEchoDbFactory( $dbResult ) );
|
|
|
|
$this->assertEquals( $result, $targetMapper->insert( $target ), $message );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock object of EchoTargetPage
|
|
|
|
*/
|
|
|
|
protected function mockEchoTargetPage() {
|
2018-04-12 23:21:09 +00:00
|
|
|
$target = $this->getMockBuilder( EchoTargetPage::class )
|
2014-08-06 00:16:10 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$target->expects( $this->any() )
|
|
|
|
->method( 'toDbArray' )
|
2016-12-05 18:51:07 +00:00
|
|
|
->will( $this->returnValue( [] ) );
|
2014-08-06 00:16:10 +00:00
|
|
|
$target->expects( $this->any() )
|
|
|
|
->method( 'getPageId' )
|
|
|
|
->will( $this->returnValue( 2 ) );
|
|
|
|
$target->expects( $this->any() )
|
|
|
|
->method( 'getEventId' )
|
|
|
|
->will( $this->returnValue( 3 ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock object of MWEchoDbFactory
|
|
|
|
*/
|
|
|
|
protected function mockMWEchoDbFactory( $dbResult ) {
|
2019-02-19 10:35:54 +00:00
|
|
|
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
|
2014-08-06 00:16:10 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$dbFactory->expects( $this->any() )
|
|
|
|
->method( 'getEchoDb' )
|
|
|
|
->will( $this->returnValue( $this->mockDb( $dbResult ) ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $dbFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-16 18:58:52 +00:00
|
|
|
* Returns a mock database object
|
|
|
|
* @return \Wikimedia\Rdbms\IDatabase
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
protected function mockDb( array $dbResult ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$dbResult += [
|
2014-08-06 00:16:10 +00:00
|
|
|
'insert' => '',
|
|
|
|
'insertId' => '',
|
|
|
|
'select' => '',
|
|
|
|
'delete' => ''
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2019-02-19 10:35:54 +00:00
|
|
|
$db = $this->getMockBuilder( DatabaseMysqli::class )
|
2014-08-06 00:16:10 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$db->expects( $this->any() )
|
|
|
|
->method( 'insert' )
|
|
|
|
->will( $this->returnValue( $dbResult['insert'] ) );
|
|
|
|
$db->expects( $this->any() )
|
|
|
|
->method( 'insertId' )
|
|
|
|
->will( $this->returnValue( $dbResult['insertId'] ) );
|
|
|
|
$db->expects( $this->any() )
|
|
|
|
->method( 'select' )
|
|
|
|
->will( $this->returnValue( $dbResult['select'] ) );
|
|
|
|
$db->expects( $this->any() )
|
|
|
|
->method( 'delete' )
|
|
|
|
->will( $this->returnValue( $dbResult['delete'] ) );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|