Ejemplo n.º 1
0
    return sizeof($rows) && isset($rows[0]["foo"]) && $rows[0]["foo"] == 1;
}, "Database\\Query\\Mysql can alias fields", "Database\\Query\\Mysql");
THCFrame\Core\Test::add(function () use($options) {
    $database = new THCFrame\Database\Database($options);
    $database = $database->initialize();
    $database = $database->connect();
    $rows = $database->query()->from("tb_example", array("tb_example.id" => "foo"))->join("tb_example AS baz", "tb_example.id = baz.id", array("baz.id" => "bar"))->all();
    return sizeof($rows) && $rows[0]["foo"] == $rows[0]["bar"];
}, "Database\\Query\\Mysql can join tables and alias joined fields", "Database\\Query\\Mysql");
THCFrame\Core\Test::add(function () use($options) {
    $database = new THCFrame\Database\Database($options);
    $database = $database->initialize();
    $database = $database->connect();
    $result = $database->query()->from("tb_example")->save(array("number" => 3, "text" => "foo", "boolean" => true));
    return $result == 5;
}, "Database\\Query\\Mysql can insert rows", "Database\\Query\\Mysql");
THCFrame\Core\Test::add(function () use($options) {
    $database = new THCFrame\Database\Database($options);
    $database = $database->initialize();
    $database = $database->connect();
    $result = $database->query()->from("tb_example")->where("id = ?", 5)->save(array("number" => 3, "text" => "foo", "boolean" => false));
    return $result == 0;
}, "Database\\Query\\Mysql can update rows", "Database\\Query\\Mysql");
THCFrame\Core\Test::add(function () use($options) {
    $database = new THCFrame\Database\Database($options);
    $database = $database->initialize();
    $database = $database->connect();
    $database->query()->from("tb_example")->delete();
    return $database->query()->from("tb_example")->count() == 0;
}, "Database\\Query\\Mysql can delete rows", "Database\\Query\\Mysql");
unset($options);
<?php

THCFrame\Core\Test::add(function () {
    $configuration = new THCFrame\Configuration\Configuration();
    return $configuration instanceof THCFrame\Configuration\Configuration;
}, "Configuration instantiates in uninitialized state", "Configuration");
THCFrame\Core\Test::add(function () {
    $configuration = new THCFrame\Configuration\Configuration(array("type" => "ini"));
    $configuration = $configuration->initialize();
    return $configuration instanceof THCFrame\Configuration\Driver\Ini;
}, "Configuration\\Driver\\Ini initializes", "Configuration\\Driver\\Ini");
THCFrame\Core\Test::add(function () {
    $configuration = new THCFrame\Configuration\Configuration(array("type" => "ini"));
    $configuration = $configuration->initialize();
    $parsed = $configuration->parse("_configuration");
    return $parsed->config->first == "hello" && $parsed->config->second->second == "bar";
}, "Configuration\\Driver\\Ini parses configuration files", "Configuration\\Driver\\Ini");
Ejemplo n.º 3
0
    $processed = $template->process();
    return $processed == "foo bar";
}, "Template parses script tag", "Template");
THCFrame\Core\Test::add(function () use($template) {
    $template->parse("\n            {foreach \$number in \$numbers}{echo \$number_i},{echo \$number},{/foreach}");
    $processed = $template->process(array("numbers" => array(1, 2, 3)));
    return trim($processed) == "0,1,1,2,2,3,";
}, "Template parses foreach tag", "Template");
THCFrame\Core\Test::add(function () use($template) {
    $template->parse("\n            {for \$number in \$numbers}{echo \$number_i},{echo \$number},{/for}\n        ");
    $processed = $template->process(array("numbers" => array(1, 2, 3)));
    return trim($processed) == "0,1,1,2,2,3,";
}, "Template parses for tag", "Template");
THCFrame\Core\Test::add(function () use($template) {
    $template->parse("\n            {if \$check == \"yes\"}yes{/if}\n            {elseif \$check == \"maybe\"}yes{/elseif}\n            {else}yes{/else}\n        ");
    $yes = $template->process(array("check" => "yes"));
    $maybe = $template->process(array("check" => "maybe"));
    $no = $template->process(array("check" => null));
    return $yes == $maybe && $maybe == $no;
}, "Template parses if, else and elseif tags", "Template");
THCFrame\Core\Test::add(function () use($template) {
    $template->parse("\n            {macro foo(\$number)}\n                {echo \$number + 2}\n            {/macro}\n            \n            {echo foo(2)}\n        ");
    $processed = $template->process();
    return $processed == 4;
}, "Template parses macro tag", "Template");
THCFrame\Core\Test::add(function () use($template) {
    $template->parse("\n            {literal}\n                {echo \"hello world\"}\n            {/literal}\n        ");
    $processed = $template->process();
    return trim($processed) == "{echo \"hello world\"}";
}, "Template parses literal tag", "Template");
unset($template);
Ejemplo n.º 4
0
<?php

$get = function ($url) {
    $request = new THCFrame\Request\Request();
    return $request->get("http://" . $_SERVER["HTTP_HOST"] . "/{$url}");
};
$has = function ($html, $fields) {
    foreach ($fields as $field) {
        if (!stristr($html, "name=\"{$field}\"")) {
            return false;
        }
    }
    return true;
};
THCFrame\Core\Test::add(function () use($get, $has) {
    $html = $get("register");
    $status = $has($html, array("first", "last", "email", "password", "photo", "register"));
    return $status;
}, "Register form has required fields", "Forms/Users");
THCFrame\Core\Test::add(function () use($get, $has) {
    $html = $get("login");
    $status = $has($html, array("email", "password", "login"));
    return $status;
}, "Login form has required fields", "Forms/Users");
<?php

$post = function ($url, $data) {
    $request = new THCFrame\Request\Request();
    return $request->post("http://" . $_SERVER["HTTP_HOST"] . "/{$url}", $data);
};
THCFrame\Core\Test::add(function () use($post) {
    $html = $post("register", array("first" => "Hello", "last" => "World", "email" => "*****@*****.**", "password" => "password", "register" => "register"));
    return stristr($html, "Your account has been created!");
}, "Register form creates user", "Functions/Users");
THCFrame\Core\Test::add(function () use($post) {
    $html = $post("login", array("email" => "*****@*****.**", "password" => "password", "login" => "login"));
    return stristr($html, "Location: /");
}, "Login form creates user session + redirect to profile", "Functions/Users");
Ejemplo n.º 6
0
    protected $_created;
}
THCFrame\Core\Test::add(function () use($database) {
    $example = new Example();
    return $database->sync($example) instanceof THCFrame\Database\Connector\Mysql;
}, "Model syncs", "Model");
THCFrame\Core\Test::add(function () use($database) {
    $example = new Example(array("name" => "foo", "created" => date("Y-m-d H:i:s")));
    return $example->save() > 0;
}, "Model inserts rows", "Model");
THCFrame\Core\Test::add(function () use($database) {
    return Example::count() == 1;
}, "Model fetches number of rows", "Model");
THCFrame\Core\Test::add(function () use($database) {
    $example = new Example(array("name" => "foo", "created" => date("Y-m-d H:i:s")));
    $example->save();
    $example->save();
    $example->save();
    return Example::count() == 2;
}, "Model saves single row multiple times", "Model");
THCFrame\Core\Test::add(function () use($database) {
    $example = new Example(array("id" => 1, "name" => "hello", "created" => date("Y-m-d H:i:s")));
    $example->save();
    return Example::first()->name == "hello";
}, "Model updates rows", "Model");
THCFrame\Core\Test::add(function () use($database) {
    $example = new Example(array("id" => 2));
    $example->delete();
    return Example::count() == 1;
}, "Model deletes rows", "Model");
unset($database);
Ejemplo n.º 7
0
    return $cache->set("foo", "bar", 5) instanceof THCFrame\Cache\Driver\Memcached;
}, "Cache\\Driver\\Memcached sets values and returns self", "Cache\\Driver\\Memcached");
THCFrame\Core\Test::add(function () {
    $cache = new THCFrame\Cache\Cache(array("type" => "memcached"));
    $cache = $cache->initialize();
    $cache = $cache->connect();
    $value = $cache->get("foo");
    return $cache->get("foo") == "bar";
}, "Cache\\Driver\\Memcached retrieves values: {$value}", "Cache\\Driver\\Memcached");
THCFrame\Core\Test::add(function () {
    $cache = new THCFrame\Cache\Cache(array("type" => "memcached"));
    $cache = $cache->initialize();
    $cache = $cache->connect();
    return $cache->get("404", "baz") == "baz";
}, "Cache\\Driver\\Memcached returns default values", "Cache\\Driver\\Memcached");
THCFrame\Core\Test::add(function () {
    $cache = new THCFrame\Cache\Cache(array("type" => "memcached"));
    $cache = $cache->initialize();
    $cache = $cache->connect();
    // we sleep to void the 5 second cache key/value above
    sleep(5);
    return $cache->get("foo") == null;
}, "Cache\\Driver\\Memcached expires values", "Cache\\Driver\\Memcached");
THCFrame\Core\Test::add(function () {
    $cache = new THCFrame\Cache\Cache(array("type" => "memcached"));
    $cache = $cache->initialize();
    $cache = $cache->connect();
    $cache = $cache->set("hello", "world");
    $cache = $cache->erase("hello");
    return $cache->get("hello") == null && $cache instanceof THCFrame\Cache\Driver\Memcached;
}, "Cache\\Driver\\Memcached erases values and returns self", "Cache\\Driver\\Memcached");