|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SRF\Tests\BibTex; |
|
4
|
|
|
|
|
5
|
|
|
use SRF\BibTex\Item; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers \SRF\BibTex\Item |
|
9
|
|
|
* @group semantic-result-formats |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU GPL v2+ |
|
12
|
|
|
* @since 3.1 |
|
13
|
|
|
* |
|
14
|
|
|
* @author mwjames |
|
15
|
|
|
*/ |
|
16
|
|
|
class ItemTest extends \PHPUnit_Framework_TestCase { |
|
17
|
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
|
19
|
|
|
|
|
20
|
|
|
$this->assertInstanceOf( |
|
21
|
|
|
Item::class, |
|
22
|
|
|
new Item() |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @dataProvider fieldsProvider |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testText( $fields, $expected ) { |
|
30
|
|
|
|
|
31
|
|
|
$instance = new Item(); |
|
32
|
|
|
|
|
33
|
|
|
foreach ( $fields as $key => $value ) { |
|
34
|
|
|
$instance->set( $key, $value ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$this->assertEquals( |
|
38
|
|
|
$expected, |
|
39
|
|
|
$instance->text() |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @dataProvider formatterCallbackFieldsProvider |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testFormatterCallback( $fields, $expected ) { |
|
47
|
|
|
|
|
48
|
|
|
$instance = new Item(); |
|
49
|
|
|
$instance->setFormatterCallback( function( $key, $values ) { |
|
50
|
|
|
return implode( '#', $values ); |
|
51
|
|
|
} ); |
|
52
|
|
|
|
|
53
|
|
|
foreach ( $fields as $key => $value ) { |
|
54
|
|
|
$instance->set( $key, $value ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals( |
|
58
|
|
|
$expected, |
|
59
|
|
|
$instance->text() |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @dataProvider replaceTextProvider |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testReplace( $key, $text, $expected ) { |
|
67
|
|
|
|
|
68
|
|
|
$instance = new Item(); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals( |
|
71
|
|
|
$expected, |
|
72
|
|
|
$instance->replace( 'uri', $text ) |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function fieldsProvider() { |
|
77
|
|
|
|
|
78
|
|
|
yield [ |
|
79
|
|
|
[ 'foo' => 'test', 'author' => [ 'abc', 'def', '123' ] ], |
|
80
|
|
|
"@Book{abc,\r\n author = \"abc, def, 123\", \r\n}" |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
yield [ |
|
84
|
|
|
[ 'foo' => 'test', 'title' => 'foo bar', 'editor' => [ 'abc', 'def', '123' ] ], |
|
85
|
|
|
"@Book{fb,\r\n editor = \"abc, def, 123\", \r\n title = \"foo bar\", \r\n}" |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function formatterCallbackFieldsProvider() { |
|
90
|
|
|
|
|
91
|
|
|
yield [ |
|
92
|
|
|
[ 'foo' => 'test', 'author' => [ 'abc', 'def', '123' ] ], |
|
93
|
|
|
"@Book{abc,\r\n author = \"abc#def#123\", \r\n}" |
|
94
|
|
|
]; |
|
95
|
|
|
|
|
96
|
|
|
yield [ |
|
97
|
|
|
[ 'foo' => 'test', 'title' => 'foo bar', 'editor' => [ 'abc', 'def', '123' ] ], |
|
98
|
|
|
"@Book{fb,\r\n editor = \"abc#def#123\", \r\n title = \"foo bar\", \r\n}" |
|
99
|
|
|
]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function replaceTextProvider() { |
|
103
|
|
|
|
|
104
|
|
|
yield [ |
|
105
|
|
|
'uri', |
|
106
|
|
|
'abc-_+ÄäÖ', |
|
107
|
|
|
'abcAeaeOe' |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|