summaryrefslogtreecommitdiff
path: root/framework/Collections/TList.php
diff options
context:
space:
mode:
authorjavalizard <>2010-09-27 04:52:42 +0000
committerjavalizard <>2010-09-27 04:52:42 +0000
commitac27dc3f3db931cb59e9318a1d69bc683d45b332 (patch)
treebe1d2adb6c4285be1d997f316f353165bc8c8a26 /framework/Collections/TList.php
parent546221db4bcf502c3b5744a438d09cbf9df43070 (diff)
#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.
Diffstat (limited to 'framework/Collections/TList.php')
-rw-r--r--framework/Collections/TList.php47
1 files changed, 31 insertions, 16 deletions
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));
}
/**