public function testDisableCaching() { b8\Registry::getInstance()->set('DisableCaching', true); $cache = b8\Cache::getInstance(); $this->assertFalse($cache->isEnabled()); $this->assertFalse($cache->set('anything', 10)); $this->assertTrue(is_null($cache->get('anything'))); b8\Registry::getInstance()->set('DisableCaching', false); }
public function testGetSetUnsetParam() { Registry::forceReset(); $r = Registry::getInstance(); $this->assertTrue($r->getParam('cat', false) == false); $r->setParam('cat', 'dog'); $this->assertTrue($r->getParam('cat', false) == 'dog'); $r->unsetParam('cat'); $this->assertTrue($r->getParam('cat', false) == false); }
public function testFormBasics() { $f = new Form(); $f->setAction('/'); $f->setMethod('POST'); $this->assertTrue($f->getAction() == '/'); $this->assertTrue($f->getMethod() == 'POST'); Registry::getInstance()->set('ViewPath', dirname(__FILE__) . '/data/view/'); $this->assertTrue($f->render('form') == '/POST'); Registry::getInstance()->set('ViewPath', ''); $this->assertTrue(strpos((string) $f, '<form') !== false); }
/** * @depends testGeneratedStores */ public function testGeneratedControllers() { require_once self::$_base . 'Generation/Controller/Base/UnoControllerBase.php'; require_once self::$_base . 'Generation/Controller/Base/DosControllerBase.php'; require_once self::$_base . 'Generation/Controller/Base/TresControllerBase.php'; require_once self::$_base . 'Generation/Controller/UnoController.php'; require_once self::$_base . 'Generation/Controller/DosController.php'; require_once self::$_base . 'Generation/Controller/TresController.php'; require_once self::$_base . 'TestUser.php'; $uno = new Generation\Controller\UnoController(); $dos = new Generation\Controller\DosController(); $tres = new Generation\Controller\TresController(); $uno->init(); $dos->init(); $tres->init(); $this->assertTrue($uno instanceof b8\Controller); $this->assertTrue($dos instanceof b8\Controller); $this->assertTrue($tres instanceof b8\Controller); $this->assertTrue($uno instanceof Generation\Controller\Base\UnoControllerBase); $this->assertTrue($dos instanceof Generation\Controller\Base\DosControllerBase); $this->assertTrue($tres instanceof Generation\Controller\Base\TresControllerBase); Registry::getInstance()->setParam('hello', 'world'); $this->assertTrue($uno->getParam('hello', 'dave') == 'world'); $uno->setParam('hello', 'dave'); $this->assertTrue($uno->getParam('hello', 'world') == 'dave'); $this->assertTrue(array_key_exists('hello', $uno->getParams())); $uno->unsetParam('hello'); $this->assertFalse(array_key_exists('hello', $uno->getParams())); $testUser = new \TestUser(); $uno->setActiveUser($testUser); $dos->setActiveUser($uno->getActiveUser()); $tres->setActiveUser($uno->getActiveUser()); $unoModel = new Generation\Model\Uno(); $unoStore = \b8\Store\Factory::getStore('Uno'); $unoModel->setFieldVarchar('Hi'); $unoStore->save($unoModel); $list = $uno->index(); $this->assertTrue(is_array($list)); $this->assertTrue(is_array($list['items'])); $this->assertTrue(count($list['items']) > 0); $caught = false; try { $dos->index(); } catch (Exception $ex) { $caught = true; } $this->assertTrue($caught); $first = array_shift($list['items']); $uno1 = $uno->get($first['id']); $this->assertTrue(is_array($uno1)); $this->assertTrue(isset($uno1['uno'])); $this->assertTrue($uno1['uno']['id'] == $first['id']); $caught = false; try { $dos->get(1); } catch (Exception $ex) { $caught = true; } $this->assertTrue($caught); $uno->setParam('field_varchar', 'Un'); $uno1 = $uno->put($first['id']); $this->assertTrue($uno1['uno']['id'] == $first['id']); $caught = false; try { $dos->put(1); } catch (Exception $ex) { $caught = true; } $this->assertTrue($caught); $this->assertTrue(is_null($uno->put(10000))); $uno->setParam('field_text', 'Hello'); $res = $uno->post(); $this->assertTrue($res['uno']['field_varchar'] == 'Un'); $this->assertTrue(!empty($res['uno']['id'])); $caught = false; try { $dos->post(); } catch (Exception $ex) { $caught = true; } $this->assertTrue($caught); $del = $uno->delete($res['uno']['id']); $this->assertTrue($del['deleted']); $del = $uno->delete($res['uno']['id']); $this->assertFalse($del['deleted']); $del = $tres->delete(100); $this->assertFalse($del['deleted']); $caught = false; try { $dos->delete(1000); } catch (Exception $ex) { $caught = true; } $this->assertTrue($caught); //---- // Tests for _parseWhere() //---- $uno->setParam('where', array('id' => array(1000))); $uno->setParam('neq', 'id'); $list = $uno->index(); $this->assertTrue(is_array($list)); $this->assertTrue(count($list['items']) != 0); Registry::getInstance()->forceReset(); $uno->setParam('where', array('id' => 1000)); $uno->setParam('fuzzy', 'id'); $list = $uno->index(); $this->assertTrue(is_array($list)); $this->assertTrue(count($list['items']) == 0); }