1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SRF\Tests\BibTex; |
4
|
|
|
|
5
|
|
|
use SRF\BibTex\BibTexFileExportPrinter; |
6
|
|
|
use SRF\Tests\ResultPrinterReflector; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SRF\BibTex\BibTexFileExportPrinter |
10
|
|
|
* @group semantic-result-formats |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 3.1 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class BibTexFileExportPrinterTest 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
|
|
|
BibTexFileExportPrinter::class, |
36
|
|
|
new BibTexFileExportPrinter( 'bibtex' ) |
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 BibTexFileExportPrinter( |
51
|
|
|
'bibtex' |
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 BibTexFileExportPrinter( |
65
|
|
|
'bibtex' |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->assertEquals( |
69
|
|
|
'text/bibtex', |
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 BibTexFileExportPrinter( |
97
|
|
|
'bibtex' |
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
|
|
|
'', |
111
|
|
|
'BibTeX.bib' |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
yield[ |
115
|
|
|
'', |
116
|
|
|
'foo bar', |
117
|
|
|
'foo_bar.bib' |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
yield[ |
121
|
|
|
'foo', |
122
|
|
|
'', |
123
|
|
|
'foo.bib' |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
yield[ |
127
|
|
|
'foo.bib', |
128
|
|
|
'', |
129
|
|
|
'foo.bib' |
130
|
|
|
]; |
131
|
|
|
|
132
|
|
|
yield[ |
133
|
|
|
'foo bar.bib', |
134
|
|
|
'', |
135
|
|
|
'foo_bar.bib' |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|