8 class ApiPageSetTest
extends ApiTestCase
{
9 public static function provideRedirectMergePolicy() {
11 'By default nothing is merged' => [
16 'A simple merge policy adds the redirect data in' => [
17 function( $current, $new ) {
18 if ( !isset( $current['index'] ) ||
$new['index'] < $current['index'] ) {
19 $current['index'] = $new['index'];
29 * @dataProvider provideRedirectMergePolicy
31 public function testRedirectMergePolicyWithArrayResult( $mergePolicy, $expect ) {
32 list( $target, $pageSet ) = $this->createPageSetWithRedirect();
33 $pageSet->setRedirectMergePolicy( $mergePolicy );
35 $target->getArticleID() => []
37 $pageSet->populateGeneratorData( $result );
38 $this->assertEquals( $expect, $result[$target->getArticleID()] );
42 * @dataProvider provideRedirectMergePolicy
44 public function testRedirectMergePolicyWithApiResult( $mergePolicy, $expect ) {
45 list( $target, $pageSet ) = $this->createPageSetWithRedirect();
46 $pageSet->setRedirectMergePolicy( $mergePolicy );
47 $result = new ApiResult( false );
48 $result->addValue( null, 'pages', [
49 $target->getArticleID() => []
51 $pageSet->populateGeneratorData( $result, [ 'pages' ] );
54 $result->getResultData( [ 'pages', $target->getArticleID() ] )
58 protected function createPageSetWithRedirect() {
59 $target = Title
::makeTitle( NS_MAIN
, 'UTRedirectTarget' );
60 $sourceA = Title
::makeTitle( NS_MAIN
, 'UTRedirectSourceA' );
61 $sourceB = Title
::makeTitle( NS_MAIN
, 'UTRedirectSourceB' );
62 self
::editPage( 'UTRedirectTarget', 'api page set test' );
63 self
::editPage( 'UTRedirectSourceA', '#REDIRECT [[UTRedirectTarget]]' );
64 self
::editPage( 'UTRedirectSourceB', '#REDIRECT [[UTRedirectTarget]]' );
66 $request = new FauxRequest( [ 'redirects' => 1 ] );
67 $context = new RequestContext();
68 $context->setRequest( $request );
69 $main = new ApiMain( $context );
70 $pageSet = new ApiPageSet( $main );
72 $pageSet->setGeneratorData( $sourceA, [ 'index' => 1 ] );
73 $pageSet->setGeneratorData( $sourceB, [ 'index' => 3 ] );
74 $pageSet->populateFromTitles( [ $sourceA, $sourceB ] );
76 return [ $target, $pageSet ];