FormPrinterHandlerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 105
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 7 1
A testCanUseForm() 0 23 1
B testGetFormText() 0 34 1
B testGetTemplateText() 0 34 1
1
<?php
2
3
namespace SES\Tests;
4
5
use SES\FormPrinterHandler;
6
use Title;
7
8
/**
9
 * @covers \SES\FormPrinterHandler
10
 *
11
 * @group semantic-signup
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.1
15
 *
16
 * @author mwjames
17
 */
18
class FormPrinterHandlerTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testCanConstruct() {
21
22
		$this->assertInstanceOf(
23
			'\SES\FormPrinterHandler',
24
			new FormPrinterHandler()
25
		);
26
	}
27
28
	public function testCanUseForm() {
29
30
		$instance = new FormPrinterHandler();
31
32
		$this->assertFalse(
33
			$instance->canUseForm()
34
		);
35
36
		$title = $this->getMockBuilder( '\Title' )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$title->expects( $this->once() )
41
			->method( 'exists' )
42
			->will( $this->returnValue( true ) );
43
44
		$instance = new FormPrinterHandler( $title );
45
46
		$this->assertTrue(
47
			$instance->canUseForm()
48
		);
49
50
	}
51
52
	public function testGetFormText() {
53
54
		$title = $this->getMockBuilder( '\Title' )
55
			->disableOriginalConstructor()
56
			->getMock();
57
58
		$title->expects( $this->any() )
59
			->method( 'exists' )
60
			->will( $this->returnValue( true ) );
61
62
		$instance = new FormPrinterHandler( $title );
63
64
		$this->assertEmpty(
65
			$instance->getFormText()
66
		);
67
68
		$formPrinter = $this->getMockBuilder( '\SFFormPrinter' )
69
			->disableOriginalConstructor()
70
			->getMock();
71
72
		$formPrinter->expects( $this->once() )
73
			->method( 'formHTML' )
74
			->will( $this->returnValue( array( 'Foo', '', '', '', '' ) ) );
75
76
		$instance = new FormPrinterHandler(
77
			$title,
78
			$formPrinter
79
		);
80
81
		$this->assertEquals(
82
			'Foo',
83
			$instance->getFormText()
84
		);
85
	}
86
87
	public function testGetTemplateText() {
88
89
		$title = $this->getMockBuilder( '\Title' )
90
			->disableOriginalConstructor()
91
			->getMock();
92
93
		$title->expects( $this->any() )
94
			->method( 'exists' )
95
			->will( $this->returnValue( true ) );
96
97
		$instance = new FormPrinterHandler( $title );
98
99
		$this->assertEmpty(
100
			$instance->getTemplateText()
101
		);
102
103
		$formPrinter = $this->getMockBuilder( '\SFFormPrinter' )
104
			->disableOriginalConstructor()
105
			->getMock();
106
107
		$formPrinter->expects( $this->once() )
108
			->method( 'formHTML' )
109
			->will( $this->returnValue( array( '', '', 'Bar', '', '' ) ) );
110
111
		$instance = new FormPrinterHandler(
112
			$title,
113
			$formPrinter
114
		);
115
116
		$this->assertEquals(
117
			'Bar',
118
			$instance->getTemplateText()
119
		);
120
	}
121
122
}
123