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
|
|
|
|