|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Unit\SubPageList\Counter; |
|
4
|
|
|
|
|
5
|
|
|
use ParamProcessor\ProcessedParam; |
|
6
|
|
|
use ParamProcessor\ProcessingResult; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use SubPageList\Counter\SubPageCount; |
|
9
|
|
|
use SubPageList\TitleFactory; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \SubPageList\Counter\SubPageCount |
|
13
|
|
|
* |
|
14
|
|
|
* @group SubPageList |
|
15
|
|
|
* |
|
16
|
|
|
* @licence GNU GPL v2+ |
|
17
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
18
|
|
|
*/ |
|
19
|
|
|
class SubPageCountTest extends TestCase { |
|
20
|
|
|
|
|
21
|
|
|
public function testSubPageCountHook() { |
|
22
|
|
|
$titleText = 'FooBarPage'; |
|
23
|
|
|
$numberOfSubPages = 42; |
|
24
|
|
|
|
|
25
|
|
|
$subPageCount = $this->newSubPageCount( $titleText, $numberOfSubPages ); |
|
26
|
|
|
$countResult = $this->getCountResult( $subPageCount, $titleText ); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertInternalType( 'string', $countResult ); |
|
29
|
|
|
$this->assertEquals( (string)$numberOfSubPages . '.0', $countResult ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
private function newSubPageCount( $titleText, $numberOfSubPages ) { |
|
33
|
|
|
$titleFactory = new TitleFactory(); |
|
34
|
|
|
|
|
35
|
|
|
$counter = $this->createMock( 'SubPageList\Counter\SubPageCounter' ); |
|
36
|
|
|
|
|
37
|
|
|
$counter->expects( $this->once() ) |
|
38
|
|
|
->method( 'countSubPages' ) |
|
39
|
|
|
->with( $titleFactory->newFromText( $titleText ) ) |
|
40
|
|
|
->will( $this->returnValue( $numberOfSubPages ) ); |
|
41
|
|
|
|
|
42
|
|
|
return new SubPageCount( $counter, $titleFactory ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function getCountResult( SubPageCount $subPageCount, $titleText ) { |
|
46
|
|
|
$language = $this->createMock( 'Language' ); |
|
47
|
|
|
|
|
48
|
|
|
$language->expects( $this->once() ) |
|
49
|
|
|
->method( 'formatNum' ) |
|
50
|
|
|
->will( $this->returnCallback( function( $number ) { |
|
51
|
|
|
return (string)$number . '.0'; |
|
52
|
|
|
} ) ); |
|
53
|
|
|
|
|
54
|
|
|
$parser = $this->createMock( 'Parser' ); |
|
55
|
|
|
|
|
56
|
|
|
$parser->expects( $this->once() ) |
|
57
|
|
|
->method( 'getTargetLanguage' ) |
|
58
|
|
|
->will( $this->returnValue( $language ) ); |
|
59
|
|
|
|
|
60
|
|
|
$processingResult = new ProcessingResult( |
|
61
|
|
|
[ |
|
62
|
|
|
'page' => new ProcessedParam( 'page', $titleText, false ) |
|
63
|
|
|
], |
|
64
|
|
|
[] |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
return $subPageCount->handle( $parser, $processingResult ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|