SimpleSubPageFinderTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4

5 Methods

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