| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/dbal/src/query/lmbInsertQuery.class.php'); 10 lmb_require('limb/dbal/src/lmbSimpleDb.class.php'); 11 12 class lmbInsertQueryTest extends UnitTestCase 13 { 14 var $query; 15 var $db; 16 17 function setUp() 18 { 19 $toolkit = lmbToolkit :: save(); 20 $this->conn = $toolkit->getDefaultDbConnection(); 21 $this->db = new lmbSimpleDb($this->conn); 22 23 $this->_dbCleanUp(); 24 } 25 26 function tearDown() 27 { 28 $this->_dbCleanUp(); 29 } 30 31 function _dbCleanUp() 32 { 33 $this->db->delete('test_db_table'); 34 } 35 36 function testInsert() 37 { 38 $this->db->insert('test_db_table', array('id' => 100)); 39 40 $query = new lmbInsertQuery('test_db_table', $this->conn); 41 $query->addField('id', $id = 101); 42 $query->addField('description', $description = 'Some \'description\''); 43 $query->addField('title', $title = 'Some title'); 44 45 $stmt = $query->getStatement(); 46 $stmt->execute(); 47 48 $rs = $this->db->select('test_db_table')->sort(array('id' => 'ASC')); 49 $arr = $rs->getArray(); 50 51 $this->assertEqual(sizeof($arr), 2); 52 $this->assertEqual($arr[0]['id'], 100); 53 $this->assertEqual($arr[1]['id'], $id); 54 $this->assertEqual($arr[1]['description'], $description); 55 $this->assertEqual($arr[1]['title'], $title); 56 } 57 58 function testAddFieldWithoutValueOnlyReservesAPlaceholder() 59 { 60 $query = new lmbInsertQuery('test_db_table', $this->conn); 61 $query->addField('id'); 62 $query->addField('description'); 63 $query->addField('title'); 64 65 $stmt = $query->getStatement(); 66 $stmt->set('id', $id = 101); 67 $stmt->set('description', $description = 'Some \'description\''); 68 $stmt->set('title', $title = 'Some title'); 69 $stmt->execute(); 70 71 $rs = $this->db->select('test_db_table'); 72 $arr = $rs->getArray(); 73 74 $this->assertEqual(sizeof($arr), 1); 75 $this->assertEqual($arr[0]['id'], $id); 76 $this->assertEqual($arr[0]['description'], $description); 77 $this->assertEqual($arr[0]['title'], $title); 78 79 } 80 } 81 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Sep 6 04:46:52 2008 | Cross-referenced by PHPXref 0.7 |