Skip to content

Commit

Permalink
Merge pull request #641 from wmde/atIndexRegression
Browse files Browse the repository at this point in the history
Test 4.x behavior of ReferenceList::addReference at index
  • Loading branch information
Benestar committed Mar 10, 2016
2 parents 59ec644 + 4fecfa8 commit 5e642e3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/unit/ReferenceListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
Expand Down

0 comments on commit 5e642e3

Please sign in to comment.