Skip to content

Commit 4fecfa8

Browse files
committed
Restore 4.4 behavior of ReferenceList::addReference at index
1 parent 59ec644 commit 4fecfa8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/unit/ReferenceListTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ public function testAddReferenceAtIndexIgnoresIdenticalObjects() {
224224
$this->assertCount( 1, $list );
225225
}
226226

227+
public function testAddReferenceAtIndexMovesIdenticalObjects() {
228+
$list = new ReferenceList();
229+
$list->addNewReference( new PropertyNoValueSnak( 1 ) );
230+
$reference = new Reference( array( new PropertyNoValueSnak( 2 ) ) );
231+
$list->addReference( $reference );
232+
$this->assertSame( 1, $list->indexOf( $reference ), 'pre condition' );
233+
234+
$list->addReference( $reference, 0 );
235+
236+
$this->assertCount( 2, $list, 'not added' );
237+
$this->assertSame( 0, $list->indexOf( $reference ), 'can decrease index' );
238+
239+
$list->addReference( $reference, 2 );
240+
241+
$this->assertCount( 2, $list, 'not added' );
242+
$this->assertSame( 0, $list->indexOf( $reference ), 'can not increase index' );
243+
}
244+
227245
public function testAddReferenceAtIndexZero() {
228246
$reference1 = new Reference( array( new PropertyNoValueSnak( 1 ) ) );
229247
$reference2 = new Reference( array( new PropertyNoValueSnak( 2 ) ) );

0 commit comments

Comments
 (0)