Completed
Push — master ( 3df45e...ce7128 )
by Jeroen De
10s
created

testRenderHierarchyWithManySubPages()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Unit\SubPageList\Lister\UI;
4
5
use SubPageList\Lister\Page;
6
use SubPageList\Lister\UI\TreeListRenderer;
7
use Title;
8
9
/**
10
 * @covers SubPageList\Lister\UI\TreeListRenderer
11
 *
12
 * @group SubPageList
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class TreeListRendererTest extends \PHPUnit_Framework_TestCase {
18
19
	/**
20
	 * @dataProvider titleTextProvider
21
	 */
22
	public function testRenderHierarchyWithNoSubPages( $titleText ) {
23
		$this->assertRendersHierarchy(
24
			new Page( Title::newFromText( $titleText ) ),
25
			'',
26
			[
27
				TreeListRenderer::OPT_SHOW_TOP_PAGE => false
28
			]
29
		);
30
	}
31
32
	public function titleTextProvider() {
33
		return [
34
			[ 'A' ],
35
			[ 'AAAAAAAA' ],
36
			[ 'AA BB CC' ],
37
		];
38
	}
39
40
	/**
41
	 * @dataProvider titleTextProvider
42
	 */
43
	public function testRenderHierarchyWithNoSubPagesShowingPageItself( $titleText ) {
44
		$this->assertRendersHierarchy(
45
			new Page( Title::newFromText( $titleText ) ),
46
			$titleText
47
		);
48
	}
49
50
	private function assertRendersHierarchy( Page $page, $expected, array $options = [] ) {
51
		$listRender = $this->newListRenderer( $options );
52
53
		$actual = $listRender->renderHierarchy( $page );
54
55
		$this->assertEquals( $expected, $actual );
56
	}
57
58
	private function newListRenderer( array $options ) {
59
		$pageRenderer = $this->getMock( 'SubPageList\Lister\UI\PageRenderer\PageRenderer' );
60
61
		$pageRenderer->expects( $this->any() )
62
			->method( 'renderPage' )
63
			->will( $this->returnCallback( function( Page $page ) {
64
				return $page->getTitle()->getFullText();
65
			} ) );
66
67
		 return new TreeListRenderer(
68
			 $pageRenderer,
69
			 $options
70
		 );
71
	}
72
73
	public function testRenderHierarchyWithSubPages() {
74
		$this->assertRendersHierarchy(
75
			new Page(
76
				Title::newFromText( 'AAA' ),
77
				[
78
					new Page( Title::newFromText( 'BBB' ) ),
79
                    new Page( Title::newFromText( 'CCC' ) ),
80
				]
81
			),
82
			'AAA
83
* BBB
84
* CCC'
85
		);
86
	}
87
88
	public function testRenderHierarchyWithManySubPages() {
89
		$this->assertRendersHierarchy(
90
			new Page(
91
				Title::newFromText( 'AAA' ),
92
				[
93
					new Page(
94
						Title::newFromText( 'BBB' ),
95
						[
96
							new Page( Title::newFromText( '111' ) ),
97
							new Page( Title::newFromText( '222' ) ),
98
						]
99
					),
100
					new Page(
101
						Title::newFromText( 'CCC' ),
102
						[]
103
					),
104
					new Page(
105
						Title::newFromText( 'DDD' ),
106
						[
107
							new Page( Title::newFromText( '333' ) ),
108
						]
109
					),
110
				]
111
			),
112
			'AAA
113
* BBB
114
** 111
115
** 222
116
* CCC
117
* DDD
118
** 333'
119
		);
120
	}
121
122
	public function testRenderHierarchyWithDepthLimit() {
123
		$this->assertRendersHierarchy(
124
			new Page(
125
				Title::newFromText( 'AAA' ),
126
				[
127
					new Page(
128
						Title::newFromText( 'BBB' ),
129
						[
130
							new Page( Title::newFromText( '111' ) ),
131
							new Page( Title::newFromText( '222' ) ),
132
						]
133
					),
134
					new Page(
135
						Title::newFromText( 'CCC' ),
136
						[]
137
					),
138
					new Page(
139
						Title::newFromText( 'DDD' ),
140
						[
141
							new Page( Title::newFromText( '333' ) ),
142
						]
143
					),
144
				]
145
			),
146
			'AAA
147
* BBB
148
* CCC
149
* DDD',
150
			[
151
				TreeListRenderer::OPT_MAX_DEPTH => 1
152
			]
153
		);
154
	}
155
156
}
157