From e9812a0e6c07379f565f1ae6d0df1f2426cc13c6 Mon Sep 17 00:00:00 2001 From: Grundik Date: Thu, 16 Oct 2014 06:35:33 +0400 Subject: [PATCH 1/6] Trying to fix #6768: allowing false values in PriorityList --- library/Zend/Stdlib/PriorityList.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/Zend/Stdlib/PriorityList.php b/library/Zend/Stdlib/PriorityList.php index 1664e193280..1dce67ba92a 100644 --- a/library/Zend/Stdlib/PriorityList.php +++ b/library/Zend/Stdlib/PriorityList.php @@ -54,6 +54,13 @@ class PriorityList implements Iterator, Countable */ protected $sorted = false; + /** + * Holds current node, false if current() was invalid + * + * @var mixed + */ + protected $currentNode = false; + /** * Insert a new item. * @@ -193,6 +200,7 @@ public function rewind() public function current() { $node = current($this->items); + $this->currentNode = $node; return ($node !== false ? $node['data'] : false); } @@ -227,7 +235,8 @@ public function next() */ public function valid() { - return ($this->current() !== false); + $this->current(); + return ($this->currentNode !== false); } /** From c77bbe7a9ac77abe33abbb3c39f72109fa5470c2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 16 Oct 2014 07:05:08 +0700 Subject: [PATCH 2/6] Fixes #6768 : boolean values at priority list should be valid --- library/Zend/Stdlib/PriorityList.php | 3 +++ tests/ZendTest/Stdlib/PriorityListTest.php | 26 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/library/Zend/Stdlib/PriorityList.php b/library/Zend/Stdlib/PriorityList.php index 1664e193280..34a74444b58 100644 --- a/library/Zend/Stdlib/PriorityList.php +++ b/library/Zend/Stdlib/PriorityList.php @@ -193,6 +193,9 @@ public function rewind() public function current() { $node = current($this->items); + if (isset($node['data']) && is_bool($node['data'])) { + $node['data'] = (int) $node['data']; + } return ($node !== false ? $node['data'] : false); } diff --git a/tests/ZendTest/Stdlib/PriorityListTest.php b/tests/ZendTest/Stdlib/PriorityListTest.php index e936885392b..5f2e513068a 100644 --- a/tests/ZendTest/Stdlib/PriorityListTest.php +++ b/tests/ZendTest/Stdlib/PriorityListTest.php @@ -83,7 +83,7 @@ public function testLIFOOnly() $this->list->insert('foobar', new \stdClass()); $this->list->insert('barbaz', new \stdClass()); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -129,7 +129,7 @@ public function testFIFOWithPriority() $this->list->insert('bar', new \stdClass(), 0); $this->list->insert('baz', new \stdClass(), 1); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -147,7 +147,7 @@ public function testFIFOOnly() $this->list->insert('foobar', new \stdClass()); $this->list->insert('barbaz', new \stdClass()); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -162,7 +162,7 @@ public function testPriorityWithNegativesAndNull() $this->list->insert('bar', new \stdClass(), 1); $this->list->insert('baz', new \stdClass(), -1); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -195,4 +195,22 @@ public function testToArray() $this->list->toArray(PriorityList::EXTR_BOTH) ); } + + /** + * @group ZF2-6768 + */ + public function testBooleanValuesAreValid() + { + $this->list->insert('foo', false, null); + $this->list->insert('bar', 'test', 1); + $this->list->insert('baz', true, -1); + + $orders = array(); + + foreach ($this->list as $key => $value) { + $orders[] = $value; + } + + $this->assertEquals(array('test', false, true), $orders); + } } From b68195f0b4a344915648d48c3580906f94b01627 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 19 Nov 2014 19:33:58 +0700 Subject: [PATCH 3/6] change return on valid() method --- library/Zend/Stdlib/PriorityList.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/library/Zend/Stdlib/PriorityList.php b/library/Zend/Stdlib/PriorityList.php index 34a74444b58..c7ea271eb89 100644 --- a/library/Zend/Stdlib/PriorityList.php +++ b/library/Zend/Stdlib/PriorityList.php @@ -53,7 +53,7 @@ class PriorityList implements Iterator, Countable * @var bool */ protected $sorted = false; - + /** * Insert a new item. * @@ -193,9 +193,6 @@ public function rewind() public function current() { $node = current($this->items); - if (isset($node['data']) && is_bool($node['data'])) { - $node['data'] = (int) $node['data']; - } return ($node !== false ? $node['data'] : false); } @@ -230,7 +227,7 @@ public function next() */ public function valid() { - return ($this->current() !== false); + return (current($this->items) !== false); } /** From 5b4443c7ce16913ffaa90fb90e95ffed3c0be11d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 1 Nov 2014 01:26:21 +0700 Subject: [PATCH 4/6] added test for boolean values in ZendTest/Db/Sql/UpdateTest --- tests/ZendTest/Db/Sql/UpdateTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/ZendTest/Db/Sql/UpdateTest.php b/tests/ZendTest/Db/Sql/UpdateTest.php index 596ea1d70b6..0fe14cb0c43 100644 --- a/tests/ZendTest/Db/Sql/UpdateTest.php +++ b/tests/ZendTest/Db/Sql/UpdateTest.php @@ -232,6 +232,13 @@ public function testGetSqlString() ->where('x = y'); $this->assertEquals('UPDATE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform())); + + // with boolean values + $this->update = new Update; + $this->update->table(new TableIdentifier('foo', 'sch')) + ->set(array('bar' => false, 'boo' => 'test', 'bam' => true)) + ->where('x = y'); + $this->assertEquals('UPDATE "sch"."foo" SET "bar" = \'\', "boo" = \'test\', "bam" = \'1\' WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform())); } /** From 6f0d29b0f40b10f025fb416fe9a9355df66577a4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 19 Nov 2014 20:08:06 +0700 Subject: [PATCH 5/6] fixes cs --- library/Zend/Stdlib/PriorityList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Zend/Stdlib/PriorityList.php b/library/Zend/Stdlib/PriorityList.php index c7ea271eb89..48511648a65 100644 --- a/library/Zend/Stdlib/PriorityList.php +++ b/library/Zend/Stdlib/PriorityList.php @@ -53,7 +53,7 @@ class PriorityList implements Iterator, Countable * @var bool */ protected $sorted = false; - + /** * Insert a new item. * From 1d2f3f74c1dc9cda6365900e860ee24e642e98c3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 19 Nov 2014 20:21:06 +0700 Subject: [PATCH 6/6] add new list insert for null --- tests/ZendTest/Stdlib/PriorityListTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ZendTest/Stdlib/PriorityListTest.php b/tests/ZendTest/Stdlib/PriorityListTest.php index 5f2e513068a..a8fb5ead9e6 100644 --- a/tests/ZendTest/Stdlib/PriorityListTest.php +++ b/tests/ZendTest/Stdlib/PriorityListTest.php @@ -202,6 +202,7 @@ public function testToArray() public function testBooleanValuesAreValid() { $this->list->insert('foo', false, null); + $this->list->insert('foo', null, null); $this->list->insert('bar', 'test', 1); $this->list->insert('baz', true, -1);