Completed
Push — master ( c18f14...017364 )
by mw
292:38 queued 257:37
created

DisposeJobTaskHandlerTest::testGetHtml()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 0
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\MediaWiki\Specials\Admin;
4
5
use SMW\Tests\TestEnvironment;
6
use SMW\MediaWiki\Specials\Admin\DisposeJobTaskHandler;
7
8
/**
9
 * @covers \SMW\MediaWiki\Specials\Admin\DisposeJobTaskHandler
10
 * @group semantic-mediawiki
11
 *
12
 * @license GNU GPL v2+
13
 * @since 2.5
14
 *
15
 * @author mwjames
16
 */
17
class DisposeJobTaskHandlerTest 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\DisposeJobTaskHandler',
62
			new DisposeJobTaskHandler( $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 DisposeJobTaskHandler(
87
			$this->store,
88
			$this->htmlFormRenderer,
89
			$this->outputFormatter
90
		);
91
92
		$instance->getHtml();
93
	}
94
95
	public function testHandleRequest() {
96
97
		$entityIdDisposerJob = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\EntityIdDisposerJob' )
98
			->disableOriginalConstructor()
99
			->getMock();
100
101
		$entityIdDisposerJob->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( $entityIdDisposerJob ) );
111
112
		$this->testEnvironment->registerObject( 'JobFactory', $jobFactory );
113
114
		$webRequest = $this->getMockBuilder( '\WebRequest' )
115
			->disableOriginalConstructor()
116
			->getMock();
117
118
		$instance = new DisposeJobTaskHandler(
119
			$this->store,
120
			$this->htmlFormRenderer,
121
			$this->outputFormatter
122
		);
123
124
		$instance->setEnabledFeatures( SMW_ADM_DISPOSAL );
125
		$instance->handleRequest( $webRequest );
126
	}
127
128
}
129