File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Wikibase DataModel release notes
22
3- ## Version 5.0 (dev)
4-
5- #### Breaking changes
6-
7- * Removed ` Entity::copy `
8-
93## Version 4.0 (2015-07-28)
104
115#### Breaking changes
Original file line number Diff line number Diff line change @@ -288,6 +288,18 @@ public function setAllAliases( array $aliasLists ) {
288288 }
289289 }
290290
291+ /**
292+ * Returns a deep copy of the entity.
293+ *
294+ * @since 0.1
295+ * @deprecated since 1.0
296+ *
297+ * @return self
298+ */
299+ public function copy () {
300+ return unserialize ( serialize ( $ this ) );
301+ }
302+
291303 /**
292304 * @since 0.3
293305 * @deprecated since 1.0, use getStatements()->toArray() instead.
Original file line number Diff line number Diff line change @@ -360,6 +360,32 @@ public function instanceProvider() {
360360 return $ argLists ;
361361 }
362362
363+ /**
364+ * @dataProvider instanceProvider
365+ * @param Entity $entity
366+ */
367+ public function testCopy ( Entity $ entity ) {
368+ $ copy = $ entity ->copy ();
369+
370+ // The equality method alone is not enough since it does not check the IDs.
371+ $ this ->assertTrue ( $ entity ->equals ( $ copy ) );
372+ $ this ->assertEquals ( $ entity ->getId (), $ copy ->getId () );
373+
374+ $ this ->assertFalse ( $ entity === $ copy );
375+ }
376+
377+ public function testCopyRetainsLabels () {
378+ $ item = new Item ();
379+
380+ $ item ->getFingerprint ()->setLabel ( 'en ' , 'foo ' );
381+ $ item ->getFingerprint ()->setLabel ( 'de ' , 'bar ' );
382+
383+ $ newItem = unserialize ( serialize ( $ item ) );
384+
385+ $ this ->assertTrue ( $ newItem ->getFingerprint ()->getLabels ()->hasTermForLanguage ( 'en ' ) );
386+ $ this ->assertTrue ( $ newItem ->getFingerprint ()->getLabels ()->hasTermForLanguage ( 'de ' ) );
387+ }
388+
363389 /**
364390 * @dataProvider instanceProvider
365391 * @param Entity $entity
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ public function itemProvider() {
8080 $ items [] = $ item ;
8181
8282 /** @var Item $item */
83- $ item = unserialize ( serialize ( $ item ) );
83+ $ item = $ item-> copy ( );
8484 $ item ->getStatements ()->addNewStatement (
8585 new PropertyNoValueSnak ( new PropertyId ( 'P42 ' ) )
8686 );
You can’t perform that action at this time.
0 commit comments