1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\MediaWiki\Specials\Admin; |
4
|
|
|
|
5
|
|
|
use SMW\Tests\TestEnvironment; |
6
|
|
|
use SMW\MediaWiki\Specials\Admin\FulltextSearchTableRebuildJobTaskHandler; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SMW\MediaWiki\Specials\Admin\FulltextSearchTableRebuildJobTaskHandler |
10
|
|
|
* @group semantic-mediawiki |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 2.5 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class FulltextSearchTableRebuildJobTaskHandlerTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $testEnvironment; |
20
|
|
|
private $connection; |
21
|
|
|
private $htmlFormRenderer; |
22
|
|
|
private $outputFormatter; |
23
|
|
|
|
24
|
|
|
protected function setUp() { |
25
|
|
|
parent::setUp(); |
26
|
|
|
|
27
|
|
|
$this->testEnvironment = new TestEnvironment(); |
28
|
|
|
|
29
|
|
|
$this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
30
|
|
|
->disableOriginalConstructor() |
31
|
|
|
->getMock(); |
32
|
|
|
|
33
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
34
|
|
|
->disableOriginalConstructor() |
35
|
|
|
->setMethods( array( 'getConnection' ) ) |
36
|
|
|
->getMockForAbstractClass(); |
37
|
|
|
|
38
|
|
|
$this->store->expects( $this->any() ) |
39
|
|
|
->method( 'getConnection' ) |
40
|
|
|
->will( $this->returnValue( $this->connection ) ); |
41
|
|
|
|
42
|
|
|
$this->htmlFormRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlFormRenderer' ) |
43
|
|
|
->disableOriginalConstructor() |
44
|
|
|
->getMock(); |
45
|
|
|
|
46
|
|
|
$this->outputFormatter = $this->getMockBuilder( '\SMW\MediaWiki\Specials\Admin\OutputFormatter' ) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
|
50
|
|
|
$this->testEnvironment->registerObject( 'Store', $this->store ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function tearDown() { |
54
|
|
|
$this->testEnvironment->tearDown(); |
55
|
|
|
parent::tearDown(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCanConstruct() { |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf( |
61
|
|
|
'\SMW\MediaWiki\Specials\Admin\FulltextSearchTableRebuildJobTaskHandler', |
62
|
|
|
new FulltextSearchTableRebuildJobTaskHandler( $this->store, $this->htmlFormRenderer, $this->outputFormatter ) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetHtml() { |
67
|
|
|
|
68
|
|
|
$methods = array( |
69
|
|
|
'setName', |
70
|
|
|
'setMethod', |
71
|
|
|
'addHiddenField', |
72
|
|
|
'addHeader', |
73
|
|
|
'addParagraph', |
74
|
|
|
'addSubmitButton' |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
foreach ( $methods as $method ) { |
78
|
|
|
$this->htmlFormRenderer->expects( $this->any() ) |
79
|
|
|
->method( $method ) |
80
|
|
|
->will( $this->returnSelf() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->htmlFormRenderer->expects( $this->atLeastOnce() ) |
84
|
|
|
->method( 'getForm' ); |
85
|
|
|
|
86
|
|
|
$instance = new FulltextSearchTableRebuildJobTaskHandler( |
87
|
|
|
$this->store, |
88
|
|
|
$this->htmlFormRenderer, |
89
|
|
|
$this->outputFormatter |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$instance->getHtml(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testHandleRequest() { |
96
|
|
|
|
97
|
|
|
$fulltextSearchTableRebuildJob = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\FulltextSearchTableRebuildJob' ) |
98
|
|
|
->disableOriginalConstructor() |
99
|
|
|
->getMock(); |
100
|
|
|
|
101
|
|
|
$fulltextSearchTableRebuildJob->expects( $this->once() ) |
102
|
|
|
->method( 'insert' ); |
103
|
|
|
|
104
|
|
|
$jobFactory = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\JobFactory' ) |
105
|
|
|
->disableOriginalConstructor() |
106
|
|
|
->getMock(); |
107
|
|
|
|
108
|
|
|
$jobFactory->expects( $this->once() ) |
109
|
|
|
->method( 'newByType' ) |
110
|
|
|
->will( $this->returnValue( $fulltextSearchTableRebuildJob ) ); |
111
|
|
|
|
112
|
|
|
$this->testEnvironment->registerObject( 'JobFactory', $jobFactory ); |
113
|
|
|
|
114
|
|
|
$webRequest = $this->getMockBuilder( '\WebRequest' ) |
115
|
|
|
->disableOriginalConstructor() |
116
|
|
|
->getMock(); |
117
|
|
|
|
118
|
|
|
$instance = new FulltextSearchTableRebuildJobTaskHandler( |
119
|
|
|
$this->store, |
120
|
|
|
$this->htmlFormRenderer, |
121
|
|
|
$this->outputFormatter |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$instance->setEnabledFeatures( SMW_ADM_FULLT ); |
125
|
|
|
$instance->handleRequest( $webRequest ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|