Completed
Push — master ( 3c5b53...50507a )
by mw
08:24
created

vCardFileExportPrinterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 117
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testCanConstruct() 0 7 1
A testGetFileName() 0 18 1
A testGetMimeType() 0 11 1
A testGetResult_LinkOnNonFileOutput() 0 31 1
A filenameProvider() 0 26 1
1
<?php
2
3
namespace SRF\Tests\vCard;
4
5
use SRF\vCard\vCardFileExportPrinter;
6
use SRF\Tests\ResultPrinterReflector;
7
8
/**
9
 * @covers \SRF\vCard\vCardFileExportPrinter
10
 * @group semantic-result-formats
11
 *
12
 * @license GNU GPL v2+
13
 * @since 3.1
14
 *
15
 * @author mwjames
16
 */
17
class vCardFileExportPrinterTest extends \PHPUnit_Framework_TestCase {
18
19
	private $queryResult;
20
	private $resultPrinterReflector;
21
22
	protected function setUp() {
23
		parent::setUp();
24
25
		$this->resultPrinterReflector = new ResultPrinterReflector();
26
27
		$this->queryResult = $this->getMockBuilder( '\SMWQueryResult' )
28
			->disableOriginalConstructor()
29
			->getMock();
30
	}
31
32
	public function testCanConstruct() {
33
34
		$this->assertInstanceOf(
35
			vCardFileExportPrinter::class,
36
			new vCardFileExportPrinter( 'vcard' )
37
		);
38
	}
39
40
	/**
41
	 * @dataProvider filenameProvider
42
	 */
43
	public function testGetFileName( $filename, $searchlabel, $expected ) {
44
45
		$parameters = [
46
			'filename' => $filename,
47
			'searchlabel' => $searchlabel
48
		];
49
50
		$instance = new vCardFileExportPrinter(
51
			'vcard'
52
		);
53
54
		$this->resultPrinterReflector->addParameters( $instance, $parameters );
55
56
		$this->assertEquals(
57
			$expected,
58
			$instance->getFileName( $this->queryResult )
59
		);
60
	}
61
62
	public function testGetMimeType() {
63
64
		$instance = new vCardFileExportPrinter(
65
			'vcard'
66
		);
67
68
		$this->assertEquals(
69
			'text/x-vcard',
70
			$instance->getMimeType( $this->queryResult )
71
		);
72
	}
73
74
	public function testGetResult_LinkOnNonFileOutput() {
75
76
		$link = $this->getMockBuilder( '\SMWInfolink' )
77
			->disableOriginalConstructor()
78
			->getMock();
79
80
		$link->expects( $this->any() )
81
			->method( 'getText' )
82
			->will( $this->returnValue( 'foo_link' ) );
83
84
		$this->queryResult->expects( $this->any() )
85
			->method( 'getErrors' )
86
			->will( $this->returnValue( [] ) );
87
88
		$this->queryResult->expects( $this->any() )
89
			->method( 'getCount' )
90
			->will( $this->returnValue( 1 ) );
91
92
		$this->queryResult->expects( $this->once() )
93
			->method( 'getQueryLink' )
94
			->will( $this->returnValue( $link ) );
95
96
		$instance = new vCardFileExportPrinter(
97
			'vcard'
98
		);
99
100
		$this->assertEquals(
101
			'foo_link',
102
			$instance->getResult( $this->queryResult, [], SMW_OUTPUT_HTML )
103
		);
104
	}
105
106
	public function filenameProvider() {
107
108
		yield[
109
			'',
110
			'foo bar',
111
			'foo_bar.vcf'
112
		];
113
114
		yield[
115
			'foo',
116
			'',
117
			'foo.vcf'
118
		];
119
120
		yield[
121
			'foo.vcf',
122
			'',
123
			'foo.vcf'
124
		];
125
126
		yield[
127
			'foo bar.vcf',
128
			'',
129
			'foo_bar.vcf'
130
		];
131
	}
132
133
}
134