Browse Source

Added test for Collection::insert()

Jose Lorenzo Rodriguez 12 years ago
parent
commit
1538bd32f9
1 changed files with 16 additions and 0 deletions
  1. 16 0
      tests/TestCase/Collection/CollectionTest.php

+ 16 - 0
tests/TestCase/Collection/CollectionTest.php

@@ -839,4 +839,20 @@ class CollectionTest extends TestCase {
 		$this->assertEquals($expected, $collection->toArray());
 	}
 
+/**
+ * Tests insert
+ *
+ * @return void
+ */
+	public function testInsert() {
+		$items = [['a' => 1], ['b' => 2]];
+		$collection = new Collection($items);
+		$iterator = $collection->insert('c', [3, 4]);
+		$this->assertInstanceOf('\Cake\Collection\Iterator\InsertIterator', $iterator);
+		$this->assertEquals(
+			[['a' => 1, 'c' => 3], ['b' => 2, 'c' => 4]],
+			iterator_to_array($iterator)
+		);
+	}
+
 }