-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEntityDiffTest.php
More file actions
175 lines (135 loc) · 4.43 KB
/
EntityDiffTest.php
File metadata and controls
175 lines (135 loc) · 4.43 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
namespace Wikibase\DataModel\Services\Tests\Diff;
use Diff\DiffOp\Diff\Diff;
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
use PHPUnit_Framework_TestCase;
use Wikibase\DataModel\Services\Diff\EntityDiff;
use Wikibase\DataModel\Services\Diff\StatementListDiffer;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Statement\StatementList;
/**
* @covers Wikibase\DataModel\Services\Diff\EntityDiff
*
* @license GPL-2.0+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class EntityDiffTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider newForTypeProvider
*/
public function testNewForType( $entityType, $expected ) {
$diff = EntityDiff::newForType( $entityType );
$this->assertInstanceOf( $expected, $diff );
}
public function newForTypeProvider() {
return array(
array( 'item', 'Wikibase\DataModel\Services\Diff\ItemDiff' ),
array( 'anything', 'Wikibase\DataModel\Services\Diff\EntityDiff' ),
);
}
public function isEmptyProvider() {
$argLists = array();
$argLists[] = array( array(), true );
$fields = array( 'aliases', 'label', 'description', 'claim' );
foreach ( $fields as $field ) {
$argLists[] = array( array( $field => new Diff( array() ) ), true );
}
$diffOps = array();
foreach ( $fields as $field ) {
$diffOps[$field] = new Diff( array() );
}
$argLists[] = array( $diffOps, true );
foreach ( $fields as $field ) {
$argLists[] = array( array( $field => new Diff( array( new DiffOpAdd( 42 ) ) ) ), false );
}
return $argLists;
}
/**
* @dataProvider isEmptyProvider
* @param Diff[] $diffOps
* @param bool $isEmpty
*/
public function testIsEmpty( array $diffOps, $isEmpty ) {
$diff = new EntityDiff( $diffOps );
$this->assertEquals( $isEmpty, $diff->isEmpty() );
}
public function diffProvider() {
$diffs = array();
$diffOps = array(
'label' => new Diff( array(
'en' => new DiffOpAdd( 'foobar' ),
'de' => new DiffOpRemove( 'onoez' ),
'nl' => new DiffOpChange( 'foo', 'bar' ),
), true )
);
$diffs[] = new EntityDiff( $diffOps );
$diffOps['description'] = new Diff( array(
'en' => new DiffOpAdd( 'foobar' ),
'de' => new DiffOpRemove( 'onoez' ),
'nl' => new DiffOpChange( 'foo', 'bar' ),
), true );
$diffs[] = new EntityDiff( $diffOps );
$diffOps['aliases'] = new Diff( array(
'en' => new Diff( array( new DiffOpAdd( 'foobar' ), new DiffOpRemove( 'onoez' ) ), false ),
'de' => new Diff( array( new DiffOpRemove( 'foo' ) ), false ),
), true );
$diffs[] = new EntityDiff( $diffOps );
$statement = new Statement( new PropertyNoValueSnak( 42 ) );
$statement->setGuid( 'EntityDiffTest$foo' );
$statementListDiffer = new StatementListDiffer();
$diffOps['claim'] = $statementListDiffer->getDiff(
new StatementList( $statement ),
new StatementList()
);
$diffs[] = new EntityDiff( $diffOps );
$argLists = array();
foreach ( $diffs as $diff ) {
$argLists[] = array( $diff );
}
return $argLists;
}
/**
* @dataProvider diffProvider
*/
public function testGetClaimsDiff( EntityDiff $entityDiff ) {
$diff = $entityDiff->getClaimsDiff();
$this->assertInstanceOf( 'Diff\Diff', $diff );
$this->assertTrue( $diff->isAssociative() );
foreach ( $diff as $diffOp ) {
$this->assertTrue( $diffOp instanceof DiffOpAdd || $diffOp instanceof DiffOpRemove );
$statement = $diffOp instanceof DiffOpAdd ? $diffOp->getNewValue() : $diffOp->getOldValue();
$this->assertInstanceOf( 'Wikibase\DataModel\Statement\Statement', $statement );
}
}
/**
* @dataProvider diffProvider
*/
public function testGetDescriptionsDiff( EntityDiff $entityDiff ) {
$diff = $entityDiff->getDescriptionsDiff();
$this->assertInstanceOf( 'Diff\Diff', $diff );
$this->assertTrue( $diff->isAssociative() );
}
/**
* @dataProvider diffProvider
*/
public function testGetLabelsDiff( EntityDiff $entityDiff ) {
$diff = $entityDiff->getLabelsDiff();
$this->assertInstanceOf( 'Diff\Diff', $diff );
$this->assertTrue( $diff->isAssociative() );
}
/**
* @dataProvider diffProvider
*/
public function testGetAliasesDiff( EntityDiff $entityDiff ) {
$diff = $entityDiff->getAliasesDiff();
$this->assertInstanceOf( 'Diff\Diff', $diff );
$this->assertTrue( $diff->isAssociative() );
}
public function testGetType() {
$diff = new EntityDiff();
$this->assertSame( 'diff/entity', $diff->getType() );
}
}