Passed
Push — deepCloning ( b0de0a...4428ab )
by no
03:40
created

EntityTest::testCloneEquality()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
nc 1
cc 1
eloc 5
nop 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Entity;
4
5
use Wikibase\DataModel\Entity\Entity;
6
use Wikibase\DataModel\Term\AliasGroup;
7
use Wikibase\DataModel\Term\AliasGroupList;
8
use Wikibase\DataModel\Term\Fingerprint;
9
use Wikibase\DataModel\Term\Term;
10
use Wikibase\DataModel\Term\TermList;
11
12
/**
13
 * @deprecated
14
 * This test class is to be phased out, and should not be used from outside of the component!
15
 *
16
 * @group Wikibase
17
 * @group WikibaseDataModel
18
 *
19
 * @licence GNU GPL v2+
20
 * @author Jeroen De Dauw < [email protected] >
21
 * @author Daniel Kinzler
22
 */
23
abstract class EntityTest extends \PHPUnit_Framework_TestCase {
24
25
	/**
26
	 * @since 0.1
27
	 *
28
	 * @return Entity
29
	 */
30
	protected abstract function getNewEmpty();
31
32
	public function labelProvider() {
33
		return array(
34
			array( 'en', 'spam' ),
35
			array( 'en', 'spam', 'spam' ),
36
			array( 'de', 'foo bar baz' ),
37
		);
38
	}
39
40
	/**
41
	 * @dataProvider labelProvider
42
	 * @param string $languageCode
43
	 * @param string $labelText
44
	 * @param string $moarText
45
	 */
46
	public function testSetLabel( $languageCode, $labelText, $moarText = 'ohi there' ) {
47
		$entity = $this->getNewEmpty();
48
49
		$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...
50
51
		$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...
52
53
		$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...
54
55
		$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...
56
	}
57
58
	/**
59
	 * @dataProvider labelProvider
60
	 * @param string $languageCode
61
	 * @param string $labelText
62
	 */
63
	public function testGetLabel( $languageCode, $labelText ) {
64
		$entity = $this->getNewEmpty();
65
66
		$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...
67
68
		$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...
69
70
		$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...
71
	}
72
73
	/**
74
	 * @dataProvider labelProvider
75
	 * @param string $languageCode
76
	 * @param string $labelText
77
	 */
78
	public function testRemoveLabel( $languageCode, $labelText ) {
79
		$entity = $this->getNewEmpty();
80
		$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...
81
		$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...
82
		$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...
83
	}
84
85
	public function descriptionProvider() {
86
		return array(
87
			array( 'en', 'spam' ),
88
			array( 'en', 'spam', 'spam' ),
89
			array( 'de', 'foo bar baz' ),
90
		);
91
	}
92
93
	/**
94
	 * @dataProvider descriptionProvider
95
	 * @param string $languageCode
96
	 * @param string $description
97
	 * @param string $moarText
98
	 */
99
	public function testSetDescription( $languageCode, $description, $moarText = 'ohi there' ) {
100
		$entity = $this->getNewEmpty();
101
102
		$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...
103
104
		$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...
105
106
		$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...
107
108
		$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...
109
	}
110
111
	/**
112
	 * @dataProvider descriptionProvider
113
	 * @param string $languageCode
114
	 * @param string $description
115
	 */
116
	public function testGetDescription( $languageCode, $description ) {
117
		$entity = $this->getNewEmpty();
118
119
		$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...
120
121
		$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...
122
123
		$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...
124
	}
125
126
	/**
127
	 * @dataProvider descriptionProvider
128
	 * @param string $languageCode
129
	 * @param string $description
130
	 */
131
	public function testRemoveDescription( $languageCode, $description ) {
132
		$entity = $this->getNewEmpty();
133
		$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...
134
		$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...
135
		$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...
136
	}
137
138
	public function aliasesProvider() {
139
		return array(
140
			array( array(
141
				'en' => array( array( 'spam' ) )
142
			) ),
143
			array( array(
144
				'en' => array( array( 'foo', 'bar', 'baz' ) )
145
			) ),
146
			array( array(
147
				'en' => array( array( 'foo', 'bar' ), array( 'baz', 'spam' ) )
148
			) ),
149
			array( array(
150
				'en' => array( array( 'foo', 'bar', 'baz' ) ),
151
				'de' => array( array( 'foobar' ), array( 'baz' ) ),
152
			) ),
153
			// with duplicates
154
			array( array(
155
				'en' => array( array( 'spam', 'ham', 'ham' ) )
156
			) ),
157
			array( array(
158
				'en' => array( array( 'foo', 'bar' ), array( 'bar', 'spam' ) )
159
			) ),
160
		);
161
	}
162
163
	/**
164
	 * @dataProvider aliasesProvider
165
	 */
166
	public function testAddAliases( array $aliasesLists ) {
167
		$entity = $this->getNewEmpty();
168
169
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
170
			foreach ( $aliasesList as $aliases ) {
171
				$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...
172
			}
173
		}
174
175
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
176
			$expected = array_values( array_unique( call_user_func_array( 'array_merge', $aliasesList ) ) );
177
			asort( $expected );
178
179
			$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...
180
			asort( $actual );
181
182
			$this->assertEquals( $expected, $actual );
183
		}
184
	}
185
186
	/**
187
	 * @dataProvider aliasesProvider
188
	 */
189
	public function testSetAliases( array $aliasesLists ) {
190
		$entity = $this->getNewEmpty();
191
192
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
193
			foreach ( $aliasesList as $aliases ) {
194
				$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...
195
			}
196
		}
197
198
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
199
			$expected = array_values( array_unique( array_pop( $aliasesList ) ) );
200
			asort( $aliasesList );
201
202
			$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...
203
			asort( $actual );
204
205
			$this->assertEquals( $expected, $actual );
206
		}
207
	}
208
209
	/**
210
	 * @dataProvider aliasesProvider
211
	 */
212
	public function testSetEmptyAlias( array $aliasesLists ) {
213
		$entity = $this->getNewEmpty();
214
215
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
216
			foreach ( $aliasesList as $aliases ) {
217
				$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...
218
			}
219
		}
220
		$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...
221
		$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...
222
223
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
224
			$expected = array_values( array_unique( array_pop( $aliasesList ) ) );
225
			asort( $aliasesList );
226
227
			$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...
228
			asort( $actual );
229
230
			$this->assertEquals( $expected, $actual );
231
		}
232
	}
233
234
	/**
235
	 * @dataProvider aliasesProvider
236
	 */
237
	public function testSetAllAliases( array $aliasGroups ) {
238
		$entity = $this->getNewEmpty();
239
		$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...
240
241
		$aliasesToSet = array();
242
		foreach ( $aliasGroups as $langCode => $aliasGroup ) {
243
			foreach ( $aliasGroup as $aliases ) {
244
				$aliasesToSet[$langCode] = $aliases;
245
			}
246
		}
247
248
		$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...
249
250
		foreach ( $aliasGroups as $langCode => $aliasGroup ) {
251
			$expected = array_values( array_unique( array_pop( $aliasGroup ) ) );
252
			asort( $aliasGroup );
253
254
			$actual = $entity->getFingerprint()->getAliasGroups()->getByLanguage( $langCode )->getAliases();
255
			asort( $actual );
256
257
			$this->assertEquals( $expected, $actual );
258
		}
259
260
		/** @var AliasGroup $aliasGroup */
261
		foreach ( $entity->getFingerprint()->getAliasGroups() as $langCode => $aliasGroup ) {
262
			$this->assertEquals( $aliasGroup->getAliases(), array_unique( $aliasesToSet[$langCode] ) );
263
		}
264
	}
265
266
	public function testGetAliases() {
267
		$entity = $this->getNewEmpty();
268
		$aliases = array( 'a', 'b' );
269
270
		$entity->getFingerprint()->setAliasGroup( 'en', $aliases );
271
272
		$this->assertEquals(
273
			$aliases,
274
			$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...
275
		);
276
	}
277
278
	public function duplicateAliasesProvider() {
279
		return array(
280
			array( array(
281
				'en' => array( array( 'foo', 'bar', 'baz' ), array( 'foo', 'bar', 'baz' ) )
282
			) ),
283
			array( array(
284
				'en' => array( array( 'foo', 'bar', 'baz' ), array( 'foo', 'bar' ) )
285
			) ),
286
			array( array(
287
				'en' => array( array( 'foo', 'bar' ), array( 'foo', 'bar', 'baz' ) )
288
			) ),
289
			array( array(
290
				'en' => array( array( 'foo', 'bar' ), array( 'bar', 'baz' ) ),
291
				'de' => array( array(), array( 'foo' ) ),
292
				'nl' => array( array( 'foo' ), array() ),
293
			) ),
294
			array( array(
295
				'en' => array( array( 'foo', 'bar', 'baz' ), array( 'foo', 'bar', 'baz', 'foo', 'bar' ) )
296
			) ),
297
		);
298
	}
299
300
	/**
301
	 * @dataProvider duplicateAliasesProvider
302
	 */
303
	public function testRemoveAliases( array $aliasesLists ) {
304
		$entity = $this->getNewEmpty();
305
306
		foreach ( $aliasesLists as $langCode => $aliasesList ) {
307
			$aliases = array_shift( $aliasesList );
308
			$removedAliases = array_shift( $aliasesList );
309
310
			$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...
311
			$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...
312
313
			$expected = array_values( array_diff( $aliases, $removedAliases ) );
314
			$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...
315
316
			asort( $expected );
317
			asort( $actual );
318
319
			$this->assertEquals( $expected, $actual );
320
		}
321
	}
322
323
	public function instanceProvider() {
324
		$entities = array();
325
326
		// empty
327
		$entity = $this->getNewEmpty();
328
		$entities[] = $entity;
329
330
		// ID only
331
		$entity = clone $entity;
332
		$entity->setId( 44 );
333
334
		$entities[] = $entity;
335
336
		// with labels and stuff
337
		$entity = $this->getNewEmpty();
338
		$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...
339
		$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...
340
		$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...
341
342
		$entities[] = $entity;
343
344
		// with labels etc and ID
345
		$entity = clone $entity;
346
		$entity->setId( 42 );
347
348
		$entities[] = $entity;
349
350
		$argLists = array();
351
352
		foreach ( $entities as $entity ) {
353
			$argLists[] = array( $entity );
354
		}
355
356
		return $argLists;
357
	}
358
359
	/**
360
	 * @dataProvider instanceProvider
361
	 * @param Entity $entity
362
	 */
363
	public function testSerialize( Entity $entity ) {
364
		$string = serialize( $entity );
365
366
		$this->assertInternalType( 'string', $string );
367
368
		$instance = unserialize( $string );
369
370
		$this->assertTrue( $entity->equals( $instance ) );
371
		$this->assertEquals( $entity->getId(), $instance->getId() );
372
	}
373
374
	public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() {
375
		$entity = $this->getNewEmpty();
376
377
		$this->assertEquals(
378
			new Fingerprint(),
379
			$entity->getFingerprint()
380
		);
381
	}
382
383
	public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels() {
384
		$entity = $this->getNewEmpty();
385
386
		$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...
387
		$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...
388
389
		$this->assertEquals(
390
			new Fingerprint(
391
				new TermList( array(
392
					new Term( 'en', 'foo' ),
393
					new Term( 'de', 'bar' ),
394
				) )
395
			),
396
			$entity->getFingerprint()
397
		);
398
	}
399
400
	public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms() {
401
		$entity = $this->getNewEmpty();
402
403
		$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...
404
		$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...
405
		$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...
406
407
		$this->assertEquals(
408
			new Fingerprint(
409
				new TermList( array(
410
					new Term( 'en', 'foo' ),
411
				) ),
412
				new TermList( array(
413
					new Term( 'en', 'foo bar' )
414
				) ),
415
				new AliasGroupList( array(
416
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
417
				) )
418
			),
419
			$entity->getFingerprint()
420
		);
421
	}
422
423
	public function testGivenEmptyFingerprint_noTermsAreSet() {
424
		$entity = $this->getNewEmpty();
425
		$entity->setFingerprint( new Fingerprint() );
426
427
		$this->assertHasNoTerms( $entity );
428
	}
429
430
	private function assertHasNoTerms( Entity $entity ) {
431
		$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...
432
		$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...
433
		$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...
434
	}
435
436
	public function testGivenEmptyFingerprint_existingTermsAreRemoved() {
437
		$entity = $this->getNewEmpty();
438
439
		$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...
440
		$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...
441
		$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...
442
443
		$entity->setFingerprint( new Fingerprint() );
444
445
		$this->assertHasNoTerms( $entity );
446
	}
447
448
	public function testWhenSettingFingerprint_getFingerprintReturnsIt() {
449
		$fingerprint = new Fingerprint(
450
			new TermList( array(
451
				new Term( 'en', 'english label' ),
452
			) ),
453
			new TermList( array(
454
				new Term( 'en', 'english description' )
455
			) ),
456
			new AliasGroupList( array(
457
				new AliasGroup( 'en', array( 'first en alias', 'second en alias' ) )
458
			) )
459
		);
460
461
		$entity = $this->getNewEmpty();
462
		$entity->setFingerprint( $fingerprint );
463
		$newFingerprint = $entity->getFingerprint();
464
465
		$this->assertEquals( $fingerprint, $newFingerprint );
466
	}
467
468
}
469