From 99edc1f0fd100398c190cad25db04c529020031b Mon Sep 17 00:00:00 2001 From: Bene Date: Mon, 29 Feb 2016 16:23:57 +0100 Subject: [PATCH] Add clear to list classes 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 --- RELEASE-NOTES.md | 1 + src/Statement/StatementList.php | 9 +++++++++ src/Term/AliasGroupList.php | 9 +++++++++ src/Term/TermList.php | 9 +++++++++ tests/unit/Statement/StatementListTest.php | 10 ++++++++++ tests/unit/Term/AliasGroupListTest.php | 10 ++++++++++ tests/unit/Term/TermListTest.php | 10 ++++++++++ 7 files changed, 58 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 850d75c7..2b3e968a 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -11,6 +11,7 @@ * Removed `HashArray::indicesAreUpToDate` * Removed `HashArray::removeDuplicates` * Removed `$acceptDuplicates` feature from `HashArray` +* Added `clear` to `TermList`, `AliasGroupList` and `StatementList` ## Version 6.3.1 (2016-11-30) diff --git a/src/Statement/StatementList.php b/src/Statement/StatementList.php index 8802a1b7..ea79ef69 100644 --- a/src/Statement/StatementList.php +++ b/src/Statement/StatementList.php @@ -341,6 +341,15 @@ public function filter( StatementFilter $filter ) { return $statementList; } + /** + * Removes all statements from this list. + * + * @since 6.0 + */ + public function clear() { + $this->statements = []; + } + /** * @see http://php.net/manual/en/language.oop5.cloning.php * diff --git a/src/Term/AliasGroupList.php b/src/Term/AliasGroupList.php index 204f40b1..33cc8eb0 100644 --- a/src/Term/AliasGroupList.php +++ b/src/Term/AliasGroupList.php @@ -204,4 +204,13 @@ public function toTextArray() { return $array; } + /** + * Removes all alias groups from this list. + * + * @since 6.0 + */ + public function clear() { + $this->groups = []; + } + } diff --git a/src/Term/TermList.php b/src/Term/TermList.php index 3ba47f24..4f6b0fa8 100644 --- a/src/Term/TermList.php +++ b/src/Term/TermList.php @@ -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 = []; + } + } diff --git a/tests/unit/Statement/StatementListTest.php b/tests/unit/Statement/StatementListTest.php index 26d7e9a8..e4005b63 100644 --- a/tests/unit/Statement/StatementListTest.php +++ b/tests/unit/Statement/StatementListTest.php @@ -702,4 +702,14 @@ public function testFilter() { ); } + public function testClear() { + $statement1 = $this->getStatement( 'P1', null ); + $statement2 = $this->getStatement( 'P2', null ); + $statements = new StatementList( $statement1, $statement2 ); + + $statements->clear(); + + $this->assertEquals( new StatementList(), $statements ); + } + } diff --git a/tests/unit/Term/AliasGroupListTest.php b/tests/unit/Term/AliasGroupListTest.php index 27ce4a37..dc746dfc 100644 --- a/tests/unit/Term/AliasGroupListTest.php +++ b/tests/unit/Term/AliasGroupListTest.php @@ -383,4 +383,14 @@ public function testToTextArray() { $this->assertEquals( $expected, $list->toTextArray() ); } + public function testClear() { + $list = new AliasGroupList(); + $list->setAliasesForLanguage( 'en', [ 'foo', 'baz' ] ); + $list->setAliasesForLanguage( 'de', [ 'bar' ] ); + + $list->clear(); + + $this->assertEquals( new AliasGroupList(), $list ); + } + } diff --git a/tests/unit/Term/TermListTest.php b/tests/unit/Term/TermListTest.php index 50e00a15..a1ab16c1 100644 --- a/tests/unit/Term/TermListTest.php +++ b/tests/unit/Term/TermListTest.php @@ -396,4 +396,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 ); + } + }