2013-05-09 18:50:05 +00:00
|
|
|
<?php
|
|
|
|
|
2019-10-23 02:31:36 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2014-07-25 20:19:15 +00:00
|
|
|
/**
|
|
|
|
* @group Echo
|
2019-10-23 10:23:09 +00:00
|
|
|
* @covers \EchoSuppressionRowUpdateGenerator
|
2014-07-25 20:19:15 +00:00
|
|
|
*/
|
2013-05-09 18:50:05 +00:00
|
|
|
class SuppressionMaintenanceTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public static function provider_updateRow() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$input = [
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_id' => 2,
|
|
|
|
'event_type' => 'mention',
|
|
|
|
'event_variant' => null,
|
|
|
|
'event_agent_id' => 3,
|
|
|
|
'event_agent_ip' => null,
|
2015-03-23 22:46:40 +00:00
|
|
|
'event_page_title' => '',
|
|
|
|
'event_page_namespace' => 0,
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_extra' => null,
|
|
|
|
'event_extra' => null,
|
|
|
|
'event_page_id' => null,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
[ 'Unrelated row must result in no update', [], $input ],
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2013-05-09 18:50:05 +00:00
|
|
|
'Page title and namespace for non-existant page must move into event_extra',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ // expected update
|
|
|
|
'event_extra' => serialize( [
|
2013-05-09 18:50:05 +00:00
|
|
|
'page_title' => 'Yabba Dabba Do',
|
|
|
|
'page_namespace' => NS_MAIN
|
2016-12-05 18:51:07 +00:00
|
|
|
] ),
|
|
|
|
],
|
|
|
|
[ // input row
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_title' => 'Yabba Dabba Do',
|
|
|
|
'event_page_namespace' => NS_MAIN,
|
2016-12-05 18:51:07 +00:00
|
|
|
] + $input,
|
|
|
|
],
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2013-05-09 18:50:05 +00:00
|
|
|
'Page title and namespace for existing page must be result in update to event_page_id',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ // expected update
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_id' => 42,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
[ // input row
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_title' => 'Mount Rushmore',
|
|
|
|
'event_page_namespace' => NS_MAIN,
|
2016-12-05 18:51:07 +00:00
|
|
|
] + $input,
|
2013-05-09 18:50:05 +00:00
|
|
|
self::attachTitleFor( 42, 'Mount Rushmore', NS_MAIN )
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2013-05-09 18:50:05 +00:00
|
|
|
'When updating non-existant page must keep old extra data',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ // expected update
|
|
|
|
'event_extra' => serialize( [
|
2013-05-09 18:50:05 +00:00
|
|
|
'foo' => 'bar',
|
|
|
|
'page_title' => 'Yabba Dabba Do',
|
|
|
|
'page_namespace' => NS_MAIN
|
2016-12-05 18:51:07 +00:00
|
|
|
] ),
|
|
|
|
],
|
|
|
|
[ // input row
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_title' => 'Yabba Dabba Do',
|
|
|
|
'event_page_namespace' => NS_MAIN,
|
2016-12-05 18:51:07 +00:00
|
|
|
'event_extra' => serialize( [ 'foo' => 'bar' ] ),
|
|
|
|
] + $input,
|
|
|
|
],
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2013-05-09 18:50:05 +00:00
|
|
|
'Must update link-from-title/namespace to link-from-page-id for page-linked events',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ // expected update
|
|
|
|
'event_extra' => serialize( [ 'link-from-page-id' => 99 ] ),
|
|
|
|
],
|
|
|
|
[ // input row
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_type' => 'page-linked',
|
2016-12-05 18:51:07 +00:00
|
|
|
'event_extra' => serialize( [
|
2013-05-09 18:50:05 +00:00
|
|
|
'link-from-title' => 'Horse',
|
|
|
|
'link-from-namespace' => NS_USER_TALK
|
2016-12-05 18:51:07 +00:00
|
|
|
] ),
|
|
|
|
] + $input,
|
2013-05-09 18:50:05 +00:00
|
|
|
self::attachTitleFor( 99, 'Horse', NS_USER_TALK )
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2013-05-09 18:50:05 +00:00
|
|
|
'Must perform both generic update and page-linked update at same time',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ // expected update
|
|
|
|
'event_extra' => serialize( [ 'link-from-page-id' => 8675309 ] ),
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_id' => 8675309,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
[ // input row
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_type' => 'page-linked',
|
2016-12-05 18:51:07 +00:00
|
|
|
'event_extra' => serialize( [
|
2013-05-09 18:50:05 +00:00
|
|
|
'link-from-title' => 'Jenny',
|
|
|
|
'link-from-namespace' => NS_MAIN,
|
2016-12-05 18:51:07 +00:00
|
|
|
] ),
|
2013-05-09 18:50:05 +00:00
|
|
|
'event_page_title' => 'Jenny',
|
|
|
|
'event_page_namespace' => NS_MAIN,
|
2016-12-05 18:51:07 +00:00
|
|
|
] + $input,
|
2013-05-09 18:50:05 +00:00
|
|
|
self::attachTitleFor( 8675309, 'Jenny', NS_MAIN ),
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
];
|
2013-05-09 18:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static function attachTitleFor( $id, $providedText, $providedNamespace ) {
|
2019-10-23 02:31:36 +00:00
|
|
|
return function (
|
|
|
|
TestCase $test,
|
|
|
|
EchoSuppressionRowUpdateGenerator $gen
|
|
|
|
) use ( $id, $providedText, $providedNamespace ) {
|
|
|
|
$title = $test->createMock( Title::class );
|
2013-05-09 18:50:05 +00:00
|
|
|
$title->expects( $test->any() )
|
|
|
|
->method( 'getArticleId' )
|
|
|
|
->will( $test->returnValue( $id ) );
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$titles = [ $providedNamespace => [ $providedText => $title ] ];
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2016-06-06 21:02:03 +00:00
|
|
|
$gen->setNewTitleFromNsAndText( function ( $namespace, $text ) use ( $titles ) {
|
2019-05-07 16:52:01 +00:00
|
|
|
return $titles[$namespace][$text] ?? Title::makeTitleSafe( $namespace, $text );
|
2013-05-09 18:50:05 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provider_updateRow
|
|
|
|
*/
|
2019-10-23 02:31:36 +00:00
|
|
|
public function testUpdateRow( $message, array $expected, array $input, callable $callable = null ) {
|
2013-05-09 18:50:05 +00:00
|
|
|
$gen = new EchoSuppressionRowUpdateGenerator;
|
|
|
|
if ( $callable ) {
|
|
|
|
call_user_func( $callable, $this, $gen );
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
$update = $gen->update( (object)$input );
|
2013-05-09 18:50:05 +00:00
|
|
|
$this->assertEquals( $expected, $update, $message );
|
|
|
|
}
|
|
|
|
}
|