miniMVC/tests/miniMVCTest.php

144 lines
2.5 KiB
PHP
Raw Normal View History

2012-01-13 12:28:11 -05:00
<?php
2012-01-16 21:36:28 -05:00
require_once('simpletest/autorun.php');
require_once('../src/sys/common.php');
2012-01-17 08:10:30 -05:00
/**
* Test class for /src/sys/common.php
*/
2012-01-16 21:36:28 -05:00
class commonTest extends UnitTestCase {
function __construct()
{
parent::__construct('Common.php Tests');
}
function setUp()
{
$this->empty = array();
$this->object = new JSObject();
$this->array_like = new JSObject(array('foo' => 'bar'));
}
function tearDown()
{
2012-01-17 08:10:30 -05:00
unset($this->empty);
unset($this->object);
unset($this->array_like);
2012-01-16 21:36:28 -05:00
}
function testCreation()
{
// Empty is not array like
$this->assertFalse(is_like_array($this->empty));
// Empty object is array like - because objects are truthy
$this->assertTrue(is_like_array($this->object));
}
}
2012-01-17 08:10:30 -05:00
// --------------------------------------------------------------------------
/**
* Test Class for JSObject class
*/
class JSObjectTest extends UnitTestCase {
function __construct()
{
parent::__construct('JSObject Class Tests');
}
function setUp()
{
$this->JSO = new JSObject(array(
'foo' => 54,
'bar' => 'baz',
));
}
function tearDown()
{
unset($this->JSO);
}
function testCreation()
{
// __toString produces same output as print_r by default
$this->assertIdentical($this->JSO->__toString(), '<pre>'.print_r($this->JSO, TRUE).'</pre>');
}
}
// --------------------------------------------------------------------------
/**
* Test class for miniMVC class
*/
2012-01-16 21:36:28 -05:00
class miniMVCTest extends UnitTestCase {
function __construct()
{
parent::__construct('miniMVC Class Tests');
}
function setUp()
{
$this->mm = new miniMVC();
}
function tearDown()
{
unset($this->mm);
}
function testCreation()
{
// miniMVC::get_instance returns reference to latest miniMVC object
$this->assertReference($this->mm, miniMVC::get_instance());
// Expect an error trying to clone the miniMVC object
$this->expectError("Clone is not allowed.");
$mm2 = clone $this->mm;
// miniMVC extends JSObject, right?
$this->assertIsA($this->mm, 'JSObject');
2012-01-17 08:10:30 -05:00
// Invoke function should return the same reference than miniMVC::get_instance() does
$mm = $this->mm;
$this->assertIdentical($mm(), miniMVC::get_instance());
$this->assertIdentical($this->mm->__invoke(), miniMVC::get_instance());
2012-01-16 21:36:28 -05:00
}
2012-01-13 12:28:11 -05:00
}
2012-01-17 08:10:30 -05:00
// --------------------------------------------------------------------------
class DBTest extends UnitTestCase {
2012-01-16 21:36:28 -05:00
function __construct()
{
2012-01-17 08:10:30 -05:00
2012-01-16 21:36:28 -05:00
}
function setUp()
{
2012-01-17 08:10:30 -05:00
2012-01-16 21:36:28 -05:00
}
function tearDown()
{
2012-01-17 08:10:30 -05:00
2012-01-16 21:36:28 -05:00
}
2012-01-17 08:10:30 -05:00
2012-01-16 21:36:28 -05:00
function testCreation()
{
}
2012-01-13 12:28:11 -05:00
2012-01-17 08:10:30 -05:00
}