Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/base.test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of lattuada  >  GPC_Validate  >  tests/base.test.php  >  Download  
File: tests/base.test.php
Role: Unit test script
Content type: text/plain
Description: test case
Class: GPC_Validate
Validate and filter values of given types
Author: By
Last change:
Date: 2011-10-19 06:09
Size: 1,832 bytes
 

Contents

Class file image Download
<?php

ini_set
("error_reporting"E_ALL);
ini_set("display_errors"true);

require_once 
'PHPUnit/Autoload.php';
require_once 
__DIR__ "/../GPC_Validate.class.php";

class 
BaseTest extends PHPUnit_Framework_TestCase
{

    private 
$data null;
    private 
$values = array("a"=>12"b"=>13"c"=>14);

    protected function 
setUp(){

        
$this->data['id'] = 22;
        
$this->data['name'] = "nicolas";
        
$this->data['nodes'] = $this->values;

        
$this->data = new GPC_Validate($this->data);
    }

    public function 
testOffsetGet(){
        
$this->assertEquals($this->data->getInt("id"), 22);
        
$this->assertEquals($this->data->getString("name"), "nicolas");
    }

    public function 
testOffsetGetArray(){
        
$this->assertTrue($this->data["nodes"] instanceof GPC_Validate);
    }

    public function 
testOffsetExists(){
        
$this->assertTrue(isset($this->data["id"]));
    }

    public function 
testIterator(){
        
$nodes  $this->data["nodes"];
        
$values array_values($this->values);
        
$i 0;
        
        foreach (
$nodes as $key=>$value) {
            
$this->assertEquals($key0);
            
$this->assertEquals($value->toInt(), $values[$i]);
            
$i++;
        }
    }

    
    public function 
testOffsetSet(){
        
$this->data["test"] = "value";
        
$this->assertEquals($this->data->getString("test"), "value");
    }
    
    
/**
     * @expectedException PHPUnit_Framework_Error_Notice
     */
    
public function testOffsetUnset(){
        
$this->data["test"] = "value";
        unset(
$this->data["test"]);
        
$this->assertEquals($this->data->getString("test"), null);
    }
    
    
/**
     * @expectedException PHPUnit_Framework_Error
     */
    
public function testOffsetGetError(){
        
$this->assertEquals($this->data["id"], false);
    }
    
    public function 
testGetStringMysql(){
        
$this->assertEquals($this->data->getString("id""MYSQL"), 22);
        
$this->assertEquals($this->data->getString("id""NOEXISTS"), null);
    }

}