summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php
blob: f094268f610696e8ded0f606daa5c0806fefa06e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php

namespace SRF\Tests\vCard;

use SRF\vCard\vCardFileExportPrinter;
use SRF\Tests\ResultPrinterReflector;

/**
 * @covers \SRF\vCard\vCardFileExportPrinter
 * @group semantic-result-formats
 *
 * @license GNU GPL v2+
 * @since 3.1
 *
 * @author mwjames
 */
class vCardFileExportPrinterTest extends \PHPUnit_Framework_TestCase {

	private $queryResult;
	private $resultPrinterReflector;

	protected function setUp() {
		parent::setUp();

		$this->resultPrinterReflector = new ResultPrinterReflector();

		$this->queryResult = $this->getMockBuilder( '\SMWQueryResult' )
			->disableOriginalConstructor()
			->getMock();
	}

	public function testCanConstruct() {

		$this->assertInstanceOf(
			vCardFileExportPrinter::class,
			new vCardFileExportPrinter( 'vcard' )
		);
	}

	/**
	 * @dataProvider filenameProvider
	 */
	public function testGetFileName( $filename, $searchlabel, $expected ) {

		$parameters = [
			'filename' => $filename,
			'searchlabel' => $searchlabel
		];

		$instance = new vCardFileExportPrinter(
			'vcard'
		);

		$this->resultPrinterReflector->addParameters( $instance, $parameters );

		$this->assertEquals(
			$expected,
			$instance->getFileName( $this->queryResult )
		);
	}

	public function testGetMimeType() {

		$instance = new vCardFileExportPrinter(
			'vcard'
		);

		$this->assertEquals(
			'text/x-vcard',
			$instance->getMimeType( $this->queryResult )
		);
	}

	public function testGetResult_LinkOnNonFileOutput() {

		$link = $this->getMockBuilder( '\SMWInfolink' )
			->disableOriginalConstructor()
			->getMock();

		$link->expects( $this->any() )
			->method( 'getText' )
			->will( $this->returnValue( 'foo_link' ) );

		$this->queryResult->expects( $this->any() )
			->method( 'getErrors' )
			->will( $this->returnValue( [] ) );

		$this->queryResult->expects( $this->any() )
			->method( 'getCount' )
			->will( $this->returnValue( 1 ) );

		$this->queryResult->expects( $this->once() )
			->method( 'getQueryLink' )
			->will( $this->returnValue( $link ) );

		$instance = new vCardFileExportPrinter(
			'vcard'
		);

		$this->assertEquals(
			'foo_link',
			$instance->getResult( $this->queryResult, [], SMW_OUTPUT_HTML )
		);
	}

	public function filenameProvider() {

		yield[
			'',
			'foo bar',
			'foo_bar.vcf'
		];

		yield[
			'foo',
			'',
			'foo.vcf'
		];

		yield[
			'foo.vcf',
			'',
			'foo.vcf'
		];

		yield[
			'foo bar.vcf',
			'',
			'foo_bar.vcf'
		];
	}

}