From 1229f1e5c1a7d6c3d7a3a11fd7e81b6bc1ca46e5 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 21 Feb 2019 18:19:28 -0800 Subject: [PATCH] db_Query tests for BIND etc. --- tests/unit/e_db_pdoTest.php | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/unit/e_db_pdoTest.php b/tests/unit/e_db_pdoTest.php index e29ab28b6..d0d3c63b1 100644 --- a/tests/unit/e_db_pdoTest.php +++ b/tests/unit/e_db_pdoTest.php @@ -231,6 +231,69 @@ $err = $this->db->getLastErrorText(); $this->assertFalse($result, $err); + + $query = array ( + 'PREPARE' => 'INSERT INTO '.MPREFIX.'tmp (`tmp_ip`,`tmp_time`,`tmp_info`) VALUES (:tmp_ip, :tmp_time, :tmp_info)', + 'BIND' => + array( + 'tmp_ip' => + array( + 'value' => '127.0.0.1', + 'type' => PDO::PARAM_STR, + ), + 'tmp_time' => + array( + 'value' => 12345435, + 'type' => PDO::PARAM_INT, + ), + 'tmp_info' => + array( + 'value' => 'Insert test', + 'type' => PDO::PARAM_STR, + ), + ), + ); + + + $result = $this->db->db_Query($query, null, 'INSERT'); + $this->assertGreaterThan(0,$result); + + + $query = array ( + 'PREPARE' => 'INSERT INTO '.MPREFIX.'tmp (`tmp_ip`,`tmp_time`,`tmp_info`) VALUES (:tmp_ip, :tmp_time, :tmp_info)', + 'BIND' => + array( + 'tmp_ip' => + array( + 'value' => '127.0.0.1', + 'type' => PDO::PARAM_STR, + ), + 'tmp_time' => + array( + 'value' => 12345435, + 'type' => PDO::PARAM_INT, + ), + 'tmp_info' => + array( + 'value' => 'Insert test', + 'type' => PDO::PARAM_STR, + ), + ), + ); + + $query = array( + 'PREPARE' => 'SELECT * FROM '.MPREFIX.'user WHERE user_id=:user_id AND user_name=:user_name', + 'EXECUTE' => array( + 'user_id' => 1, + 'user_name' => 'e107' + ) + ); + + + $res = $this->db->db_Query($query, null, 'db_Select'); + $result = $res->fetch(); + $this->assertArrayHasKey('user_password', $result); + } @@ -297,6 +360,9 @@ $result = $this->db->select('user', 'user_id, user_name', 'WHERE user_id = 1', true); $this->assertEquals(1, $result); + $result = $this->db->select('user', 'user_id, user_name', 'user_id=:id OR user_name=:name ORDER BY user_name', array('id' => 999, 'name'=>'e107')); // bind support. + $this->assertEquals(1, $result); + }