summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/database/query_builder/insert_test.php
diff options
context:
space:
mode:
authorTimothy Warren <tim@timshomepage.net>2012-04-26 23:58:56 +0200
committerTimothy Warren <tim@timshomepage.net>2012-04-26 23:58:56 +0200
commit042766bac61958a21ba5d6b3c53b0e4296fdcce7 (patch)
treedf9e26699ddb5d3841a0d1cc1795913c819bf611 /tests/codeigniter/database/query_builder/insert_test.php
parent0688ac9ad88a03f1c56cfcd9e3c475b83301344d (diff)
parent61318a2c53c13a314f483fcbbfd64c6e01f5242c (diff)
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into library-cleanup
Diffstat (limited to 'tests/codeigniter/database/query_builder/insert_test.php')
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
new file mode 100644
index 000000000..53ce23c19
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -0,0 +1,67 @@
+<?php
+
+class Insert_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ * @see ./mocks/schema/skeleton.php
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+
+ // Truncate the current datas
+ $this->db->truncate('job');
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert()
+ {
+ $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
+
+ // Do normal insert
+ $this->assertTrue($this->db->insert('job', $job_data));
+
+ $jobs = $this->db->get('job')->result_array();
+ $job1 = $jobs[0];
+
+ // Check the result
+ $this->assertEquals('Grocery Sales', $job1['name']);
+
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert_batch()
+ {
+ $job_datas = array(
+ array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
+ array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
+ );
+
+ // Do insert batch except for sqlite driver
+ if (strpos(DB_DRIVER, 'sqlite') === FALSE)
+ {
+ $this->assertTrue($this->db->insert_batch('job', $job_datas));
+
+ $job_2 = $this->db->where('id', 2)->get('job')->row();
+ $job_3 = $this->db->where('id', 3)->get('job')->row();
+
+ // Check the result
+ $this->assertEquals('Commedian', $job_2->name);
+ $this->assertEquals('Cab Driver', $job_3->name);
+ }
+ }
+
+} \ No newline at end of file