PHP Classes

File: tests/unit/Sql/InsertTest.php

Recommend this page to a friend!
  Classes of Haseeb Ahmad Basil   PHP Skeleton Framework   tests/unit/Sql/InsertTest.php   Download  
File: tests/unit/Sql/InsertTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Skeleton Framework
Extensive Web application development framework
Author: By
Last change:
Date: 8 years ago
Size: 1,694 bytes
 

Contents

Class file image Download
<?php

class Sql_InsertTest extends UnitTestCase {
   
    function
setUp() {
    }
   
    function
TearDown() {
    }
   
    function
testSql_InsertNull() {
        
       
$Sql_Insert = new A_Sql_Insert();
         
$this->assertEqual($Sql_Insert->render(), '');

       
$Sql_Insert = new A_Sql_Insert();
         
$this->assertEqual($Sql_Insert->table('foobar')->render(), '');

    }
   
    function
testSql_InsertValues() {
        
       
$Sql_Insert = new A_Sql_Insert();
         
$this->assertEqual($Sql_Insert->table('foobar')->values('foo', 'bar')->render(), "INSERT INTO foobar (foo) VALUES ('bar')");

         
$Sql_Insert = new A_Sql_Insert();
         
$this->assertEqual($Sql_Insert->table('foobar')->values(array('foo'=>'bar'))->render(), "INSERT INTO foobar (foo) VALUES ('bar')");

         
$Sql_Insert = new A_Sql_Insert();
         
$this->assertEqual($Sql_Insert->table('foobar')->values(array('foo'=>'bar', 'faz'=>'baz'))->render(), "INSERT INTO foobar (foo, faz) VALUES ('bar', 'baz')");

    }
   
    function
testSql_InsertSelect() {
        
       
$Sql_Insert = new A_Sql_Insert();
       
$Sql_Insert->table('foobar')
                    ->
columns(array('foo', 'bar'))
                    ->
select()->columns('fox','box')->from('barfoo')->where('id!=', 42);
         
$this->assertEqual($Sql_Insert->render(), "INSERT INTO foobar (foo, bar) SELECT fox, box FROM barfoo WHERE (id!= 42)");

    }

    public function
testSql_InsertDuplicateKey() {

       
$Sql_Insert = new A_Sql_Insert();
       
$Sql_Insert->table('foobar')
            ->
values(array(
               
'foo' => 'barbaz'
           
))
            ->
updateIfDuplicateKey('foo');

       
$query = $Sql_Insert->render();

       
$this->assertEqual($query, 'INSERT INTO foobar (foo) VALUES (\'barbaz\') ON DUPLICATE KEY UPDATE `foo` = VALUES(`foo`)');
    }
   
}