SubPageListTest::newSubPageList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Unit\SubPageList\Lister;
4
5
use ParamProcessor\ProcessedParam;
6
use ParamProcessor\ProcessingResult;
7
use PHPUnit\Framework\TestCase;
8
use SubPageList\Lister\Page;
9
use SubPageList\Lister\SubPageList;
10
use SubPageList\TitleFactory;
11
12
/**
13
 * @covers \SubPageList\Lister\SubPageList
14
 *
15
 * @group SubPageList
16
 *
17
 * @licence GNU GPL v2+
18
 * @author Jeroen De Dauw < [email protected] >
19
 */
20
class SubPageListTest extends TestCase {
21
22
	public function testSubPageListHook() {
23
		$titleText = 'FooBarPage';
24
		$renderResult = 'ohi there!';
25
26
		$subPageList = $this->newSubPageList( $titleText, $renderResult );
27
28
		$renderedList = $this->getRenderedList( $subPageList, $titleText );
29
30
		$this->assertInternalType( 'string', $renderedList );
31
		$this->assertEquals( $renderResult, $renderedList );
32
	}
33
34
	private function newSubPageList( $titleText, $renderResult ) {
35
		$title = \Title::newFromText( $titleText );
36
		$page = new Page( $title );
37
38
		$finder = $this->createMock( 'SubPageList\Lister\SubPageFinder' );
39
40
		$finder->expects( $this->once() )
41
			->method( 'getSubPagesFor' )
42
			->with( $this->equalTo( $titleText ) )
43
			->will( $this->returnValue( [] ) );
44
45
		$hierarchyCreator = $this->getMockBuilder( 'SubPageList\Lister\PageHierarchyCreator' )
46
			->disableOriginalConstructor()->getMock();
47
48
		$hierarchyCreator->expects( $this->once() )
49
			->method( 'createHierarchy' )
50
			->with( $this->equalTo( [ $title ] ) )
51
			->will( $this->returnValue( [ $page ] ) );
52
53
		$renderer = $this->createMock( 'SubPageList\Lister\UI\SubPageListRenderer' );
54
55
		$renderer->expects( $this->once() )
56
			->method( 'render' )
57
			->with( $this->equalTo( $page ) )
58
			->will( $this->returnValue( $renderResult ) );
59
60
		return new SubPageList(
61
			$finder,
62
			$hierarchyCreator,
63
			$renderer,
64
			new TitleFactory()
65
		);
66
	}
67
68
	private function getRenderedList( SubPageList $subPageList, $titleText ) {
69
		$parser = $this->createMock( 'Parser' );
70
71
		$processingResult = new ProcessingResult(
72
			[
73
				'page' => new ProcessedParam( 'page', $titleText, false ),
74
				'showpage' => new ProcessedParam( 'showpage', true, false ),
75
				'default' => new ProcessedParam( 'default', '', true ),
76
				'limit' => new ProcessedParam( 'limit', 200, true ),
77
				'sort' => new ProcessedParam( 'sort', 'asc', true ),
78
				'redirects' => new ProcessedParam( 'redirects', false, true )
79
			],
80
			[]
81
		);
82
83
		return $subPageList->handle( $parser, $processingResult );
84
	}
85
86
}
87