createMock( WikiPage::class ); $contextMock = $this->getMockBuilder( RequestContext::class ) ->disableOriginalConstructor() ->onlyMethods( [ 'getRequest', 'getWikiPage', 'getTitle' ] ) ->getMock(); $contextMock->method( 'getRequest' )->willReturn( new FauxRequest( [] ) ); $title = Title::makeTitle( NS_MAIN, 'HistoryPagerTest' ); $contextMock->method( 'getTitle' )->willReturn( $title ); $contextMock->method( 'getWikiPage' )->willReturn( $wikiPageMock ); $articleMock = $this->getMockBuilder( Article::class ) ->disableOriginalConstructor() ->onlyMethods( [ 'getContext' ] ) ->getMock(); $articleMock->method( 'getContext' )->willReturn( $contextMock ); $actionMock = $this->getMockBuilder( HistoryAction::class ) ->setConstructorArgs( [ $articleMock, $contextMock ] ) ->getMock(); $actionMock->method( 'getArticle' )->willReturn( $articleMock ); $actionMock->message = [ 'cur' => 'cur', 'last' => 'last', 'tooltip-cur' => '', 'tooltip-last' => '', ]; $outputMock = $this->getMockBuilder( OutputPage::class ) ->disableOriginalConstructor() ->onlyMethods( [ 'wrapWikiMsg' ] ) ->getMock(); $pager = $this->getMockBuilder( HistoryPager::class ) ->onlyMethods( [ 'reallyDoQuery', 'doBatchLookups', 'getOutput' ] ) ->setConstructorArgs( [ $actionMock ] ) ->getMock(); $pager->method( 'getOutput' )->willReturn( $outputMock ); $pager->method( 'reallyDoQuery' )->willReturn( new FakeResultWrapper( $results ) ); // make all the methods in our mock public $pager = TestingAccessWrapper::newFromObject( $pager ); // and update the private properties... $pager->formattedComments = array_map( static function ( $result ) { return 'dummy comment'; }, $results ); $pager->revisions = array_map( static function ( $result ) { $title = Title::makeTitle( NS_MAIN, 'HistoryPagerTest' ); $r = new MutableRevisionRecord( $title ); $r->setId( $result[ 'rev_id' ] ); return $r; }, $results ); return $pager; } /** * @covers HistoryPager::getBody */ public function testGetBodyEmpty() { $pager = $this->getHistoryPager( [] ); $html = $pager->getBody(); $this->assertStringContainsString( 'No matching revisions were found.', $html ); $this->assertStringNotContainsString( 'getHistoryPager( [ [ 'rev_page' => 'title', 'ts_tags' => '', 'rev_deleted' => false, 'rev_minor_edit' => false, 'rev_parent_id' => 1, 'user_name' => 'Jdlrobson', 'rev_id' => 2, 'rev_comment_data' => '{}', 'rev_comment_cid' => '1', 'rev_comment_text' => 'Created page', 'rev_timestamp' => '20220101001122', ] ] ); $html = $pager->getBody(); $this->assertStringContainsString( ' 'title', 'rev_deleted' => false, 'rev_minor_edit' => false, 'ts_tags' => '', 'rev_parent_id' => 1, 'user_name' => 'Jdlrobson', 'rev_comment_data' => '{}', 'rev_comment_cid' => '1', 'rev_comment_text' => 'Fixed typo', ]; $pager = $this->getHistoryPager( [ $pagerData + [ 'rev_id' => 3, 'rev_timestamp' => '20220301001122', ], $pagerData + [ 'rev_id' => 2, 'rev_timestamp' => '20220101001122', ], ] ); $html = preg_replace( "/\n+/", '', $pager->getBody() ); $firstHeader = '

1 March 2022

' . '