public function testAdditionalEnabledVariants() { $variants = array('sqlite' => true); $settings = new DefaultBuildSettings(array('enabled_variants' => $variants)); ok($settings->getVariant('sqlite')); ok($settings->isEnabledVariant('curl')); }
public function testBasicView() { $action = new CreateUserAction(); ok($action); $view = new ActionKit\View\StackView($action); ok($view); $html = $view->render(); ok($html); $resultDom = new DOMDocument(); $resultDom->loadXML($html); $finder = new DomXPath($resultDom); $nodes = $finder->query("//form"); is(1, $nodes->length); $nodes = $finder->query("//input"); is(4, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-widget')]"); is(8, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-widget-text')]"); is(2, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-label')]"); is(3, $nodes->length); $nodes = $finder->query("//input[@name='last_name']"); is(1, $nodes->length); $nodes = $finder->query("//input[@name='first_name']"); is(1, $nodes->length); }
/** * Инициализация управления вложениями * @return null */ public function init() { /* @var $attach attachments */ $attach = n("attachments"); $act = $_GET["act"]; switch ($act) { case "upload": $type = $_GET["type"]; $toid = $_GET["toid"]; $ret = $attach->change_type($type)->upload($toid); ok(true); print $ret; break; case "download": $attach_id = (int) $_GET["id"]; $preview = (int) $_GET["preview"]; $attach->download($attach_id, $preview); break; case "delete": $attach_id = $_POST["id"]; $ret = $attach->delete($attach_id); if (!$ret) { throw new Exception(); } ok(); break; } die; }
function testExcept() { $v = new ValidationKit\StringValidator(array('except' => 'aaa')); ok($v); ok($v->validate('Find the position of the first occurrence of a substring in a string')); not_ok($v->validate('Find the aaa of the first occurrence of a substring in a string')); }
public function testSQLiteTableParser() { $pdo = new PDO('sqlite::memory:'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ok($pdo); $pdo->query('CREATE TABLE foo ( id integer primary key autoincrement, name varchar(12), phone varchar(32) unique , address text not null );'); $pdo->query('CREATE TABLE bar ( id integer primary key autoincrement, confirmed boolean default false, content blob );'); $parser = new SqliteTableParser(new PDOSQLiteDriver($pdo), $pdo); $tables = $parser->getTables(); $this->assertNotEmpty($tables); $this->assertCount(2, $tables); $sql = $parser->getTableSql('foo'); ok($sql); $columns = $parser->parseTableSql('foo'); $this->assertNotEmpty($columns); $columns = $parser->parseTableSql('bar'); $this->assertNotEmpty($columns); $schema = $parser->reverseTableSchema('bar'); $this->assertNotNull($schema); $id = $schema->getColumn('id'); $this->assertNotNull($id); $this->assertTrue($id->autoIncrement); $this->assertEquals('INTEGER', $id->type); $this->assertEquals('int', $id->isa); $this->assertTrue($id->primary); }
public function testSchemaGenerator() { $g = new SchemaGenerator($this->config, $this->logger); $g->setForceUpdate(true); $schemas = $this->getModels(); foreach ($schemas as $schema) { if ($result = $g->generateCollectionClass($schema)) { list($class, $file) = $result; ok($class); ok($file); path_ok($file); $this->syntaxTest($file); } if ($classMap = $g->generate(array($schema))) { foreach ($classMap as $class => $file) { ok($class); ok($file); path_ok($file, $file); // $this->syntaxTest($file); require_once $file; } } $pk = $schema->findPrimaryKey(); $this->assertNotNull($pk, "Find primary key from " . get_class($schema)); $model = $schema->newModel(); $this->assertNotNull($model); $collection = $schema->newCollection(); $this->assertNotNull($collection); } }
function is_deeply($a, $b, $name = null) { if ($name === null) { $name = 'is_deeply'; } ok(deep_array_compare($a, $b), $name); }
function test() { $validator = new CallbackValidator(function ($value) { return true; }); ok($validator->validate(123)); }
function test() { $store = $this->getStore(); ok($store); $store->destroy(); $store->load(); $user = new \Phifty\JsonStore\FileJsonModel('User', $store); $id = $user->save(array('name' => 123)); ok($id); $store->save(); $items = $store->items(); ok($items); count_ok(1, $items); $user = new \Phifty\JsonStore\FileJsonModel('User', $store); $id = $user->save(array('name' => 333)); ok($id); $items = $store->items(); ok($items); count_ok(2, $items); $user = new \Phifty\JsonStore\FileJsonModel('User', $store); $id = $user->save(array('id' => 99, 'name' => 'with Id')); ok($id); ok($store->get(99)); ok($store->get("99")); $items = $store->items(); ok($items); count_ok(3, $items); ok($store->destroy()); }
public function testGetRegionId() { $region = new Region('/bs/news/crud/edit', array('id' => 1)); $id = $region->getRegionId(); ok($id); ok($region->render()); }
function test() { $username = new FormKit\Widget\TextInput('username', array('label' => 'Username')); $username->value('default')->maxlength(10)->minlength(3)->size(20); $password = new FormKit\Widget\PasswordInput('password', array('label' => 'Password')); $remember = new FormKit\Widget\CheckboxInput('remember', array('label' => 'Remember me')); $remember->value(12); $remember->check(); $widgets = new FormKit\WidgetCollection(); ok($widgets); $widgets->add($username); $widgets->add($password); $widgets->add($remember); // get __get method is($username, $widgets->username); is($password, $widgets->password); is($username, $widgets->get('username')); ok($widgets->render('username')); ok(is_array($widgets->getJavascripts())); ok(is_array($widgets->getStylesheets())); is(3, $widgets->size()); $widgets->remove($username); is(2, $widgets->size()); unset($widgets['password']); is(1, $widgets->size()); }
/** * Инициализация Ajax-части чата * @return null */ public function init() { lang::o()->get("blocks/chat"); $id = (int) $_GET['id']; switch ($_GET["act"]) { case "text": $this->get_text($id); die; break; case "delete": $this->delete($id); ok(); break; case "truncate": $this->truncate(); die(lang::o()->v('chat_no_messages')); break; case "save": $this->save($_POST['text'], $id); ok(); break; default: $this->show((int) $_GET['time'], (bool) $_GET['prev']); break; } }
public function test() { $con = new ProductResourceController(); ok($con); $routes = $con->getActionRoutes(); ok($routes); $methods = $con->getActionMethods(); ok($methods); $productMux = $con->expand(); // there is a sorting bug (fixed), this tests it. ok($productMux); $root = new Mux(); ok($root); $root->mount('/product', $con->expand()); $_SERVER['REQUEST_METHOD'] = 'GET'; ok($root->dispatch('/product/10')); $_SERVER['REQUEST_METHOD'] = 'DELETE'; ok($root->dispatch('/product/10')); $_SERVER['REQUEST_METHOD'] = 'POST'; ok($root->dispatch('/product')); // create $_SERVER['REQUEST_METHOD'] = 'POST'; ok($root->dispatch('/product/10')); // update }
function test() { $region = new Phifty\Web\Region('/bs/news/crud/edit', array('id' => 1)); $id = $region->getRegionId(); ok($id); ok($region->render()); }
public function testSetQuiet() { $make = new MakeTask($this->createLogger(), new OptionResult()); not_ok($make->isQuiet()); $make->setQuiet(); ok($make->isQuiet()); }
public function testClassnames() { $classes = CompletionUtils::classnames(); ok(is_array($classes)); $classes = CompletionUtils::classnames('/CLI/'); ok(is_array($classes)); }
public function testImageParam() { $image = new ImageParam('photo'); ok($image->size(['width' => 100, 'height' => 200])); ok($image->autoResize(false)); ok($image->autoResize(true)); }
public function testTemplate() { $t = new Template(); $t->init(); ok($t); ok($t->getClassDir()); }
public function testAnnotations() { if (defined('HHVM_VERSION')) { echo "HHVM does not support Reflection to expand controller action methods"; return; } $controller = new ExpandableProductController(); $this->assertTrue(is_array($map = $controller->getActionMethods())); $routes = $controller->getActionRoutes(); $this->assertNotEmpty($routes); $this->assertEquals('', $routes[0][0], 'the path'); $this->assertEquals('indexAction', $routes[0][1], 'the mapping method'); $mux = new Pux\Mux(); // works fine // $submux = $controller->expand(); // $mux->mount('/product', $submux ); // gc scan bug $mux->mount('/product', $controller->expand()); $paths = array('/product/delete' => 'DELETE', '/product/update' => 'PUT', '/product/add' => 'POST', '/product/foo/bar' => null, '/product/item' => 'GET', '/product' => null); foreach ($paths as $path => $method) { if ($method) { $_SERVER['REQUEST_METHOD'] = $method; } else { $_SERVER['REQUEST_METHOD'] = 'GET'; } ok($mux->dispatch($path), $path); } }
public function testMigrationByDiff() { $this->conn->query('DROP TABLE IF EXISTS users'); $this->conn->query('DROP TABLE IF EXISTS test'); $this->conn->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)'); if (!file_exists('tests/migrations_testing')) { mkdir('tests/migrations_testing'); } $generator = new MigrationGenerator(Console::getInstance()->getLogger(), 'tests/migrations_testing'); ok(class_exists('TestApp\\Model\\UserSchema', true)); $finder = new SchemaFinder(); $finder->find(); list($class, $path) = $generator->generateWithDiff('DiffMigration', $this->getDriverType(), ["users" => new TestApp\Model\UserSchema()], '20120101'); require_once $path; ok($class::getId()); /* $userSchema = new TestApp\Model\UserSchema; $column = $userSchema->getColumn('account'); */ // run migration $runner = new MigrationRunner($this->logger, $this->getDriverType()); $runner->resetMigrationId($this->conn, $this->queryDriver); $runner->load('tests/migrations_testing'); // XXX: PHPUnit can't run this test in separated unit test since // there is a bug of serializing the global array, this assertion will get 5 instead of the expected 1. $scripts = $runner->loadMigrationScripts(); $this->assertNotEmpty($scripts); // $this->assertCount(1, $scripts); // $this->expectOutputRegex('#DiffMigration_1325347200#'); $runner->runUpgrade($this->conn, $this->queryDriver, [$class]); # echo file_get_contents($path); unlink($path); $this->conn->query('DROP TABLE IF EXISTS users'); }
public function test() { if (!extension_loaded('apc') && !extension_loaded('apcu')) { // echo 'APC or APCu extension is required.'; return; } $con = new ProductResource2Controller(); ok($con); $routes = $con->getActionRoutes(); ok($routes); $methods = $con->getActionMethods(); ok($methods); $productMux = $con->expand(); // there is a sorting bug (fixed), this tests it. ok($productMux); $root = new Mux(); ok($root); $root->mount('/product', $con->expand()); $dispatcher = new APCDispatcher($root, array('namespace' => 'tests', 'expiry' => 10)); $_SERVER['REQUEST_METHOD'] = 'GET'; ok($dispatcher->dispatch('/product/10') == $root->dispatch('/product/10')); $_SERVER['REQUEST_METHOD'] = 'DELETE'; ok($dispatcher->dispatch('/product/10') == $root->dispatch('/product/10')); $_SERVER['REQUEST_METHOD'] = 'POST'; ok($dispatcher->dispatch('/product') == $root->dispatch('/product')); // create $_SERVER['REQUEST_METHOD'] = 'POST'; ok($dispatcher->dispatch('/product/10') == $root->dispatch('/product/10')); // update }
public function testSetConfigStash() { $config = new ConfigLoader(); $config->setLoaded(true); $config->setConfigStash(array('schema' => array('auto_id' => true))); ok($config); }
function test() { $creator = new CornelTek\DBUtil(); $conn = $creator->create('mysql', array('username' => 'root', 'password' => '123123', 'database' => 'mysql_test')); ok($conn); $creator->dropFromConnection($conn, 'mysql_test'); }
public function testRouteExecutor() { $mux = new \Pux\Mux(); ok($mux); $mux->add('/hello/:name', array('HelloController2', 'helloAction'), array('require' => array('name' => '\\w+'))); $mux->add('/product/:id', array('ProductController', 'itemAction')); $mux->add('/product', array('ProductController', 'listAction')); $mux->add('/foo', array('ProductController', 'fooAction')); $mux->add('/bar', array('ProductController', 'barAction')); $mux->add('/', array('ProductController', 'indexAction')); ok($r = $mux->dispatch('/')); is('index', RouteExecutor::execute($r)); ok($r = $mux->dispatch('/foo')); is('foo', RouteExecutor::execute($r)); ok($r = $mux->dispatch('/bar')); is('bar', RouteExecutor::execute($r)); // XXX: seems like a gc bug here return; $cb = function () use($mux) { $r = $mux->dispatch('/product/23'); RouteExecutor::execute($r); }; for ($i = 0; $i < 100; $i++) { call_user_func($cb); } for ($i = 0; $i < 100; $i++) { ok($r = $mux->dispatch('/product/23')); is('product item 23', RouteExecutor::execute($r)); } ok($r = $mux->dispatch('/hello/john')); is('hello john', RouteExecutor::execute($r)); }
public function test() { $memcache = new LazyRecord\Cache\Memcache(array('servers' => array(array('host' => 'localhost', 'port' => 11211)))); ok($memcache); $memcache->set('foo', '123'); ok($memcache->get('foo')); is('123', $memcache->get('foo')); }
function test() { $element = new Element('div'); ok($element); is('<div/>', $element->render()); $element->addChild(new DOMText('Text')); is('<div>Text</div>', $element->render()); }
public function testCurrentUserService() { $kernel = kernel(); $service = new Phifty\ServiceProvider\CurrentUserServiceProvider(); $service->register($kernel, array()); ok($service); ok($kernel->currentUser); }
public function testQuery() { $q = new DropDatabaseQuery('test'); ok($q); $this->assertSql("DROP DATABASE `test`", $q); $q->drop('test2'); $this->assertSql("DROP DATABASE `test2`", $q); }
public function testRemoveVariant() { $settings = new BuildSettings(); $settings->enableVariant('sqlite', true); ok($settings->hasVariant('sqlite')); $settings->removeVariant('sqlite'); not_ok($settings->hasVariant('sqlite')); }
public function test() { ob_start(); $cmd = new PhpBrew\CommandBuilder('ls'); ok($cmd); ok($cmd->execute()); ob_end_clean(); }