Passed
Push — refactor-referencelist ( 826e0b...168ca5 )
by Jeroen De
18:44 queued 15:47
created

EntityTest::testGetClaims()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Entity;
4
5
use Wikibase\DataModel\Entity\Entity;
6
use Wikibase\DataModel\Entity\Item;
7
use Wikibase\DataModel\Term\AliasGroup;
8
use Wikibase\DataModel\Term\AliasGroupList;
9
use Wikibase\DataModel\Term\Fingerprint;
10
use Wikibase\DataModel\Term\Term;
11
use Wikibase\DataModel\Term\TermList;
12
13
/**
14
 * @deprecated
15
 * This test class is to be phased out, and should not be used from outside of the component!
16
 *
17
 * @group Wikibase
18
 * @group WikibaseDataModel
19
 *
20
 * @licence GNU GPL v2+
21
 * @author Jeroen De Dauw < [email protected] >
22
 * @author Daniel Kinzler
23
 */
24
abstract class EntityTest extends \PHPUnit_Framework_TestCase {
25
26
	/**
27
	 * @since 0.1
28
	 *
29
	 * @return Entity
30
	 */
31
	protected abstract function getNewEmpty();
32
33
	public function labelProvider() {
34
		return array(
35
			array( 'en', 'spam' ),
36
			array( 'en', 'spam', 'spam' ),
37
			array( 'de', 'foo bar baz' ),
38
		);
39
	}
40
41
	/**
42
	 * @dataProvider labelProvider
43
	 * @param string $languageCode
44
	 * @param string $labelText
45
	 * @param string $moarText
46
	 */
47
	public function testSetLabel( $languageCode, $labelText, $moarText = 'ohi there' ) {
48
		$entity = $this->getNewEmpty();
49
50
		$entity->setLabel( $languageCode, $labelText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
51
52
		$this->assertEquals( $labelText, $entity->getLabel( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
53
54
		$entity->setLabel( $languageCode, $moarText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
55
56
		$this->assertEquals( $moarText, $entity->getLabel( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
57
	}
58
59
	/**
60
	 * @dataProvider labelProvider
61
	 * @param string $languageCode
62
	 * @param string $labelText
63
	 */
64
	public function testGetLabel( $languageCode, $labelText ) {
65
		$entity = $this->getNewEmpty();
66
67
		$this->assertFalse( $entity->getLabel( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
68
69
		$entity->setLabel( $languageCode, $labelText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
70
71
		$this->assertEquals( $labelText, $entity->getLabel( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
72
	}
73
74
	/**
75
	 * @dataProvider labelProvider
76
	 * @param string $languageCode
77
	 * @param string $labelText
78
	 */
79
	public function testRemoveLabel( $languageCode, $labelText ) {
80
		$entity = $this->getNewEmpty();
81
		$entity->setLabel( $languageCode, $labelText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
82
		$entity->removeLabel( $languageCode );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::removeLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
83
		$this->assertFalse( $entity->getLabel( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
84
	}
85
86
	public function descriptionProvider() {
87
		return array(
88
			array( 'en', 'spam' ),
89
			array( 'en', 'spam', 'spam' ),
90
			array( 'de', 'foo bar baz' ),
91
		);
92
	}
93
94
	/**
95
	 * @dataProvider descriptionProvider
96
	 * @param string $languageCode
97
	 * @param string $description
98
	 * @param string $moarText
99
	 */
100
	public function testSetDescription( $languageCode, $description, $moarText = 'ohi there' ) {
101
		$entity = $this->getNewEmpty();
102
103
		$entity->setDescription( $languageCode, $description );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
104
105
		$this->assertEquals( $description, $entity->getDescription( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
106
107
		$entity->setDescription( $languageCode, $moarText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
108
109
		$this->assertEquals( $moarText, $entity->getDescription( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
110
	}
111
112
	/**
113
	 * @dataProvider descriptionProvider
114
	 * @param string $languageCode
115
	 * @param string $description
116
	 */
117
	public function testGetDescription( $languageCode, $description ) {
118
		$entity = $this->getNewEmpty();
119
120
		$this->assertFalse( $entity->getDescription( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
121
122
		$entity->setDescription( $languageCode, $description );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
123
124
		$this->assertEquals( $description, $entity->getDescription( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
125
	}
126
127
	/**
128
	 * @dataProvider descriptionProvider
129
	 * @param string $languageCode
130
	 * @param string $description
131
	 */
132
	public function testRemoveDescription( $languageCode, $description ) {
133
		$entity = $this->getNewEmpty();
134
		$entity->setDescription( $languageCode, $description );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
135
		$entity->removeDescription( $languageCode );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entit...ty::removeDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
136
		$this->assertFalse( $entity->getDescription( $languageCode ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
137
	}
138
139
	public function aliasesProvider() {
140
		return array(
141
			array( array(
142
				'en' => array( array( 'spam' ) )
143
			) ),
144
			array( array(
145
				'en' => array( array( 'foo', 'bar', 'baz' ) )
146
			) ),
147
			array( array(
148
				'en' => array( array( 'foo', 'bar' ), array( 'baz', 'spam' ) )
149
			) ),
150
			array( array(
151
				'en' => array( array( 'foo', 'bar', 'baz' ) ),
152
				'de' => array( array( 'foobar' ), array( 'baz' ) ),
153
			) ),
154
			// with duplicates
155
			array( array(
156
				'en' => array( array( 'spam', 'ham', 'ham' ) )
157
			) ),
158
			array( array(
159
				'en' => array( array( 'foo', 'bar' ), array( 'bar', 'spam' ) )
160
			) ),
161
		);
162
	}
163
164
	/**
165
	 * @dataProvider aliasesProvider
166
	 */
167
	public function testAddAliases( array $aliasesLists ) {
168
		$entity = $this->getNewEmpty();
169
170
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
171
			foreach ( $aliasesList as $aliases ) {
172
				$entity->addAliases( $langCode, $aliases );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::addAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
173
			}
174
		}
175
176
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
177
			$expected = array_values( array_unique( call_user_func_array( 'array_merge', $aliasesList ) ) );
178
			asort( $expected );
179
180
			$actual = $entity->getAliases( $langCode );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
181
			asort( $actual );
182
183
			$this->assertEquals( $expected, $actual );
184
		}
185
	}
186
187
	/**
188
	 * @dataProvider aliasesProvider
189
	 */
190
	public function testSetAliases( array $aliasesLists ) {
191
		$entity = $this->getNewEmpty();
192
193
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
194
			foreach ( $aliasesList as $aliases ) {
195
				$entity->setAliases( $langCode, $aliases );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
196
			}
197
		}
198
199
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
200
			$expected = array_values( array_unique( array_pop( $aliasesList ) ) );
201
			asort( $aliasesList );
202
203
			$actual = $entity->getAliases( $langCode );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
204
			asort( $actual );
205
206
			$this->assertEquals( $expected, $actual );
207
		}
208
	}
209
210
	/**
211
	 * @dataProvider aliasesProvider
212
	 */
213
	public function testSetEmptyAlias( array $aliasesLists ) {
214
		$entity = $this->getNewEmpty();
215
216
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
217
			foreach ( $aliasesList as $aliases ) {
218
				$entity->setAliases( $langCode, $aliases );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
219
			}
220
		}
221
		$entity->setAliases( 'zh', array( 'wind', 'air', '', 'fire' ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
222
		$entity->setAliases( 'zu', array( '', '' ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
223
224
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
225
			$expected = array_values( array_unique( array_pop( $aliasesList ) ) );
226
			asort( $aliasesList );
227
228
			$actual = $entity->getAliases( $langCode );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
229
			asort( $actual );
230
231
			$this->assertEquals( $expected, $actual );
232
		}
233
	}
234
235
	/**
236
	 * @dataProvider aliasesProvider
237
	 */
238
	public function testSetAllAliases( array $aliasGroups ) {
239
		$entity = $this->getNewEmpty();
240
		$entity->addAliases( 'zh', array( 'qwertyuiop123', '321poiuytrewq' ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::addAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
241
242
		$aliasesToSet = array();
243
		foreach ( $aliasGroups as $langCode => $aliasGroup ) {
244
			foreach ( $aliasGroup as $aliases ) {
245
				$aliasesToSet[$langCode] = $aliases;
246
			}
247
		}
248
249
		$entity->setAllAliases( $aliasesToSet );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAllAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
250
251
		foreach ( $aliasGroups as $langCode => $aliasGroup ) {
252
			$expected = array_values( array_unique( array_pop( $aliasGroup ) ) );
253
			asort( $aliasGroup );
254
255
			$actual = $entity->getFingerprint()->getAliasGroups()->getByLanguage( $langCode )->getAliases();
256
			asort( $actual );
257
258
			$this->assertEquals( $expected, $actual );
259
		}
260
261
		/** @var AliasGroup $aliasGroup */
262
		foreach ( $entity->getFingerprint()->getAliasGroups() as $langCode => $aliasGroup ) {
263
			$this->assertEquals( $aliasGroup->getAliases(), array_unique( $aliasesToSet[$langCode] ) );
264
		}
265
	}
266
267
	public function testGetAliases() {
268
		$entity = $this->getNewEmpty();
269
		$aliases = array( 'a', 'b' );
270
271
		$entity->getFingerprint()->setAliasGroup( 'en', $aliases );
272
273
		$this->assertEquals(
274
			$aliases,
275
			$entity->getAliases( 'en' )
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
276
		);
277
	}
278
279
	public function duplicateAliasesProvider() {
280
		return array(
281
			array( array(
282
				'en' => array( array( 'foo', 'bar', 'baz' ), array( 'foo', 'bar', 'baz' ) )
283
			) ),
284
			array( array(
285
				'en' => array( array( 'foo', 'bar', 'baz' ), array( 'foo', 'bar' ) )
286
			) ),
287
			array( array(
288
				'en' => array( array( 'foo', 'bar' ), array( 'foo', 'bar', 'baz' ) )
289
			) ),
290
			array( array(
291
				'en' => array( array( 'foo', 'bar' ), array( 'bar', 'baz' ) ),
292
				'de' => array( array(), array( 'foo' ) ),
293
				'nl' => array( array( 'foo' ), array() ),
294
			) ),
295
			array( array(
296
				'en' => array( array( 'foo', 'bar', 'baz' ), array( 'foo', 'bar', 'baz', 'foo', 'bar' ) )
297
			) ),
298
		);
299
	}
300
301
	/**
302
	 * @dataProvider duplicateAliasesProvider
303
	 */
304
	public function testRemoveAliases( array $aliasesLists ) {
305
		$entity = $this->getNewEmpty();
306
307
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
308
			$aliases = array_shift( $aliasesList );
309
			$removedAliases = array_shift( $aliasesList );
310
311
			$entity->setAliases( $langCode, $aliases );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
312
			$entity->removeAliases( $langCode, $removedAliases );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::removeAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
313
314
			$expected = array_values( array_diff( $aliases, $removedAliases ) );
315
			$actual = $entity->getAliases( $langCode );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
316
317
			asort( $expected );
318
			asort( $actual );
319
320
			$this->assertEquals( $expected, $actual );
321
		}
322
	}
323
324
	public function instanceProvider() {
325
		$entities = array();
326
327
		// empty
328
		$entity = $this->getNewEmpty();
329
		$entities[] = $entity;
330
331
		// ID only
332
		$entity = clone $entity;
333
		$entity->setId( 44 );
334
335
		$entities[] = $entity;
336
337
		// with labels and stuff
338
		$entity = $this->getNewEmpty();
339
		$entity->setAliases( 'en', array( 'o', 'noez' ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
340
		$entity->setLabel( 'de', 'spam' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
341
		$entity->setDescription( 'en', 'foo bar baz' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
342
343
		$entities[] = $entity;
344
345
		// with labels etc and ID
346
		$entity = clone $entity;
347
		$entity->setId( 42 );
348
349
		$entities[] = $entity;
350
351
		$argLists = array();
352
353
		foreach ( $entities as $entity ) {
354
			$argLists[] = array( $entity );
355
		}
356
357
		return $argLists;
358
	}
359
360
	/**
361
	 * @dataProvider instanceProvider
362
	 * @param Entity $entity
363
	 */
364
	public function testCopy( Entity $entity ) {
365
		$copy = $entity->copy();
366
367
		// The equality method alone is not enough since it does not check the IDs.
368
		$this->assertTrue( $entity->equals( $copy ) );
369
		$this->assertEquals( $entity->getId(), $copy->getId() );
370
371
		$this->assertNotSame( $entity, $copy );
372
	}
373
374
	public function testCopyRetainsLabels() {
375
		$item = new Item();
376
377
		$item->getFingerprint()->setLabel( 'en', 'foo' );
378
		$item->getFingerprint()->setLabel( 'de', 'bar' );
379
380
		$newItem = $item->copy();
381
382
		$this->assertTrue( $newItem->getFingerprint()->getLabels()->hasTermForLanguage( 'en' ) );
383
		$this->assertTrue( $newItem->getFingerprint()->getLabels()->hasTermForLanguage( 'de' ) );
384
	}
385
386
	/**
387
	 * @dataProvider instanceProvider
388
	 * @param Entity $entity
389
	 */
390
	public function testSerialize( Entity $entity ) {
391
		$string = serialize( $entity );
392
393
		$this->assertInternalType( 'string', $string );
394
395
		$instance = unserialize( $string );
396
397
		$this->assertTrue( $entity->equals( $instance ) );
398
		$this->assertEquals( $entity->getId(), $instance->getId() );
399
	}
400
401
	public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() {
402
		$entity = $this->getNewEmpty();
403
404
		$this->assertEquals(
405
			new Fingerprint(),
406
			$entity->getFingerprint()
407
		);
408
	}
409
410
	public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels() {
411
		$entity = $this->getNewEmpty();
412
413
		$entity->setLabel( 'en', 'foo' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
414
		$entity->setLabel( 'de', 'bar' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
415
416
		$this->assertEquals(
417
			new Fingerprint(
418
				new TermList( array(
419
					new Term( 'en', 'foo' ),
420
					new Term( 'de', 'bar' ),
421
				) )
422
			),
423
			$entity->getFingerprint()
424
		);
425
	}
426
427
	public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms() {
428
		$entity = $this->getNewEmpty();
429
430
		$entity->setLabel( 'en', 'foo' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
431
		$entity->setDescription( 'en', 'foo bar' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
432
		$entity->setAliases( 'en', array( 'foo', 'bar' ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
433
434
		$this->assertEquals(
435
			new Fingerprint(
436
				new TermList( array(
437
					new Term( 'en', 'foo' ),
438
				) ),
439
				new TermList( array(
440
					new Term( 'en', 'foo bar' )
441
				) ),
442
				new AliasGroupList( array(
443
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
444
				) )
445
			),
446
			$entity->getFingerprint()
447
		);
448
	}
449
450
	public function testGivenEmptyFingerprint_noTermsAreSet() {
451
		$entity = $this->getNewEmpty();
452
		$entity->setFingerprint( new Fingerprint() );
453
454
		$this->assertHasNoTerms( $entity );
455
	}
456
457
	private function assertHasNoTerms( Entity $entity ) {
458
		$this->assertEquals( array(), $entity->getLabels() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getLabels() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
459
		$this->assertEquals( array(), $entity->getDescriptions() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entit...tity::getDescriptions() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
460
		$this->assertEquals( array(), $entity->getAllAliases() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAllAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
461
	}
462
463
	public function testGivenEmptyFingerprint_existingTermsAreRemoved() {
464
		$entity = $this->getNewEmpty();
465
466
		$entity->setLabel( 'en', 'foo' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
467
		$entity->setDescription( 'en', 'foo bar' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
468
		$entity->setAliases( 'en', array( 'foo', 'bar' ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
469
470
		$entity->setFingerprint( new Fingerprint() );
471
472
		$this->assertHasNoTerms( $entity );
473
	}
474
475
	public function testWhenSettingFingerprint_getFingerprintReturnsIt() {
476
		$fingerprint = new Fingerprint(
477
			new TermList( array(
478
				new Term( 'en', 'english label' ),
479
			) ),
480
			new TermList( array(
481
				new Term( 'en', 'english description' )
482
			) ),
483
			new AliasGroupList( array(
484
				new AliasGroup( 'en', array( 'first en alias', 'second en alias' ) )
485
			) )
486
		);
487
488
		$entity = $this->getNewEmpty();
489
		$entity->setFingerprint( $fingerprint );
490
		$newFingerprint = $entity->getFingerprint();
491
492
		$this->assertEquals( $fingerprint, $newFingerprint );
493
	}
494
495
}
496