|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SRF\Tests\BibTex; |
|
4
|
|
|
|
|
5
|
|
|
use SRF\BibTex\BibTexFileExportPrinter; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers \SRF\BibTex\BibTexFileExportPrinter |
|
9
|
|
|
* @group semantic-result-formats |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU GPL v2+ |
|
12
|
|
|
* @since 3.1 |
|
13
|
|
|
* |
|
14
|
|
|
* @author mwjames |
|
15
|
|
|
*/ |
|
16
|
|
|
class BibTexFileExportPrinterTest extends \PHPUnit_Framework_TestCase { |
|
17
|
|
|
|
|
18
|
|
|
private $queryResult; |
|
19
|
|
|
private $resultPrinterReflector; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() { |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
|
|
24
|
|
|
$this->queryResult = $this->getMockBuilder( '\SMWQueryResult' ) |
|
25
|
|
|
->disableOriginalConstructor() |
|
26
|
|
|
->getMock(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function addParameters( $instance, array $parameters ) { |
|
30
|
|
|
|
|
31
|
|
|
$reflector = new \ReflectionClass( $instance ); |
|
32
|
|
|
$params = $reflector->getProperty( 'params' ); |
|
33
|
|
|
$params->setAccessible( true ); |
|
34
|
|
|
$params->setValue( $instance, $parameters ); |
|
35
|
|
|
|
|
36
|
|
|
if ( isset( $parameters['searchlabel'] ) ) { |
|
37
|
|
|
$searchlabel = $reflector->getProperty( 'mSearchlabel' ); |
|
38
|
|
|
$searchlabel->setAccessible( true ); |
|
39
|
|
|
$searchlabel->setValue( $instance, $parameters['searchlabel'] ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if ( isset( $parameters['headers'] ) ) { |
|
43
|
|
|
$searchlabel = $reflector->getProperty( 'mShowHeaders' ); |
|
44
|
|
|
$searchlabel->setAccessible( true ); |
|
45
|
|
|
$searchlabel->setValue( $instance, $parameters['headers'] ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $instance; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testCanConstruct() { |
|
52
|
|
|
|
|
53
|
|
|
$this->assertInstanceOf( |
|
54
|
|
|
BibTexFileExportPrinter::class, |
|
55
|
|
|
new BibTexFileExportPrinter( 'bibtex' ) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetFileName() { |
|
60
|
|
|
|
|
61
|
|
|
$parameters = [ |
|
62
|
|
|
'filename' => 'foo' |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
$instance = new BibTexFileExportPrinter( |
|
66
|
|
|
'bibtex' |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$this->addParameters( $instance, $parameters ); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals( |
|
72
|
|
|
'foo.bib', |
|
73
|
|
|
$instance->getFileName( $this->queryResult ) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testGetMimeType() { |
|
78
|
|
|
|
|
79
|
|
|
$instance = new BibTexFileExportPrinter( |
|
80
|
|
|
'bibtex' |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertEquals( |
|
84
|
|
|
'text/bibtex', |
|
85
|
|
|
$instance->getMimeType( $this->queryResult ) |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|