pickles/tests/classes/ResourceTest.php
Josh Sherman 39d5b8d40b Cleaned up unit tests
Wanted to get back to the point that the tests were running and not erroring.
2014-09-25 23:11:29 -04:00

69 lines
1.6 KiB
PHP

<?php
$_POST['field2'] = 'short';
$_GET['field2'] = 'short';
$_REQUEST['field2'] = 'short';
class MockParentResource extends Resource
{
public $validate = [
'field1',
'field2' => [
'length:<:10' => 'Too short',
'length:>:50' => 'Too long',
],
];
}
class MockChildResource extends MockParentResource
{
public $method = ['POST', 'GET'];
}
class ResourceTest extends PHPUnit_Framework_TestCase
{
public function testAutoRun()
{
$this->assertInstanceOf('Resource', new Resource(true));
}
public function testAutoRunParentError()
{
$this->expectOutputString('');
$model = new MockChildResource(true);
}
public function testSetGetReturn()
{
$module = new Resource();
$module->foo = 'bar';
$this->assertEquals('bar', $module->foo);
}
public function testGetMissing()
{
$module = new Resource();
$this->assertFalse($module->missing);
}
public function testValidateGet()
{
$module = new MockParentResource();
$module->method = 'GET';
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
}
public function testValidatePost()
{
$module = new MockParentResource();
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
}
public function testValidateRequest()
{
$module = new MockParentResource();
$module->method = null;
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
}
}