function test_file_mime_content_type() { assert_not_empty(file_mime_content_type('')); assert_not_empty(file_mime_content_type('my_file')); assert_equal(file_mime_content_type('my_file'), 'application/octet-stream'); assert_equal(file_mime_content_type('my_file.txt'), 'text/plain'); assert_equal(file_mime_content_type('my_file.TXT'), 'text/plain'); assert_equal(file_mime_content_type('my_file.jpg'), 'image/jpeg'); assert_equal(file_mime_content_type('my_file.JPG'), 'image/jpeg'); }
function test_router_route() { assert_empty(route()); $r = route("get", "/index", "my_func"); assert_length_of($r, 1); assert_length_of($r[0], 5); assert_equal($r[0]["method"], "GET"); assert_equal($r[0]["pattern"], "#^/index(?:/*?)?\$#i"); assert_empty($r[0]["names"]); assert_equal($r[0]["function"], "my_func"); assert_empty($r[0]["options"]); $r = route("put", "/blog/:id", "my_update_func"); assert_length_of($r, 2); assert_length_of($r[1], 5); assert_equal($r[1]["method"], "PUT"); assert_match($r[1]["pattern"], "/blog/102"); assert_length_of($r[1]["names"], 1); assert_equal($r[1]["names"][0], "id"); assert_equal($r[1]["function"], "my_update_func"); assert_empty($r[1]["options"]); $r = route("post", "/blog/:id", "my_post_func", array('params' => array('extra' => 10))); assert_length_of($r[2], 5); assert_equal($r[2]["method"], "POST"); assert_match($r[2]["pattern"], "/blog/102"); assert_length_of($r[2]["names"], 1); assert_equal($r[2]["names"][0], "id"); assert_equal($r[2]["function"], "my_post_func"); assert_not_empty($r[2]["options"]); assert_not_empty($r[2]["options"]['params']); assert_equal($r[2]["options"]['params']['extra'], 10); $r = route("get", "/blog/:id", "my_get_func", array('params' => array('id' => 10))); assert_match($r[2]["pattern"], "/blog/102"); }
function test_error() { $this->curl->get('diaewkaksdljf-invalid-url-dot-com.com'); assert_not_empty($this->curl->error()); }
function test_main_require_once_dir() { $root = dirname(dirname(__FILE__)); ob_start(); assert_empty(require_once_dir($root)); $files = require_once_dir($root, "AUTHORS"); assert_empty(ob_get_contents()); ob_clean(); assert_length_of($files, 1); assert_match('/AUTHORS$/', $files[0]); ob_start(); $files = require_once_dir($root, "CHANGES", false); assert_not_empty(ob_get_contents()); ob_clean(); $lib = $root.'/lib'; // pb because it loads abstract.php that conflict with tests that use abstracts // $limonade = $lib.'/limonade'; // // $files = require_once_dir($limonade); // assert_not_empty($files); $tests_lib = $root.'/tests/data/lib0'; $libs = array('a', 'b', 'c'); foreach($libs as $lib) assert_false(defined('TEST_LIB_'.strtoupper($lib))); $files = require_once_dir($tests_lib); assert_not_empty($files); assert_length_of($files, 3); foreach($libs as $lib) assert_true(defined('TEST_LIB_'.strtoupper($lib))); assert_empty(require_once_dir($root.'/tests/data/')); assert_true(is_array(require_once_dir($root.'/tests/data/'))); assert_empty(require_once_dir($root.'/tests/data/unknown_dir')); assert_true(is_array(require_once_dir($root.'/tests/data/unknown_dir'))); }
function test_main_require_once_dir() { $root = dirname(dirname(__FILE__)); ob_start(); assert_empty(require_once_dir($root)); $files = require_once_dir($root, "AUTHORS"); ob_clean(); assert_length_of($files, 1); assert_match('/AUTHORS$/', $files[0]); $lib = $root . '/lib'; $limonade = $lib . '/limonade'; $files = require_once_dir($limonade); assert_not_empty($files); $tests_lib = $root . '/tests/data/lib0'; $libs = array('a', 'b', 'c'); foreach ($libs as $lib) { assert_false(defined('TEST_LIB_' . strtoupper($lib))); } $files = require_once_dir($tests_lib); assert_not_empty($files); assert_length_of($files, 3); foreach ($libs as $lib) { assert_true(defined('TEST_LIB_' . strtoupper($lib))); } assert_empty(require_once_dir($root . '/tests/data/')); assert_true(is_array(require_once_dir($root . '/tests/data/'))); assert_empty(require_once_dir($root . '/tests/data/unknown_dir')); assert_true(is_array(require_once_dir($root . '/tests/data/unknown_dir'))); }