Passed
Push — deepCloning ( b0de0a )
by no
03:44
created

EntityTest::duplicateAliasesProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
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
	 */
363
	public function testCloneEquality( Entity $entity ) {
364
		$clone = clone $entity;
365
366
		// The equality method alone is not enough since it does not check the IDs.
367
		$this->assertTrue( $entity->equals( $clone ) );
368
		$this->assertEquals( $entity->getId(), $clone->getId() );
369
370
		$this->assertNotSame( $entity, $clone );
371
	}
372
373
	public function testCloneRetainsLabels() {
374
		$item = new Item();
375
376
		$item->getFingerprint()->setLabel( 'en', 'foo' );
377
		$item->getFingerprint()->setLabel( 'de', 'bar' );
378
379
		$newItem = clone $item;
380
381
		$this->assertTrue( $newItem->getFingerprint()->getLabels()->hasTermForLanguage( 'en' ) );
382
		$this->assertTrue( $newItem->getFingerprint()->getLabels()->hasTermForLanguage( 'de' ) );
383
	}
384
385
	/**
386
	 * @dataProvider instanceProvider
387
	 * @param Entity $entity
388
	 */
389
	public function testSerialize( Entity $entity ) {
390
		$string = serialize( $entity );
391
392
		$this->assertInternalType( 'string', $string );
393
394
		$instance = unserialize( $string );
395
396
		$this->assertTrue( $entity->equals( $instance ) );
397
		$this->assertEquals( $entity->getId(), $instance->getId() );
398
	}
399
400
	public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() {
401
		$entity = $this->getNewEmpty();
402
403
		$this->assertEquals(
404
			new Fingerprint(),
405
			$entity->getFingerprint()
406
		);
407
	}
408
409
	public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels() {
410
		$entity = $this->getNewEmpty();
411
412
		$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...
413
		$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...
414
415
		$this->assertEquals(
416
			new Fingerprint(
417
				new TermList( array(
418
					new Term( 'en', 'foo' ),
419
					new Term( 'de', 'bar' ),
420
				) )
421
			),
422
			$entity->getFingerprint()
423
		);
424
	}
425
426
	public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms() {
427
		$entity = $this->getNewEmpty();
428
429
		$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...
430
		$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...
431
		$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...
432
433
		$this->assertEquals(
434
			new Fingerprint(
435
				new TermList( array(
436
					new Term( 'en', 'foo' ),
437
				) ),
438
				new TermList( array(
439
					new Term( 'en', 'foo bar' )
440
				) ),
441
				new AliasGroupList( array(
442
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
443
				) )
444
			),
445
			$entity->getFingerprint()
446
		);
447
	}
448
449
	public function testGivenEmptyFingerprint_noTermsAreSet() {
450
		$entity = $this->getNewEmpty();
451
		$entity->setFingerprint( new Fingerprint() );
452
453
		$this->assertHasNoTerms( $entity );
454
	}
455
456
	private function assertHasNoTerms( Entity $entity ) {
457
		$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...
458
		$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...
459
		$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...
460
	}
461
462
	public function testGivenEmptyFingerprint_existingTermsAreRemoved() {
463
		$entity = $this->getNewEmpty();
464
465
		$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...
466
		$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...
467
		$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...
468
469
		$entity->setFingerprint( new Fingerprint() );
470
471
		$this->assertHasNoTerms( $entity );
472
	}
473
474
	public function testWhenSettingFingerprint_getFingerprintReturnsIt() {
475
		$fingerprint = new Fingerprint(
476
			new TermList( array(
477
				new Term( 'en', 'english label' ),
478
			) ),
479
			new TermList( array(
480
				new Term( 'en', 'english description' )
481
			) ),
482
			new AliasGroupList( array(
483
				new AliasGroup( 'en', array( 'first en alias', 'second en alias' ) )
484
			) )
485
		);
486
487
		$entity = $this->getNewEmpty();
488
		$entity->setFingerprint( $fingerprint );
489
		$newFingerprint = $entity->getFingerprint();
490
491
		$this->assertEquals( $fingerprint, $newFingerprint );
492
	}
493
494
}
495