Skip to content

Commit

Permalink
Add clear to list classes
Browse files Browse the repository at this point in the history
This is needed as a replacement for users of the holder interfaces to
remove all elements from one of the given list classes.

Bug: T128363
  • Loading branch information
Benestar authored and thiemowmde committed Mar 10, 2016
1 parent 5e642e3 commit 90ec73d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* `getByLangauge` now throws an `OutOfBoundsException`.
* `removeByLanguage` does nothing for invalid values.
* `hasTermForLanguage` and `hasGroupForLangauge` return false instead.
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`

## Version 5.1.0 (2016-03-08)

Expand Down
9 changes: 9 additions & 0 deletions src/Statement/StatementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ public function filter( StatementFilter $filter ) {
return $statementList;
}

/**
* Removes all statements from this list.
*
* @since 6.0
*/
public function clear() {
$this->statements = array();
}

/**
* @see http://php.net/manual/en/language.oop5.cloning.php
*
Expand Down
9 changes: 9 additions & 0 deletions src/Term/AliasGroupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,13 @@ public function toTextArray() {
return $array;
}

/**
* Removes all alias groups from this list.
*
* @since 6.0
*/
public function clear() {
$this->groups = array();
}

}
9 changes: 9 additions & 0 deletions src/Term/TermList.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,13 @@ public function hasTerm( Term $term ) {
&& $this->terms[$term->getLanguageCode()]->equals( $term );
}

/**
* Removes all terms from this list.
*
* @since 6.0
*/
public function clear() {
$this->terms = array();
}

}
10 changes: 10 additions & 0 deletions tests/unit/Statement/StatementListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,14 @@ public function testFilter() {
);
}

public function testClear() {
$statement1 = $this->getStatement( 1, null );
$statement2 = $this->getStatement( 2, null );
$statements = new StatementList( $statement1, $statement2 );

$statements->clear();

$this->assertEquals( new StatementList(), $statements );
}

}
10 changes: 10 additions & 0 deletions tests/unit/Term/AliasGroupListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,14 @@ public function testToTextArray() {
$this->assertEquals( $expected, $list->toTextArray() );
}

public function testClear() {
$list = new AliasGroupList();
$list->setAliasesForLanguage( 'en', array( 'foo', 'baz' ) );
$list->setAliasesForLanguage( 'de', array( 'bar' ) );

$list->clear();

$this->assertEquals( new AliasGroupList(), $list );
}

}
10 changes: 10 additions & 0 deletions tests/unit/Term/TermListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,14 @@ public function testGivenEmptyTerm_setTermRemovesExistingOne() {
);
}

public function testClear() {
$list = new TermList();
$list->setTextForLanguage( 'en', 'foo' );
$list->setTextForLanguage( 'de', 'bar' );

$list->clear();

$this->assertEquals( new TermList(), $list );
}

}

0 comments on commit 90ec73d

Please sign in to comment.