PHP Classes

File: tests/unit/Sql/ExpressionTest.php

Recommend this page to a friend!
  Classes of Haseeb Ahmad Basil   PHP Skeleton Framework   tests/unit/Sql/ExpressionTest.php   Download  
File: tests/unit/Sql/ExpressionTest.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: 2,455 bytes
 

Contents

Class file image Download
<?php

class Sql_ExpressionTest extends UnitTestCase {
   
    function
setUp() {
    }
   
    function
TearDown() {
    }
   
    function
testSimpleEqualsUsingTwoParameters() {
       
$expression = new A_Sql_Expression('foo', 'bar');
       
$this->assertEqual($expression->render(), "foo = 'bar'");
    }
   
    function
testSimpleDoesEqualsUsingTwoParametersWithOperatorEmbedded() {
       
$expression = new A_Sql_Expression('foo =', 'bar');
       
$this->assertEqual($expression->render(), "foo = 'bar'");
    }
   
    function
testSingleParameterWithArrayOfSingleExpressions() {
       
$expressions = array('foo' => 'bar');
       
$expression = new A_Sql_Expression($expressions);
       
$this->assertEqual($expression->render(), "foo = 'bar'");
    }
   
    function
testSingleParameterWithArrayOfMultipleExpressions() {
       
$expressions = array(
           
'foo' => 'bar',
           
'foo2' => 'bar',
           
'foo3' => 'bar3'
       
);
       
       
$expression = new A_Sql_Expression($expressions);
       
$this->assertEqual($expression->render(), "foo = 'bar' AND foo2 = 'bar' AND foo3 = 'bar3'");
    }
   
    function
testAlternateCommaSeperator() {
       
$expressions = array(
           
'foo' => 'bar',
           
'foo2' => 'bar',
           
'foo3' => 'bar3'
       
);
       
$expression = new A_Sql_Expression($expressions);
       
$this->assertEqual($expression->render(','), "foo = 'bar', foo2 = 'bar', foo3 = 'bar3'");
    }
 
    function
testAlternateLogicalSeperator() {
       
$expressions = array(
           
'foo' => 'bar',
           
'foo2' => 'bar',
           
'foo3' => 'bar3'
       
);
       
$expression = new A_Sql_Expression($expressions);
       
$this->assertEqual($expression->render('OR'), "foo = 'bar' OR foo2 = 'bar' OR foo3 = 'bar3'");
    }
   
    function
testBracketsMultipleValuesExpressions() {
       
$expressions = array(
           
'foo IN' => array('foo2', 'bar2'),
           
'foo2 NOT IN' => array('foo3', 'bar3')
        );
       
$expression = new A_Sql_Expression($expressions);
       
$this->assertEqual($expression->render(), "foo IN ('foo2', 'bar2') AND foo2 NOT IN ('foo3', 'bar3')");
    }
   
    function
testValuesAreEscaped() {
       
$expression = new A_Sql_Expression('foobar', "foo'bar");
       
$this->assertEqual($expression->render(), "foobar = 'foo\'bar'");
    }

}