8 class ApiPageSetTest
extends ApiTestCase
{
9 public static function provideRedirectMergePolicy() {
11 'By default nothing is merged' => array(
16 'A simple merge policy adds the redirect data in' => array(
17 function( $current, $new ) {
18 if ( !isset( $current['index'] ) ||
$new['index'] < $current['index'] ) {
19 $current['index'] = $new['index'];
23 array( 'index' => 1 ),
29 * @dataProvider provideRedirectMergePolicy
31 public function testRedirectMergePolicyWithArrayResult( $mergePolicy, $expect ) {
32 list( $target, $pageSet ) = $this->createPageSetWithRedirect();
33 $pageSet->setRedirectMergePolicy( $mergePolicy );
35 $target->getArticleID() => array()
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', array(
49 $target->getArticleID() => array()
51 $pageSet->populateGeneratorData( $result, array( 'pages' ) );
54 $result->getResultData( array( '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( array( 'redirects' => 1 ) );
67 $context = new RequestContext();
68 $context->setRequest( $request );
69 $main = new ApiMain( $context );
70 $pageSet = new ApiPageSet( $main );
72 $pageSet->setGeneratorData( $sourceA, array( 'index' => 1 ) );
73 $pageSet->setGeneratorData( $sourceB, array( 'index' => 3 ) );
74 $pageSet->populateFromTitles( array( $sourceA, $sourceB ) );
76 return array( $target, $pageSet );