2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'nextSequenceValue' => 1, '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',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'nextSequenceValue' => null, '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
|
|
|
'unsuccessful insert',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'nextSequenceValue' => null, 'insert' => false, 'insertId' => 2 ],
|
2014-08-06 00:16:10 +00:00
|
|
|
false
|
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() {
|
|
|
|
$target = $this->getMockBuilder( 'EchoTargetPage' )
|
|
|
|
->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( 'getUser' )
|
|
|
|
->will( $this->returnValue( User::newFromId( 1 ) ) );
|
|
|
|
$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 ) {
|
|
|
|
$dbFactory = $this->getMockBuilder( 'MWEchoDbFactory' )
|
|
|
|
->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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock object of DatabaseMysql ( DatabaseBase )
|
|
|
|
*/
|
|
|
|
protected function mockDb( array $dbResult ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$dbResult += [
|
2014-08-06 00:16:10 +00:00
|
|
|
'nextSequenceValue' => '',
|
|
|
|
'insert' => '',
|
|
|
|
'insertId' => '',
|
|
|
|
'select' => '',
|
|
|
|
'delete' => ''
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-06 00:16:10 +00:00
|
|
|
$db = $this->getMockBuilder( 'DatabaseMysql' )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$db->expects( $this->any() )
|
|
|
|
->method( 'nextSequenceValue' )
|
|
|
|
->will( $this->returnValue( $dbResult['nextSequenceValue'] ) );
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|