<?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($key, 0);
$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);
}
}
|