Code style fixes
This commit is contained in:
parent
e9b5de8ea9
commit
8e970853f6
|
@ -6,34 +6,33 @@ use b8\Config, b8\Cache;
|
|||
|
||||
class CacheTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreateSingleton()
|
||||
{
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
$this->assertTrue($cache instanceof Cache);
|
||||
}
|
||||
public function testCreateSingleton()
|
||||
{
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
$this->assertTrue($cache instanceof Cache);
|
||||
}
|
||||
|
||||
public function testDisableCaching()
|
||||
{
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('DisableCaching', true);
|
||||
public function testDisableCaching()
|
||||
{
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('DisableCaching', true);
|
||||
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
$this->assertFalse($cache->isEnabled());
|
||||
$this->assertFalse($cache->set('anything', 10));
|
||||
$this->assertTrue(is_null($cache->get('anything')));
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
$this->assertFalse($cache->isEnabled());
|
||||
$this->assertFalse($cache->set('anything', 10));
|
||||
$this->assertTrue(is_null($cache->get('anything')));
|
||||
|
||||
Config::getInstance()->set('DisableCaching', false);
|
||||
}
|
||||
Config::getInstance()->set('DisableCaching', false);
|
||||
}
|
||||
|
||||
public function testCaching()
|
||||
{
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
public function testCaching()
|
||||
{
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
|
||||
if($cache->isEnabled())
|
||||
{
|
||||
$this->assertTrue($cache->set('anything', 10));
|
||||
$this->assertTrue($cache->get('anything') == 10);
|
||||
$this->assertTrue(is_null($cache->get('invalid')));
|
||||
}
|
||||
}
|
||||
if ($cache->isEnabled()) {
|
||||
$this->assertTrue($cache->set('anything', 10));
|
||||
$this->assertTrue($cache->get('anything') == 10);
|
||||
$this->assertTrue(is_null($cache->get('invalid')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,70 +6,70 @@ use b8\Database\Generator, b8\Database\Map, b8\Database;
|
|||
|
||||
class DatabaseGenerationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $_host = 'localhost';
|
||||
protected $_user = 'b8_test';
|
||||
protected $_pass = 'b8_test';
|
||||
protected $_name = 'b8_test';
|
||||
protected $_db;
|
||||
protected $_host = 'localhost';
|
||||
protected $_user = 'b8_test';
|
||||
protected $_pass = 'b8_test';
|
||||
protected $_name = 'b8_test';
|
||||
protected $_db;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setWriteServers([$this->_host]);
|
||||
public function setUp()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setWriteServers([$this->_host]);
|
||||
|
||||
$this->_db = Database::getConnection('write');
|
||||
$this->_db = Database::getConnection('write');
|
||||
|
||||
$this->_db->query('DROP TABLE IF EXISTS tres');
|
||||
$this->_db->query('DROP TABLE IF EXISTS dos');
|
||||
$this->_db->query('DROP TABLE IF EXISTS uno');
|
||||
}
|
||||
$this->_db->query('DROP TABLE IF EXISTS tres');
|
||||
$this->_db->query('DROP TABLE IF EXISTS dos');
|
||||
$this->_db->query('DROP TABLE IF EXISTS uno');
|
||||
}
|
||||
|
||||
public function testCreateDatabase()
|
||||
{
|
||||
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
|
||||
$gen->generate();
|
||||
public function testCreateDatabase()
|
||||
{
|
||||
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
|
||||
$gen->generate();
|
||||
|
||||
$map = new Map($this->_db);
|
||||
$t = $map->generate();
|
||||
$map = new Map($this->_db);
|
||||
$t = $map->generate();
|
||||
|
||||
$this->assertTrue(array_key_exists('uno', $t));
|
||||
$this->assertTrue(array_key_exists('dos', $t));
|
||||
$this->assertTrue(array_key_exists('tres', $t));
|
||||
$this->assertFalse(array_key_exists('bad_table', $t));
|
||||
$this->assertTrue(count($t['uno']['indexes']) == 1);
|
||||
$this->assertTrue(count($t['dos']['indexes']) == 3);
|
||||
$this->assertTrue(count($t['tres']['indexes']) == 2);
|
||||
$this->assertTrue(count($t['uno']['columns']) == 11);
|
||||
$this->assertTrue(count($t['dos']['columns']) == 4);
|
||||
$this->assertTrue(count($t['tres']['columns']) == 6);
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['uno']['indexes']));
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['dos']['indexes']));
|
||||
$this->assertFalse(array_key_exists('PRIMARY', $t['tres']['indexes']));
|
||||
}
|
||||
$this->assertTrue(array_key_exists('uno', $t));
|
||||
$this->assertTrue(array_key_exists('dos', $t));
|
||||
$this->assertTrue(array_key_exists('tres', $t));
|
||||
$this->assertFalse(array_key_exists('bad_table', $t));
|
||||
$this->assertTrue(count($t['uno']['indexes']) == 1);
|
||||
$this->assertTrue(count($t['dos']['indexes']) == 3);
|
||||
$this->assertTrue(count($t['tres']['indexes']) == 2);
|
||||
$this->assertTrue(count($t['uno']['columns']) == 11);
|
||||
$this->assertTrue(count($t['dos']['columns']) == 4);
|
||||
$this->assertTrue(count($t['tres']['columns']) == 6);
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['uno']['indexes']));
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['dos']['indexes']));
|
||||
$this->assertFalse(array_key_exists('PRIMARY', $t['tres']['indexes']));
|
||||
}
|
||||
|
||||
public function testUpdateDatabase()
|
||||
{
|
||||
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
|
||||
$gen->generate();
|
||||
public function testUpdateDatabase()
|
||||
{
|
||||
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
|
||||
$gen->generate();
|
||||
|
||||
$gen = new Generator($this->_db, 'Update', __DIR__ . '/data/generation/update_models/');
|
||||
$gen->generate();
|
||||
$gen = new Generator($this->_db, 'Update', __DIR__ . '/data/generation/update_models/');
|
||||
$gen->generate();
|
||||
|
||||
$map = new Map($this->_db);
|
||||
$t = $map->generate();
|
||||
$map = new Map($this->_db);
|
||||
$t = $map->generate();
|
||||
|
||||
$this->assertTrue(array_key_exists('uno', $t));
|
||||
$this->assertTrue(array_key_exists('dos', $t));
|
||||
$this->assertTrue(array_key_exists('tres', $t));
|
||||
$this->assertFalse(array_key_exists('bad_table', $t));
|
||||
$this->assertTrue(count($t['uno']['indexes']) == 1);
|
||||
$this->assertTrue(count($t['dos']['indexes']) == 3);
|
||||
$this->assertTrue(count($t['tres']['indexes']) == 3);
|
||||
$this->assertTrue(count($t['uno']['columns']) == 10);
|
||||
$this->assertTrue(count($t['dos']['columns']) == 4);
|
||||
$this->assertTrue(count($t['tres']['columns']) == 10);
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['uno']['indexes']));
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['dos']['indexes']));
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['tres']['indexes']));
|
||||
}
|
||||
$this->assertTrue(array_key_exists('uno', $t));
|
||||
$this->assertTrue(array_key_exists('dos', $t));
|
||||
$this->assertTrue(array_key_exists('tres', $t));
|
||||
$this->assertFalse(array_key_exists('bad_table', $t));
|
||||
$this->assertTrue(count($t['uno']['indexes']) == 1);
|
||||
$this->assertTrue(count($t['dos']['indexes']) == 3);
|
||||
$this->assertTrue(count($t['tres']['indexes']) == 3);
|
||||
$this->assertTrue(count($t['uno']['columns']) == 10);
|
||||
$this->assertTrue(count($t['dos']['columns']) == 4);
|
||||
$this->assertTrue(count($t['tres']['columns']) == 10);
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['uno']['indexes']));
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['dos']['indexes']));
|
||||
$this->assertTrue(array_key_exists('PRIMARY', $t['tres']['indexes']));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,50 +6,50 @@ use b8\Database;
|
|||
|
||||
class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $_host = 'localhost';
|
||||
protected $_user = 'b8_test';
|
||||
protected $_pass = 'b8_test';
|
||||
protected $_name = 'b8_test';
|
||||
protected $_host = 'localhost';
|
||||
protected $_user = 'b8_test';
|
||||
protected $_pass = 'b8_test';
|
||||
protected $_name = 'b8_test';
|
||||
|
||||
public function testGetReadConnection()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setReadServers([$this->_host]);
|
||||
public function testGetReadConnection()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setReadServers([$this->_host]);
|
||||
|
||||
$connection = Database::getConnection('read');
|
||||
$connection = Database::getConnection('read');
|
||||
|
||||
$this->assertInstanceOf('\b8\Database', $connection);
|
||||
}
|
||||
$this->assertInstanceOf('\b8\Database', $connection);
|
||||
}
|
||||
|
||||
public function testGetWriteConnection()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setWriteServers([$this->_host]);
|
||||
public function testGetWriteConnection()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setWriteServers([$this->_host]);
|
||||
|
||||
$connection = Database::getConnection('write');
|
||||
$connection = Database::getConnection('write');
|
||||
|
||||
$this->assertInstanceOf('\b8\Database', $connection);
|
||||
}
|
||||
$this->assertInstanceOf('\b8\Database', $connection);
|
||||
}
|
||||
|
||||
public function testGetDetails()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setReadServers(['localhost']);
|
||||
public function testGetDetails()
|
||||
{
|
||||
Database::setDetails($this->_name, $this->_user, $this->_pass);
|
||||
Database::setReadServers(['localhost']);
|
||||
|
||||
$details = Database::getConnection('read')->getDetails();
|
||||
$this->assertTrue(is_array($details));
|
||||
$this->assertTrue(($details['db'] == $this->_name));
|
||||
$this->assertTrue(($details['user'] == $this->_user));
|
||||
$this->assertTrue(($details['pass'] == $this->_pass));
|
||||
}
|
||||
$details = Database::getConnection('read')->getDetails();
|
||||
$this->assertTrue(is_array($details));
|
||||
$this->assertTrue(($details['db'] == $this->_name));
|
||||
$this->assertTrue(($details['user'] == $this->_user));
|
||||
$this->assertTrue(($details['pass'] == $this->_pass));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testConnectionFailure()
|
||||
{
|
||||
Database::setDetails('non_existant', 'invalid_user', 'incorrect_password');
|
||||
Database::setReadServers(['localhost']);
|
||||
Database::getConnection('read');
|
||||
}
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testConnectionFailure()
|
||||
{
|
||||
Database::setDetails('non_existant', 'invalid_user', 'incorrect_password');
|
||||
Database::setReadServers(['localhost']);
|
||||
Database::getConnection('read');
|
||||
}
|
||||
}
|
|
@ -6,173 +6,173 @@ use b8\Form, b8\Config;
|
|||
|
||||
class FormTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFormBasics()
|
||||
{
|
||||
$f = new Form();
|
||||
$f->setAction('/');
|
||||
$f->setMethod('POST');
|
||||
public function testFormBasics()
|
||||
{
|
||||
$f = new Form();
|
||||
$f->setAction('/');
|
||||
$f->setMethod('POST');
|
||||
|
||||
$this->assertTrue($f->getAction() == '/');
|
||||
$this->assertTrue($f->getMethod() == 'POST');
|
||||
$this->assertTrue($f->getAction() == '/');
|
||||
$this->assertTrue($f->getMethod() == 'POST');
|
||||
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('ViewPath', __DIR__ . '/data/view/');
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('ViewPath', __DIR__ . '/data/view/');
|
||||
|
||||
$this->assertTrue($f->render('form') == '/POST');
|
||||
$this->assertTrue($f->render('form') == '/POST');
|
||||
|
||||
Config::getInstance()->set('ViewPath', '');
|
||||
$this->assertTrue(strpos((string)$f, '<form') !== false);
|
||||
}
|
||||
Config::getInstance()->set('ViewPath', '');
|
||||
$this->assertTrue(strpos((string)$f, '<form') !== false);
|
||||
}
|
||||
|
||||
public function testElementBasics()
|
||||
{
|
||||
$f = new Form\Element\Text('element-name');
|
||||
$f->setId('element-id');
|
||||
$f->setLabel('element-label');
|
||||
$f->setClass('element-class');
|
||||
$f->setContainerClass('container-class');
|
||||
public function testElementBasics()
|
||||
{
|
||||
$f = new Form\Element\Text('element-name');
|
||||
$f->setId('element-id');
|
||||
$f->setLabel('element-label');
|
||||
$f->setClass('element-class');
|
||||
$f->setContainerClass('container-class');
|
||||
|
||||
$this->assertTrue($f->getName() == 'elementname');
|
||||
$this->assertTrue($f->getId() == 'element-id');
|
||||
$this->assertTrue($f->getLabel() == 'element-label');
|
||||
$this->assertTrue($f->getClass() == 'element-class');
|
||||
$this->assertTrue($f->getContainerClass() == 'container-class');
|
||||
$this->assertTrue($f->getName() == 'elementname');
|
||||
$this->assertTrue($f->getId() == 'element-id');
|
||||
$this->assertTrue($f->getLabel() == 'element-label');
|
||||
$this->assertTrue($f->getClass() == 'element-class');
|
||||
$this->assertTrue($f->getContainerClass() == 'container-class');
|
||||
|
||||
$output = $f->render();
|
||||
$this->assertTrue(is_string($output));
|
||||
$this->assertTrue(!empty($output));
|
||||
$this->assertTrue(strpos($output, 'container-class') !== false);
|
||||
}
|
||||
$output = $f->render();
|
||||
$this->assertTrue(is_string($output));
|
||||
$this->assertTrue(!empty($output));
|
||||
$this->assertTrue(strpos($output, 'container-class') !== false);
|
||||
}
|
||||
|
||||
public function testInputBasics()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
$f->setValue('input-value');
|
||||
$f->setRequired(true);
|
||||
$f->setValidator(function($value) { return ($value == 'input-value'); });
|
||||
public function testInputBasics()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
$f->setValue('input-value');
|
||||
$f->setRequired(true);
|
||||
$f->setValidator(function ($value) {
|
||||
return ($value == 'input-value');
|
||||
});
|
||||
|
||||
$this->assertTrue($f->getValue() == 'input-value');
|
||||
$this->assertTrue($f->getRequired() == true);
|
||||
$this->assertTrue(is_callable($f->getValidator()));
|
||||
}
|
||||
$this->assertTrue($f->getValue() == 'input-value');
|
||||
$this->assertTrue($f->getRequired() == true);
|
||||
$this->assertTrue(is_callable($f->getValidator()));
|
||||
}
|
||||
|
||||
public function testInputValidation()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
$f->setRequired(true);
|
||||
$this->assertFalse($f->validate());
|
||||
public function testInputValidation()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
$f->setRequired(true);
|
||||
$this->assertFalse($f->validate());
|
||||
|
||||
$f->setRequired(false);
|
||||
$f->setPattern('input\-value');
|
||||
$this->assertFalse($f->validate());
|
||||
$f->setRequired(false);
|
||||
$f->setPattern('input\-value');
|
||||
$this->assertFalse($f->validate());
|
||||
|
||||
$f->setValue('input-value');
|
||||
$this->assertTrue($f->validate());
|
||||
$f->setValue('input-value');
|
||||
$this->assertTrue($f->validate());
|
||||
|
||||
$f->setValidator(function($item)
|
||||
{
|
||||
if($item != 'input-value')
|
||||
{
|
||||
throw new \Exception('Invalid input value.');
|
||||
}
|
||||
});
|
||||
$f->setValidator(function ($item) {
|
||||
if ($item != 'input-value') {
|
||||
throw new \Exception('Invalid input value.');
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertTrue($f->validate());
|
||||
$this->assertTrue($f->validate());
|
||||
|
||||
$f->setValue('fail');
|
||||
$f->setPattern(null);
|
||||
$this->assertFalse($f->validate());
|
||||
}
|
||||
$f->setValue('fail');
|
||||
$f->setPattern(null);
|
||||
$this->assertFalse($f->validate());
|
||||
}
|
||||
|
||||
public function testFieldSetBasics()
|
||||
{
|
||||
$f = new Form\FieldSet();
|
||||
$f2 = new Form\FieldSet('group');
|
||||
$f3 = new Form\FieldSet();
|
||||
public function testFieldSetBasics()
|
||||
{
|
||||
$f = new Form\FieldSet();
|
||||
$f2 = new Form\FieldSet('group');
|
||||
$f3 = new Form\FieldSet();
|
||||
|
||||
$t = new Form\Element\Text('one');
|
||||
$t->setRequired(true);
|
||||
$f2->addField($t);
|
||||
$t = new Form\Element\Text('one');
|
||||
$t->setRequired(true);
|
||||
$f2->addField($t);
|
||||
|
||||
$t = new Form\Element\Text('two');
|
||||
$f2->addField($t);
|
||||
$t = new Form\Element\Text('two');
|
||||
$f2->addField($t);
|
||||
|
||||
$t = new Form\Element\Text('three');
|
||||
$f3->addField($t);
|
||||
$t = new Form\Element\Text('three');
|
||||
$f3->addField($t);
|
||||
|
||||
$f->addField($f2);
|
||||
$f->addField($f3);
|
||||
$f->addField($f2);
|
||||
$f->addField($f3);
|
||||
|
||||
$this->assertFalse($f->validate());
|
||||
$this->assertFalse($f->validate());
|
||||
|
||||
$f->setValues(['group' => ['one' => 'ONE', 'two' => 'TWO'], 'three' => 'THREE']);
|
||||
$f->setValues(['group' => ['one' => 'ONE', 'two' => 'TWO'], 'three' => 'THREE']);
|
||||
|
||||
$values = $f->getValues();
|
||||
$this->assertTrue(is_array($values));
|
||||
$this->assertTrue(array_key_exists('group', $values));
|
||||
$this->assertTrue(array_key_exists('one', $values['group']));
|
||||
$this->assertTrue(array_key_exists('three', $values));
|
||||
$this->assertTrue($values['group']['one'] == 'ONE');
|
||||
$this->assertTrue($values['group']['two'] == 'TWO');
|
||||
$this->assertTrue($values['three'] == 'THREE');
|
||||
$this->assertTrue($f->validate());
|
||||
$values = $f->getValues();
|
||||
$this->assertTrue(is_array($values));
|
||||
$this->assertTrue(array_key_exists('group', $values));
|
||||
$this->assertTrue(array_key_exists('one', $values['group']));
|
||||
$this->assertTrue(array_key_exists('three', $values));
|
||||
$this->assertTrue($values['group']['one'] == 'ONE');
|
||||
$this->assertTrue($values['group']['two'] == 'TWO');
|
||||
$this->assertTrue($values['three'] == 'THREE');
|
||||
$this->assertTrue($f->validate());
|
||||
|
||||
$html = $f->render();
|
||||
$this->assertTrue(strpos($html, 'one') !== false);
|
||||
$this->assertTrue(strpos($html, 'two') !== false);
|
||||
}
|
||||
$html = $f->render();
|
||||
$this->assertTrue(strpos($html, 'one') !== false);
|
||||
$this->assertTrue(strpos($html, 'two') !== false);
|
||||
}
|
||||
|
||||
public function testElements()
|
||||
{
|
||||
$e = new Form\Element\Button();
|
||||
$this->assertTrue($e->validate());
|
||||
$this->assertTrue(strpos($e->render(), 'button') !== false);
|
||||
public function testElements()
|
||||
{
|
||||
$e = new Form\Element\Button();
|
||||
$this->assertTrue($e->validate());
|
||||
$this->assertTrue(strpos($e->render(), 'button') !== false);
|
||||
|
||||
$e = new Form\Element\Checkbox();
|
||||
$e->setCheckedValue('ten');
|
||||
$this->assertTrue($e->getCheckedValue() == 'ten');
|
||||
$this->assertTrue(strpos($e->render(), 'checkbox') !== false);
|
||||
$this->assertTrue(strpos($e->render(), 'checked') === false);
|
||||
$e = new Form\Element\Checkbox();
|
||||
$e->setCheckedValue('ten');
|
||||
$this->assertTrue($e->getCheckedValue() == 'ten');
|
||||
$this->assertTrue(strpos($e->render(), 'checkbox') !== false);
|
||||
$this->assertTrue(strpos($e->render(), 'checked') === false);
|
||||
|
||||
$e->setValue(true);
|
||||
$this->assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
$e->setValue(true);
|
||||
$this->assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
|
||||
$e->setValue('ten');
|
||||
$this->assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
$e->setValue('ten');
|
||||
$this->assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
|
||||
$e->setValue('fail');
|
||||
$this->assertTrue(strpos($e->render(), 'checked') === false);
|
||||
$e->setValue('fail');
|
||||
$this->assertTrue(strpos($e->render(), 'checked') === false);
|
||||
|
||||
$e = new Form\Element\CheckboxGroup();
|
||||
$this->assertTrue(strpos($e->render(), 'group') !== false);
|
||||
$e = new Form\Element\CheckboxGroup();
|
||||
$this->assertTrue(strpos($e->render(), 'group') !== false);
|
||||
|
||||
$e = new Form\ControlGroup();
|
||||
$this->assertTrue(strpos($e->render(), 'group') !== false);
|
||||
$e = new Form\ControlGroup();
|
||||
$this->assertTrue(strpos($e->render(), 'group') !== false);
|
||||
|
||||
$e = new Form\Element\Email();
|
||||
$this->assertTrue(strpos($e->render(), 'email') !== false);
|
||||
$e = new Form\Element\Email();
|
||||
$this->assertTrue(strpos($e->render(), 'email') !== false);
|
||||
|
||||
$e = new Form\Element\Select();
|
||||
$e->setOptions(['key' => 'Val']);
|
||||
$html = $e->render();
|
||||
$this->assertTrue(strpos($html, 'select') !== false);
|
||||
$this->assertTrue(strpos($html, 'option') !== false);
|
||||
$this->assertTrue(strpos($html, 'key') !== false);
|
||||
$this->assertTrue(strpos($html, 'Val') !== false);
|
||||
$e = new Form\Element\Select();
|
||||
$e->setOptions(['key' => 'Val']);
|
||||
$html = $e->render();
|
||||
$this->assertTrue(strpos($html, 'select') !== false);
|
||||
$this->assertTrue(strpos($html, 'option') !== false);
|
||||
$this->assertTrue(strpos($html, 'key') !== false);
|
||||
$this->assertTrue(strpos($html, 'Val') !== false);
|
||||
|
||||
$e = new Form\Element\Submit();
|
||||
$this->assertTrue($e->validate());
|
||||
$this->assertTrue(strpos($e->render(), 'submit') !== false);
|
||||
$e = new Form\Element\Submit();
|
||||
$this->assertTrue($e->validate());
|
||||
$this->assertTrue(strpos($e->render(), 'submit') !== false);
|
||||
|
||||
$e = new Form\Element\Text();
|
||||
$e->setValue('test');
|
||||
$this->assertTrue(strpos($e->render(), 'test') !== false);
|
||||
$e = new Form\Element\Text();
|
||||
$e->setValue('test');
|
||||
$this->assertTrue(strpos($e->render(), 'test') !== false);
|
||||
|
||||
$e = new Form\Element\TextArea();
|
||||
$e->setRows(10);
|
||||
$this->assertTrue(strpos($e->render(), '10') !== false);
|
||||
$e = new Form\Element\TextArea();
|
||||
$e->setRows(10);
|
||||
$this->assertTrue(strpos($e->render(), '10') !== false);
|
||||
|
||||
$e = new Form\Element\Url();
|
||||
$this->assertTrue(strpos($e->render(), 'url') !== false);
|
||||
}
|
||||
$e = new Form\Element\Url();
|
||||
$this->assertTrue(strpos($e->render(), 'url') !== false);
|
||||
}
|
||||
}
|
|
@ -6,59 +6,59 @@ use b8\HttpClient;
|
|||
|
||||
class HttpClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSimpleRequest()
|
||||
{
|
||||
$http = new HttpClient();
|
||||
$html = $http->request('GET', 'https://www.cloudflare.com/');
|
||||
public function testSimpleRequest()
|
||||
{
|
||||
$http = new HttpClient();
|
||||
$html = $http->request('GET', 'https://www.cloudflare.com/');
|
||||
|
||||
$this->assertContains('CloudFlare', $html['body']);
|
||||
}
|
||||
$this->assertContains('CloudFlare', $html['body']);
|
||||
}
|
||||
|
||||
public function testBaseUrl()
|
||||
{
|
||||
$http = new HttpClient('https://www.cloudflare.com');
|
||||
$html = $http->request('GET', '/');
|
||||
public function testBaseUrl()
|
||||
{
|
||||
$http = new HttpClient('https://www.cloudflare.com');
|
||||
$html = $http->request('GET', '/');
|
||||
|
||||
$this->assertContains('CloudFlare', $html['body']);
|
||||
}
|
||||
$this->assertContains('CloudFlare', $html['body']);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$http = new HttpClient('https://www.cloudflare.com');
|
||||
$html = $http->get('overview', ['x' => 1]);
|
||||
public function testGet()
|
||||
{
|
||||
$http = new HttpClient('https://www.cloudflare.com');
|
||||
$html = $http->get('overview', ['x' => 1]);
|
||||
|
||||
$this->assertContains('CloudFlare', $html['body']);
|
||||
}
|
||||
$this->assertContains('CloudFlare', $html['body']);
|
||||
}
|
||||
|
||||
public function testGetJson()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->get('/key/value');
|
||||
public function testGetJson()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->get('/key/value');
|
||||
|
||||
$this->assertArrayHasKey('key', $data['body']);
|
||||
}
|
||||
$this->assertArrayHasKey('key', $data['body']);
|
||||
}
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->post('/key/value', ['test' => 'x']);
|
||||
public function testPost()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->post('/key/value', ['test' => 'x']);
|
||||
|
||||
$this->assertTrue(is_array($data));
|
||||
}
|
||||
$this->assertTrue(is_array($data));
|
||||
}
|
||||
|
||||
public function testPut()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->put('/key/value', ['test' => 'x']);
|
||||
public function testPut()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->put('/key/value', ['test' => 'x']);
|
||||
|
||||
$this->assertTrue(is_array($data));
|
||||
}
|
||||
$this->assertTrue(is_array($data));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->delete('/key/value', ['test' => 'x']);
|
||||
public function testDelete()
|
||||
{
|
||||
$http = new HttpClient('http://echo.jsontest.com');
|
||||
$data = $http->delete('/key/value', ['test' => 'x']);
|
||||
|
||||
$this->assertTrue(is_array($data));
|
||||
}
|
||||
$this->assertTrue(is_array($data));
|
||||
}
|
||||
}
|
|
@ -6,102 +6,81 @@ use b8\Exception\HttpException;
|
|||
|
||||
class HttpExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testHttpExceptionIsException()
|
||||
{
|
||||
$ex = new HttpException();
|
||||
$this->assertTrue($ex instanceof \Exception);
|
||||
}
|
||||
public function testHttpExceptionIsException()
|
||||
{
|
||||
$ex = new HttpException();
|
||||
$this->assertTrue($ex instanceof \Exception);
|
||||
}
|
||||
|
||||
public function testHttpException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getMessage() == 'Test');
|
||||
$this->assertTrue($ex->getErrorCode() == 500);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
$this->assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
}
|
||||
public function testHttpException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getMessage() == 'Test');
|
||||
$this->assertTrue($ex->getErrorCode() == 500);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
$this->assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
}
|
||||
|
||||
public function testBadRequestException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException\BadRequestException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getErrorCode() == 400);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
}
|
||||
}
|
||||
public function testBadRequestException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException\BadRequestException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 400);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
}
|
||||
}
|
||||
|
||||
public function testForbiddenException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException\ForbiddenException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getErrorCode() == 403);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Forbidden');
|
||||
}
|
||||
}
|
||||
public function testForbiddenException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException\ForbiddenException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 403);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Forbidden');
|
||||
}
|
||||
}
|
||||
|
||||
public function testNotAuthorizedException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException\NotAuthorizedException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getErrorCode() == 401);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Not Authorized');
|
||||
}
|
||||
}
|
||||
public function testNotAuthorizedException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException\NotAuthorizedException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 401);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Not Authorized');
|
||||
}
|
||||
}
|
||||
|
||||
public function testNotFoundException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException\NotFoundException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getErrorCode() == 404);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Not Found');
|
||||
}
|
||||
}
|
||||
public function testNotFoundException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException\NotFoundException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 404);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Not Found');
|
||||
}
|
||||
}
|
||||
|
||||
public function testServerErrorException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException\ServerErrorException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getErrorCode() == 500);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
}
|
||||
}
|
||||
public function testServerErrorException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException\ServerErrorException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 500);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
}
|
||||
}
|
||||
|
||||
public function testValidationException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new HttpException\ValidationException('Test');
|
||||
}
|
||||
catch(HttpException $ex)
|
||||
{
|
||||
$this->assertTrue($ex->getErrorCode() == 400);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
}
|
||||
}
|
||||
public function testValidationException()
|
||||
{
|
||||
try {
|
||||
throw new HttpException\ValidationException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 400);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,131 +6,131 @@ use b8\View, b8\View\UserView;
|
|||
|
||||
class ViewTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSimpleView()
|
||||
{
|
||||
$view = new View('simple', __DIR__ . '/data/view/');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
public function testSimpleView()
|
||||
{
|
||||
$view = new View('simple', __DIR__ . '/data/view/');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testInvalidView()
|
||||
{
|
||||
new View('dogs', __DIR__ . '/data/view/');
|
||||
}
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testInvalidView()
|
||||
{
|
||||
new View('dogs', __DIR__ . '/data/view/');
|
||||
}
|
||||
|
||||
public function testViewVars()
|
||||
{
|
||||
$view = new View('vars', __DIR__ . '/data/view/');
|
||||
$view->who = 'World';
|
||||
public function testViewVars()
|
||||
{
|
||||
$view = new View('vars', __DIR__ . '/data/view/');
|
||||
$view->who = 'World';
|
||||
|
||||
$this->assertTrue(isset($view->who));
|
||||
$this->assertFalse(isset($view->what));
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
$this->assertTrue(isset($view->who));
|
||||
$this->assertFalse(isset($view->what));
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
|
||||
public function testFormatViewHelper()
|
||||
{
|
||||
$view = new View('format', __DIR__ . '/data/view/');
|
||||
$view->number = 1000000.25;
|
||||
$view->symbol = true;
|
||||
public function testFormatViewHelper()
|
||||
{
|
||||
$view = new View('format', __DIR__ . '/data/view/');
|
||||
$view->number = 1000000.25;
|
||||
$view->symbol = true;
|
||||
|
||||
$this->assertTrue($view->render() == '£1,000,000.25');
|
||||
$this->assertTrue($view->render() == '£1,000,000.25');
|
||||
|
||||
$view->number = 1024;
|
||||
$view->symbol = false;
|
||||
$this->assertTrue($view->render() == '1,024.00');
|
||||
}
|
||||
$view->number = 1024;
|
||||
$view->symbol = false;
|
||||
$this->assertTrue($view->render() == '1,024.00');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \b8\Exception\HttpException
|
||||
*/
|
||||
public function testInvalidHelper()
|
||||
{
|
||||
$view = new UserView('{@Invalid:test}');
|
||||
$view->render();
|
||||
}
|
||||
/**
|
||||
* @expectedException \b8\Exception\HttpException
|
||||
*/
|
||||
public function testInvalidHelper()
|
||||
{
|
||||
$view = new UserView('{@Invalid:test}');
|
||||
$view->render();
|
||||
}
|
||||
|
||||
public function testSimpleUserView()
|
||||
{
|
||||
$view = new UserView('Hello');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
public function testSimpleUserView()
|
||||
{
|
||||
$view = new UserView('Hello');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
|
||||
public function testUserViewYear()
|
||||
{
|
||||
$view = new UserView('{@year}');
|
||||
$this->assertTrue($view->render() == date('Y'));
|
||||
}
|
||||
public function testUserViewYear()
|
||||
{
|
||||
$view = new UserView('{@year}');
|
||||
$this->assertTrue($view->render() == date('Y'));
|
||||
}
|
||||
|
||||
public function testUserViewVars()
|
||||
{
|
||||
$view = new UserView('Hello {@who}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
public function testUserViewVars()
|
||||
{
|
||||
$view = new UserView('Hello {@who}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$view = new UserView('Hello {@who}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
$view = new UserView('Hello {@who}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
|
||||
$view = new UserView('Hello {@who.name}');
|
||||
$view->who = ['name' => 'Dan'];
|
||||
$this->assertTrue($view->render() == 'Hello Dan');
|
||||
$view = new UserView('Hello {@who.name}');
|
||||
$view->who = ['name' => 'Dan'];
|
||||
$this->assertTrue($view->render() == 'Hello Dan');
|
||||
|
||||
$tmp = new UserView('Hello');
|
||||
$tmp->who = 'World';
|
||||
$view = new UserView('Hello {@tmp.who}');
|
||||
$view->tmp = $tmp;
|
||||
$tmp = new UserView('Hello');
|
||||
$tmp->who = 'World';
|
||||
$view = new UserView('Hello {@tmp.who}');
|
||||
$view->tmp = $tmp;
|
||||
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$tmp = new UserView('Hello');
|
||||
$view = new UserView('Hello {@tmp.who}');
|
||||
$view->tmp = $tmp;
|
||||
$tmp = new UserView('Hello');
|
||||
$view = new UserView('Hello {@tmp.who}');
|
||||
$view->tmp = $tmp;
|
||||
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
|
||||
$view = new UserView('Hello {@who.toUpperCase}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello WORLD');
|
||||
$view = new UserView('Hello {@who.toUpperCase}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello WORLD');
|
||||
|
||||
$view = new UserView('Hello {@who.toLowerCase}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello world');
|
||||
}
|
||||
$view = new UserView('Hello {@who.toLowerCase}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello world');
|
||||
}
|
||||
|
||||
public function testUserViewIf()
|
||||
{
|
||||
$view = new UserView('Hello{if who} World{/if}');
|
||||
$view->who = true;
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
public function testUserViewIf()
|
||||
{
|
||||
$view = new UserView('Hello{if who} World{/if}');
|
||||
$view->who = true;
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$view = new UserView('Hello{if who} World{/if}');
|
||||
$view->who = false;
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
$view = new UserView('Hello{if who} World{/if}');
|
||||
$view->who = false;
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
|
||||
$view = new UserView('Hello{ifnot who} World{/ifnot}');
|
||||
$view->who = true;
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
$view = new UserView('Hello{ifnot who} World{/ifnot}');
|
||||
$view->who = true;
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
|
||||
$view = new UserView('Hello {if Format:not_present}World{/if}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
$view = new UserView('Hello {if Format:not_present}World{/if}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
|
||||
$view = new UserView('Hello {ifnot Format:not_present}World{/ifnot}');
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
$view = new UserView('Hello {ifnot Format:not_present}World{/ifnot}');
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
|
||||
public function testUserViewLoop()
|
||||
{
|
||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
||||
$view->who = ['W', 'o', 'r', 'l', 'd'];
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
public function testUserViewLoop()
|
||||
{
|
||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
||||
$view->who = ['W', 'o', 'r', 'l', 'd'];
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
|
||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
$view = new UserView('Hello {loop who}{@item}{/loop}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue