1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Diff\Internal; |
4
|
|
|
|
5
|
|
|
use Diff\DiffOp\Diff\Diff; |
6
|
|
|
use Diff\DiffOp\DiffOpAdd; |
7
|
|
|
use Diff\DiffOp\DiffOpChange; |
8
|
|
|
use Diff\DiffOp\DiffOpRemove; |
9
|
|
|
use PHPUnit_Framework_TestCase; |
10
|
|
|
use Wikibase\DataModel\Services\Diff\Internal\TermListPatcher; |
11
|
|
|
use Wikibase\DataModel\Term\Term; |
12
|
|
|
use Wikibase\DataModel\Term\TermList; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers Wikibase\DataModel\Services\Diff\Internal\TermListPatcher |
16
|
|
|
* |
17
|
|
|
* @license GPL-2.0+ |
18
|
|
|
* @author Bene* < [email protected] > |
19
|
|
|
*/ |
20
|
|
|
class TermListPatcherTest extends PHPUnit_Framework_TestCase { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
24
|
|
|
*/ |
25
|
|
|
public function providePatchTermList() { |
26
|
|
|
return array( |
27
|
|
|
'add a term' => array( |
28
|
|
|
new TermList(), |
29
|
|
|
new Diff( array( |
30
|
|
|
'en' => new DiffOpAdd( 'foo' ) |
31
|
|
|
) ), |
32
|
|
|
new TermList( array( |
33
|
|
|
new Term( 'en', 'foo' ) |
34
|
|
|
) ) |
35
|
|
|
), |
36
|
|
|
'change a term' => array( |
37
|
|
|
new TermList( array( |
38
|
|
|
new Term( 'en', 'foo' ) |
39
|
|
|
) ), |
40
|
|
|
new Diff( array( |
41
|
|
|
'en' => new DiffOpChange( 'foo', 'bar' ) |
42
|
|
|
) ), |
43
|
|
|
new TermList( array( |
44
|
|
|
new Term( 'en', 'bar' ) |
45
|
|
|
) ) |
46
|
|
|
), |
47
|
|
|
'remove a term' => array( |
48
|
|
|
new TermList( array( |
49
|
|
|
new Term( 'en', 'foo' ) |
50
|
|
|
) ), |
51
|
|
|
new Diff( array( |
52
|
|
|
'en' => new DiffOpRemove( 'foo' ) |
53
|
|
|
) ), |
54
|
|
|
new TermList() |
55
|
|
|
), |
56
|
|
|
'add an existing language is no-op' => array( |
57
|
|
|
new TermList( array( |
58
|
|
|
new Term( 'en', 'foo' ) |
59
|
|
|
) ), |
60
|
|
|
new Diff( array( |
61
|
|
|
'en' => new DiffOpAdd( 'bar' ) |
62
|
|
|
) ), |
63
|
|
|
new TermList( array( |
64
|
|
|
new Term( 'en', 'foo' ) |
65
|
|
|
) ) |
66
|
|
|
), |
67
|
|
|
'add two terms' => array( |
68
|
|
|
new TermList( array( |
69
|
|
|
new Term( 'en', 'foo' ) |
70
|
|
|
) ), |
71
|
|
|
new Diff( array( |
72
|
|
|
'de' => new DiffOpAdd( 'bar' ), |
73
|
|
|
'nl' => new DiffOpAdd( 'baz' ) |
74
|
|
|
) ), |
75
|
|
|
new TermList( array( |
76
|
|
|
new Term( 'en', 'foo' ), |
77
|
|
|
new Term( 'de', 'bar' ), |
78
|
|
|
new Term( 'nl', 'baz' ) |
79
|
|
|
) ) |
80
|
|
|
), |
81
|
|
|
'remove a not existing language is no-op' => array( |
82
|
|
|
new TermList( array( |
83
|
|
|
new Term( 'en', 'foo' ) |
84
|
|
|
) ), |
85
|
|
|
new Diff( array( |
86
|
|
|
'de' => new DiffOpRemove( 'bar' ) |
87
|
|
|
) ), |
88
|
|
|
new TermList( array( |
89
|
|
|
new Term( 'en', 'foo' ) |
90
|
|
|
) ) |
91
|
|
|
), |
92
|
|
|
'change a different value is no-op' => array( |
93
|
|
|
new TermList( array( |
94
|
|
|
new Term( 'en', 'foo' ) |
95
|
|
|
) ), |
96
|
|
|
new Diff( array( |
97
|
|
|
'en' => new DiffOpChange( 'bar', 'baz' ) |
98
|
|
|
) ), |
99
|
|
|
new TermList( array( |
100
|
|
|
new Term( 'en', 'foo' ) |
101
|
|
|
) ) |
102
|
|
|
), |
103
|
|
|
'remove a different value is no-op' => array( |
104
|
|
|
new TermList( array( |
105
|
|
|
new Term( 'en', 'foo' ) |
106
|
|
|
) ), |
107
|
|
|
new Diff( array( |
108
|
|
|
'en' => new DiffOpRemove( 'bar' ) |
109
|
|
|
) ), |
110
|
|
|
new TermList( array( |
111
|
|
|
new Term( 'en', 'foo' ) |
112
|
|
|
) ) |
113
|
|
|
), |
114
|
|
|
'complex diff (associative)' => array( |
115
|
|
|
new TermList( array( |
116
|
|
|
new Term( 'en', 'foo' ), |
117
|
|
|
new Term( 'de', 'bar' ), |
118
|
|
|
new Term( 'nl', 'baz' ) |
119
|
|
|
) ), |
120
|
|
|
new Diff( array( |
121
|
|
|
'en' => new DiffOpChange( 'foo', 'bar' ), |
122
|
|
|
'de' => new DiffOpRemove( 'bar' ), |
123
|
|
|
'nl' => new DiffOpChange( 'bar', 'foo' ), |
124
|
|
|
'it' => new DiffOpAdd( 'foo' ) |
125
|
|
|
), true ), |
126
|
|
|
new TermList( array( |
127
|
|
|
new Term( 'en', 'bar' ), |
128
|
|
|
new Term( 'nl', 'baz' ), |
129
|
|
|
new Term( 'it', 'foo' ) |
130
|
|
|
) ) |
131
|
|
|
), |
132
|
|
|
'complex diff (non-associative)' => array( |
133
|
|
|
new TermList( array( |
134
|
|
|
new Term( 'en', 'foo' ), |
135
|
|
|
new Term( 'de', 'bar' ), |
136
|
|
|
new Term( 'nl', 'baz' ) |
137
|
|
|
) ), |
138
|
|
|
new Diff( array( |
139
|
|
|
'en' => new DiffOpChange( 'foo', 'bar' ), |
140
|
|
|
'de' => new DiffOpRemove( 'bar' ), |
141
|
|
|
'nl' => new DiffOpChange( 'bar', 'foo' ), |
142
|
|
|
'it' => new DiffOpAdd( 'foo' ) |
143
|
|
|
), false ), |
144
|
|
|
new TermList( array( |
145
|
|
|
new Term( 'en', 'bar' ), |
146
|
|
|
new Term( 'nl', 'baz' ), |
147
|
|
|
new Term( 'it', 'foo' ) |
148
|
|
|
) ) |
149
|
|
|
), |
150
|
|
|
'complex diff (auto-detected)' => array( |
151
|
|
|
new TermList( array( |
152
|
|
|
new Term( 'en', 'foo' ), |
153
|
|
|
new Term( 'de', 'bar' ), |
154
|
|
|
new Term( 'nl', 'baz' ) |
155
|
|
|
) ), |
156
|
|
|
new Diff( array( |
157
|
|
|
'en' => new DiffOpChange( 'foo', 'bar' ), |
158
|
|
|
'de' => new DiffOpRemove( 'bar' ), |
159
|
|
|
'nl' => new DiffOpChange( 'bar', 'foo' ), |
160
|
|
|
'it' => new DiffOpAdd( 'foo' ) |
161
|
|
|
) ), |
162
|
|
|
new TermList( array( |
163
|
|
|
new Term( 'en', 'bar' ), |
164
|
|
|
new Term( 'nl', 'baz' ), |
165
|
|
|
new Term( 'it', 'foo' ) |
166
|
|
|
) ) |
167
|
|
|
), |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @dataProvider providePatchTermList |
173
|
|
|
*/ |
174
|
|
|
public function testPatchTermList( TermList $terms, Diff $patch, TermList $expected ) { |
175
|
|
|
$patcher = new TermListPatcher(); |
176
|
|
|
$patcher->patchTermList( $terms, $patch ); |
177
|
|
|
|
178
|
|
|
$this->assertSame( $expected->toTextArray(), $terms->toTextArray() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
} |
182
|
|
|
|