Commit 31aaff40 authored by Taddes Kroes's avatar Taddes Kroes

Added some basic unit tests.

parent 9182a8e1
......@@ -9,6 +9,8 @@
* @todo Documentation
*/
class pQueryArray extends pQuery implements pQueryExtension {
static $accepts = array('array');
/**
* Get the value of an array alement at the given index.
*
......
......@@ -219,13 +219,16 @@ class pQuery {
if( isset($accepts[$type]) ) {
$convert_method = $accepts[$type];
if( !method_exists($this, $convert_method) )
return self::error('Plugin "%s" has no conversion method "%s".', $class_name, $convert_method);
if( !method_exists($this, $convert_method) ) {
return self::error('Plugin "%s" has no conversion method "%s".',
$class_name, $convert_method);
}
$result = $this->$convert_method($variable);
$result === null || $this->variable = $result;
} else if( !in_array($type, $accepts) ) {
return self::error('Variable type "%s" is not accepted by class "%s".', $type, $class_name);
return self::error('Variable type "%s" is not accepted by class "%s".',
$type, $class_name);
}
}
......
<?php
__p::load_plugin('array');
class pQueryArrayTest extends UnitTestCase {
var $variable;
var $arr;
function __construct() {
$this->UnitTestCase('pQuery array plugin test');
parent::__construct('pQuery array plugin');
}
function setUp() {
$this->variable = array('test');
$this->arr = _arr($this->variable);
}
function test_constructor() {
$this->assertIsA($this->arr, 'pQueryArray', 'constructor does not return pQueryArray object.');
$this->assertEqual($this->arr->variable, $this->variable, 'variable is not set correctly.');
}
function test_get_simple() {
$this->assertEqual($this->arr->get(0), $this->variable[0]);
}
function test_get_non_existent() {
$this->assertNull($this->arr->get(count($this->variable)), 'non-existent index should yield NULL.');
}
function test_is_empty_empty() {
$this->assertTrue(_arr(array())->is_empty());
}
function test_is_empty_non_empty() {
$this->assertFalse($this->arr->is_empty());
}
function test_() {
function test_reverse() {
$orginal = range(1, 4);
$reverse = range(4, 1, -1);
$arr = _arr($orginal);
$this->assertEqual($arr->reverse()->variable, $reverse, 'reverse is not really reverse...');
}
}
......
......@@ -2,7 +2,7 @@
class pQueryTest extends UnitTestCase {
function __construct() {
$this->UnitTestCase('pQuery base test');
parent::__construct('pQuery base');
}
function test_() {
......
<?php
__p::load_plugin('sql');
class pQuerySqlTest extends UnitTestCase {
function __construct() {
$this->UnitTestCase('pQuery MySQL plugin test');
parent::__construct('pQuery MySQL plugin');
}
function test_() {
......
<?php
__p::load_plugin('template');
class pQueryTemplateTest extends UnitTestCase {
function __construct() {
$this->UnitTestCase('pQuery template plugin test');
parent::__construct('pQuery template plugin');
}
function test_() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment