diff --git a/tests/unit/ReferenceListTest.php b/tests/unit/ReferenceListTest.php index 7f5440cd..a310b299 100644 --- a/tests/unit/ReferenceListTest.php +++ b/tests/unit/ReferenceListTest.php @@ -224,6 +224,24 @@ public function testAddReferenceAtIndexIgnoresIdenticalObjects() { $this->assertCount( 1, $list ); } + public function testAddReferenceAtIndexMovesIdenticalObjects() { + $list = new ReferenceList(); + $list->addNewReference( new PropertyNoValueSnak( 1 ) ); + $reference = new Reference( array( new PropertyNoValueSnak( 2 ) ) ); + $list->addReference( $reference ); + $this->assertSame( 1, $list->indexOf( $reference ), 'pre condition' ); + + $list->addReference( $reference, 0 ); + + $this->assertCount( 2, $list, 'not added' ); + $this->assertSame( 0, $list->indexOf( $reference ), 'can decrease index' ); + + $list->addReference( $reference, 2 ); + + $this->assertCount( 2, $list, 'not added' ); + $this->assertSame( 0, $list->indexOf( $reference ), 'can not increase index' ); + } + public function testAddReferenceAtIndexZero() { $reference1 = new Reference( array( new PropertyNoValueSnak( 1 ) ) ); $reference2 = new Reference( array( new PropertyNoValueSnak( 2 ) ) );