mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 07:26:29 +00:00
b3c07eedeb
Target page entries used to exist for each user that was notified for an event. They were removed as the notifications were marked as read. Now they remain so that the association between pages and events can be used for moderation regardless of the notifications read status. This patch removes everything about echo_target_page.etp_user from sql and php code. Bug: T143959 Change-Id: Ib57510e6b0e9202a7e035f8ea59955dca8a0b24a
105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
<?php
|
|
|
|
class EchoTargetPageMapperTest extends MediaWikiTestCase {
|
|
|
|
public function provideDataTestInsert() {
|
|
return array(
|
|
array(
|
|
'successful insert with next sequence = 1',
|
|
array( 'nextSequenceValue' => 1, 'insert' => true, 'insertId' => 2 ),
|
|
1
|
|
),
|
|
array(
|
|
'successful insert with insert id = 2',
|
|
array( 'nextSequenceValue' => null, 'insert' => true, 'insertId' => 2 ),
|
|
2
|
|
),
|
|
array(
|
|
'unsuccessful insert',
|
|
array( 'nextSequenceValue' => null, 'insert' => false, 'insertId' => 2 ),
|
|
false
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @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' )
|
|
->will( $this->returnValue( array() ) );
|
|
$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 ) );
|
|
|
|
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 ) ) );
|
|
|
|
return $dbFactory;
|
|
}
|
|
|
|
/**
|
|
* Mock object of DatabaseMysql ( DatabaseBase )
|
|
*/
|
|
protected function mockDb( array $dbResult ) {
|
|
$dbResult += array(
|
|
'nextSequenceValue' => '',
|
|
'insert' => '',
|
|
'insertId' => '',
|
|
'select' => '',
|
|
'delete' => ''
|
|
);
|
|
$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'] ) );
|
|
|
|
return $db;
|
|
}
|
|
|
|
}
|