Completed
Push — master ( 756515...e0d7bf )
by Jeroen De
08:10 queued 08:07
created

testGetSubPagesForRedirect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 9.4285
1
<?php
2
3
namespace Tests\Unit\SubPageList\Lister;
4
5
use SubPageList\LazyDBConnectionProvider;
6
use SubPageList\Lister\SimpleSubPageFinder;
7
use SubPageList\Lister\SubPageFinder;
8
use Title;
9
10
/**
11
 * @covers SubPageList\Lister\SimpleSubPageFinder
12
 *
13
 * @group SubPageList
14
 * @group Database
15
 *
16
 * @licence GNU GPL v2+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class SimpleSubPageFinderTest extends \PHPUnit_Framework_TestCase {
20
21
	/**
22
	 * @return SubPageFinder
23
	 */
24
	public function newInstance() {
25
		return new SimpleSubPageFinder( new LazyDBConnectionProvider( DB_SLAVE ) );
26
	}
27
28
	public function titleProvider() {
29
		$argLists = [];
30
31
		$argLists[] = [ Title::newMainPage() ];
32
		$argLists[] = [ Title::newFromText( 'ohi there i do not exist nyan nyan nyan' ) ];
33
34
		return $argLists;
35
	}
36
	
37
	public function redirectProvider() {
38
		$argLists = [];
39
40
		Title::newFromText( 'hello world' );
41
		
42
		$argLists[] = [ Title::newFromText( 'Redirect Test' ) ];
43
		$rc = new RedirectCreator();
44
		$rc->createRedirect( 
45
			Title::newFromText( 'Redirect Test/Sub' ), 
46
			'hello world' 
47
		);
48
49
		return $argLists;
50
	}
51
52
	/**
53
	 * @dataProvider titleProvider
54
	 *
55
	 * @param Title $title
56
	 */
57
	public function testGetSubPagesFor( Title $title ) {
58
		$finder = $this->newInstance();
59
60
		$pages = $finder->getSubPagesFor( $title );
61
62
		$this->assertInternalType( 'array', $pages );
63
		$this->assertContainsOnlyInstancesOf( Title::class, $pages );
64
	}
65
	
66
	/**
67
	 * @dataProvider redirectProvider
68
	 *
69
	 * @param Title $title
70
	 */
71
	public function testGetSubPagesForRedirect( Title $title ) {
72
		$finder = $this->newInstance();
73
74
		$pages = $finder->getSubPagesFor( $title );
75
76
		$this->assertInternalType( 'array', $pages );
77
		$this->assertContainsOnlyInstancesOf( Title::class, $pages );
78
		
79
		foreach ( $pages as $subPage ) {
80
			$this->assertSame( 
81
				$subPage->getFullText(),
82
				'Redirect Test/Sub'
83
			);
84
		}
85
	}
86
87
}
88