From ac27dc3f3db931cb59e9318a1d69bc683d45b332 Mon Sep 17 00:00:00 2001 From: javalizard <> Date: Mon, 27 Sep 2010 04:52:42 +0000 Subject: #291 Added new unit tests for all edit operations on read-only lists. Added a read-only conditional prior to the item search within three functions that search for an item index in the TList prior to editing. --- framework/Collections/TList.php | 47 +++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'framework') diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php index 8d9fd033..aff21d33 100644 --- a/framework/Collections/TList.php +++ b/framework/Collections/TList.php @@ -175,13 +175,18 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl */ public function remove($item) { - if(($index=$this->indexOf($item))>=0) + if(!$this->_r) { - $this->removeAt($index); - return $index; + if(($index=$this->indexOf($item))>=0) + { + $this->removeAt($index); + return $index; + } + else + throw new TInvalidDataValueException('list_item_inexistent'); } else - throw new TInvalidDataValueException('list_item_inexistent'); + throw new TInvalidOperationException('list_readonly',get_class($this)); } /** @@ -253,12 +258,17 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl */ public function insertBefore($baseitem, $item) { - if(($index = $this->indexOf($baseitem)) == -1) - throw new TInvalidDataValueException('list_item_inexistent'); - - $this->insertAt($index, $item); - - return $index; + if(!$this->_r) + { + if(($index = $this->indexOf($baseitem)) == -1) + throw new TInvalidDataValueException('list_item_inexistent'); + + $this->insertAt($index, $item); + + return $index; + } + else + throw new TInvalidOperationException('list_readonly',get_class($this)); } /** @@ -270,12 +280,17 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl */ public function insertAfter($baseitem, $item) { - if(($index = $this->indexOf($baseitem)) == -1) - throw new TInvalidDataValueException('list_item_inexistent'); - - $this->insertAt($index + 1, $item); - - return $index + 1; + if(!$this->_r) + { + if(($index = $this->indexOf($baseitem)) == -1) + throw new TInvalidDataValueException('list_item_inexistent'); + + $this->insertAt($index + 1, $item); + + return $index + 1; + } + else + throw new TInvalidOperationException('list_readonly',get_class($this)); } /** -- cgit v1.2.3