/** * Exception assertion * @param $exception_class * @param null $res * @param string $title * @return bool|null */ function test_except($exception_class, $action = null, $title = '') { $res = false; // closure if ($action instanceof Closure) { try { $res = $action(); } catch (Exception $e) { if ($exception_class == get_class($e)) { $res = true; } $title .= " !Exception: " . get_class($e) . ', ' . $e->getMessage(); } } return test_assert($res, $title); }
<?php require '../loader.php'; /** @var sqlite3_db $db */ $connection = core::lib('db'); /* var_dump( $id = $connection->query('PRAGMA table_info (sat_sat_file)'), $connection->sql_error(), $connection->fetch_all('PRAGMA table_info (sat_sat_file)') ); */ // dd($connection->fetch_all("PRAGMA table_info('sat_test_images')")); //test_assert($connection->query("PRAGMA table_info('sat_test_images')")->fetchAll()[0]['name'] == 'id'); test_assert($connection->fetch_all("SELECT * FROM sqlite_master WHERE type='table' AND name LIKE 'sat_test_images'")[0]['name'] == 'sat_test_images'); test_assert($connection->fetch_all("PRAGMA table_info('sat_test_images')")[0]['name'] == 'id'); // SELECT * FROM sqlite_master WHERE type='table' AND name LIKE 'sat_sat_file'
function remove_after() { test_assert(!$this->model->behavior('Sat.ImageAttachs')->get_attachs()->count()); }
<?php require "../loader.php"; /** @var mail_tpl_collection */ $tmail = core::get_instance()->get_mail_tpl_handle(); /** @var \tf\module\core\mail_tpl_item */ $item = $tmail->where('name', "feedback")->load_first(); test_assert($item instanceof mail_tpl_item); $to = '*****@*****.**'; $vars = array('message' => 'blabla', 'title' => 'Hello from ' . __FILE__); test_assert($item->send($to, $vars));
<?php require '../loader.php'; class test_config extends abs_config { } $config = new test_config(); test_assert($config instanceof abs_config, 'abs_config'); test_assert(null === $config->cfg('test.data.id'), 'cache get 1'); $config->set_cfg_var('test.data.id', array('title' => 'hello')); if (!test_assert(array('title' => 'hello') === ($test = $config->cfg('test.data.id')), 'cache get 2')) { test_print($test); } $config->set_cfg_var('simple', 657); if (!test_assert(657 === ($test = $config->cfg('simple')), 'cache get 2.1')) { test_print($test); } $config->unset_cfg_var('test.data.id'); test_assert(null === $config->cfg('test.data.id'), 'cache get 3');
<?php require '../../loader.php'; $core = core::get_instance(); /** @var test_images_collection $collection */ $collection = $core->model('test_images'); // // $collection->append() // $collection->set_working_fields('update_date'); $date = '20.01.1983 10:30'; $ID = $collection->create(['update_date' => $date]); $newbie = $collection->get_last_item(); $item = $collection->load_only_id($ID); test_assert($ID && $item && $newbie && $item->id === $newbie->id); /// 'default' => 'now' /// test_print($item->render('update_date'), $item->update_date); test_assert($item->update_date === strtotime($date)); test_assert($date === $item->render('update_date') && $date === $newbie->render('update_date'));
require '../loader.php'; $core = core::selfie(); $colors = $core->model('test_images'); $colors->remove_all_fast(); /*->is_render_by_key(false) ->set_where("pid = %d AND value <> 0", 12) ->set_order('date DESC') ->set_limit(2) ->load()*/ $colors->load_from_array(array(array('id' => 1, 'title' => '1', 'text' => '#А'), array('id' => 2, 'title' => '2', 'text' => '#Б'), array('id' => 3, 'title' => '3', 'text' => '#В'))); test_assert($colors->count() === 3); test_assert($colors->get_item()->is_new()); test_assert($colors->get_item()->is_allocated()); test_assert($colors->get_item()->text == '#А'); $item = $colors->get_item(); $item->save(); test_assert(!$item->is_new()); test_assert(!$item->is_allocated()); test_assert($item->text == '#А'); $colors->clear()->load(); test_assert($colors->count() === 1); test_assert(!$colors->get_item()->is_new()); test_assert(!$colors->get_item()->is_allocated()); test_assert($colors->get_item()->text == '#А'); $item = $colors->get_item(); $item->text = '#UЮ'; $item->save(); $item = $colors->clear()->load()->get_item(); test_assert($item->text == '#UЮ');
<?php require '../loader.php'; $core = core::get_instance(); test_assert(function () use($core) { $ctypes = $core->get_ctypes(); return $ctypes && $ctypes instanceof ctype_collection; }, 'node ctype'); $node_ctype = $core->get_ctype('sat.node'); test_assert($node_ctype && $node_ctype->id === 200, 'node ctype'); $node_ctype = $core->get_ctype(200, false); test_assert($node_ctype && $node_ctype->model === 'sat.node', 'node ctype by ID'); if (!test_assert(($test = core::module('sat')->get_node_handle()->get_ctype()->id) === 200, 'model ctypeID')) { test_print($test); } if (!test_assert(($test = core::module('sat')->get_node_handle()->_get_ctype()) === 'sat.node', 'model ctype')) { test_print($test); }
<?php require "../loader.php"; /** @var abs_collection */ $collection = core::get_instance()->class_register('test_images'); $collection->load_from_array($array = array(2 => array('id' => 3, 'title' => 'zz2'), 6 => array('id' => 4, 'title' => 'zz3'), 1 => array('id' => 1, 'title' => 'zz'), 3 => array('id' => 2, 'title' => 'zz1'), 4 => array('id' => 5, 'title' => 'zz4'), 5 => array('id' => 6, 'title' => 'zz5'))); $collection->is_render_by_key('title'); test_assert(!empty($collection->render()['zz2']));
if (!empty($argv[1])) { return; } require '../loader.php'; $core = core::get_instance(); $m = memory_get_usage(); test_print("PHP " . PHP_VERSION . " MEM: " . sprintf('%u', $m)); /** @var abs_collection */ $cdata = $core->model('test_images'); test_print("CREATE COLLECTION MEM " . sprintf('%u', memory_get_usage() - $m)); $m = memory_get_usage(); $item = $cdata->set_where("id = %d", 1)->set_limit(1)->load()->get_item(); $item->title = uniqid(); test_print("LOAD ONE MEM: " . sprintf('%u', memory_get_usage() - $m)); $m = memory_get_usage(); $cdata->_fake_items(1000); foreach ($cdata as $item) { $item->title = uniqid(); } test_assert($cdata->count() == 1001); test_print("FAKE 1000 MEM " . sprintf('%u', memory_get_usage() - $m)); /* BOOT 5.3.10: 7088240 CREATE COLLECTION: 11624 LOAD ONE: 6416 FAKE 1000: 2661000 BOOT 5.4.3: 3572872 CREATE COLLECTION: 11496 LOAD ONE: 5512 FAKE 1000: 1717136 */
<?php define('TF_SKIP_DATABASE', true); require '../loader.php'; /** @var sape_cacher */ $cacher = core::lib('sape_cacher'); test_assert($cacher instanceof sape_cacher, 'instance'); // cache for 3 sec $cacher->set('test/data', 'id', array('title' => 'hello'), 3); if (!test_assert(array('title' => 'hello') === ($test = $cacher->get('test/data', 'id')), 'cache get')) { test_print($test); } // sleep not kill cache, clean on next request sleep(5); test_assert(null === $cacher->get('test/data', 'id'), 'cache get timeout');
<?php require '../../loader.php'; $core = core::get_instance(); /** @var test_images_collection $collection */ $collection = $core->model('test_images'); $collection->remove_all_fast(); $collection->create(array('title' => 'Оно%^&толе*')); test_assert('онотоле' == $collection->get_last_item()->slug, 'slug'); $collection->update_vfs(function (&$fields) { $fields['slug']['make_seo']['translit'] = true; }); $collection->create(array('title' => 'Онотоле')); test_assert('onotole' == $collection->get_last_item()->slug, 'translit'); $collection->create(array('title' => '^^$#Оно%^&толе*')); test_assert(strpos($collection->get_last_item()->slug, 'onotole-') === 0, 'same slug');
<?php require '../loader.php'; $reftest = new referenceTest(); $dataA = ['param' => 1]; $dataO = new stdClass(['param' => 1]); $reftest->testA(reference::make($dataA)); test_assert($dataA['param'] === 'helloA'); $reftest->testO(reference::make($dataO)); test_assert($dataO->param === 'helloO'); test_except('tf_exception', function () use($reftest, $dataO) { $reftest->testA(reference::make($dataO)); }); class referenceRunner { function testA($data) { $data['param'] = 'helloA'; } function testO($data) { $data->param = 'helloO'; } } class referenceTest { protected $rr; function __construct() { $this->rr = new referenceRunner(); }
<?php require '../loader.php'; $core = core::get_instance(); /** @var abs_collection $collection */ $collection = $core->model('test_images'); test_assert($collection->get_formats()->get('editor.list.text.hidden')); test_assert(!$collection->get_field('text', 'hidden')); $collection->set_format('editor'); test_assert(!$collection->get_field('text', 'hidden')); $collection->set_format('editor.list'); test_assert($collection->get_field('text', 'hidden')); $vf = $collection->get_field('virtual_field'); test_assert($vf['type'] == 'virtual'); $item = $collection->alloc(['id' => 2]); // closure-virtual test_assert('view#2' === $item->render('virtual_field')); $collection->set_format(); test_assert(!$collection->get_field('text', 'hidden')); //test_assert(false === $collection->get_formats(), 'null test #1'); //test_assert(false === $collection->get_item_by_prop('name', 8888), 'null test #2');
<?php // php中断言的使用 function assert_failure() { echo 'Assert Failed'; // echo cli_get_process_title(); // echo cli_get_process_title(); } function test_assert($parameter) { assert(is_bool($parameter)); //assert(is_bool($parameter)); //assert(is_bool($parameter)); //assert(is_bool($parameter)); //assert(is_bool($parameter)); } assert_options(ASSERT_ACTIVE, true); assert_options(ASSERT_BAIL, true); assert_options(ASSERT_WARNING, false); assert_options(ASSERT_CALLBACK, 'assert_failure'); test_assert(1); echo "Never reached";
<?php define('TF_SKIP_DATABASE', true); require '../loader.php'; /** @var MultiCacheFile */ $cacher = core::lib('cache')->get_file_handle(); test_assert($cacher instanceof MultiCacheFile, 'instance'); // cache for 3 sec $cacher->set('test', array('title' => 'hello'), 3); if (!test_assert(array('title' => 'hello') === ($test = $cacher->get('test')), 'cache get')) { test_print($test); } // sleep not kill cache, clean on next request sleep(5); test_assert(null === $cacher->get('test'), 'cache get timeout');
<?php require '../loader.php'; $core = core::get_instance(); $items = $core->model('test_images'); $items->append($items->alloc(array('id' => 1))); test_assert($items->count() === 1, 'count'); /** @var abs_collection_item $item */ $item = $items->get_item(); $item->invokeMethod = function ($item) { test_print('invokeMethod#' . $item->id); $item->hello = '@hello'; return 'closure-compiled'; }; test_assert(!$item->get_data('hello')); /* test_except('collection_exception' , function() use ($item) { $item->get_data('hello');} , 'get-null'); */ $items->invoke('invokeMethod'); // test_assert('@hello' === $item->hello, 'get 2'); test_print($item->render()); // test_assert($item->is_new(), 'new'); // PHP 5.2 //$users->invoke('dump'); // PHP 5.3 //$users->invoke(function($item){$item->dump();});
<?php require '../loader.php'; $core = core::selfie(); $ci = $core->model('test_images'); test_assert('test_images_collection' === get_class($ci)); $ci = $core->model('sat.sat_node'); test_assert('sat_node_collection' === get_class($ci)); $ci = $core->model(array('sat', 'sat_node')); test_assert('sat_node_collection' === get_class($ci));
function testMetaData() { $client = new RiakClient(HOST, PORT); $bucket = $client->bucket("metatest"); # Set some meta $bucket->newObject("metatest", array("foo" => 'bar'))->setMeta("foo", "bar")->store(); # Test that we load the meta back $object = $bucket->get("metatest"); test_assert($object->getMeta("foo") == "bar"); # Test that the meta is preserved when we rewrite the object $bucket->get("metatest")->store(); $object = $bucket->get("metatest"); test_assert($object->getMeta("foo") == "bar"); # Test that we remove meta $object->removeMeta("foo")->store(); $anotherObject = $bucket->get("metatest"); test_assert($anotherObject->getMeta("foo") === null); }
<?php require __DIR__ . "/../../core/_tests/loader.php"; $module = core::module('test'); test_assert($module->get_name() == 'test'); test_assert($module->model('article')->get_ctype()->model == 'test.article');
<?php require '../loader.php'; $core = core::get_instance(); /** @var abs_collection $collection */ $collection = $core->model('test_images'); $condition = '22\';11"`<>,.!#$\\:'; test_assert('"22\'\';11"`<>,.!#$\\:"' === $collection->connection()->escape($condition), 'condition.1'); $filter = $collection->get_filter(); $filter->set_filter('title', $condition, 'BEGINS', 'AND'); dd($filter->get_filters(), $filter->apply_count(), $filter->get_collection()->get_last_query(), $filter->apply_count(), $filter->get_collection()->get_last_query());
<?php require '../loader.php'; /** @var tf_renderer $r */ $r = core::lib('renderer'); /** @var Smarty3 $smarty */ $smarty = $r->get_parser(); if (!test_assert('{"first":0,"second":1}' === ($test = $smarty->fetch('string:{"first: no, second: \'yes\'"|to_array|json_encode}')), 'test boolean yes-no')) { test_print($test); } if (!test_assert('{"first":"firstValue","second":"secondValue"}' === ($test = $smarty->fetch('string:{"first: \'firstValue\', second: \'secondValue\'"|to_array|json_encode}')))) { test_print($test); } if (!test_assert('{"first":"firstValue","second":"secondValue With Space","third":"thirdValue","fourth":"Fourth Value 3"}' === ($test = $smarty->fetch('string:{"first: firstValue, second: \'secondValue With Space\', third: thirdValue, fourth: \'Fourth Value 3\'"|to_array|json_encode}')))) { test_print($test); } if (!test_assert('{"title":"Hello","dialogClass":"modal-xxl","int":"65"}' === ($test = $smarty->fetch('string:{"title: \'Hello\', dialogClass: \'modal-xxl\' , int : 65 "|to_array|json_encode}')))) { test_print($test); }
function testLinkWalking() { # Create the object... $client = new RiakClient(HOST, PORT); $bucket = $client->bucket("bucket"); $bucket->newObject("foo", 2)->addLink($bucket->newObject("foo1", "test1")->store())->addLink($bucket->newObject("foo2", "test2")->store(), "tag")->addLink($bucket->newObject("foo3", "test3")->store(), "tag2!@#\$%^&*")->store(); $obj = $bucket->get("foo"); $results = $obj->link("bucket")->run(); test_assert(count($results) == 3); $results = $obj->link("bucket", "tag")->run(); test_assert(count($results) == 1); }
<?php require "../loader.php"; /** @var sessions_collection $s */ $s = core::module('users')->get_sessions_handle(); /* * uip,uid,last_update,skey,sid,sdata) VALUES * (3285203570,0,1400497136,'e19766aad5b5e70c941abbe03d7a29ba','9756894d70bfebbde8c2b1fa9ee15fb8',''); */ $id = $s->create(['uip' => 3285203570, 'skey' => 'e19766aad5b5e70c941abbe03d7a29ba', 'sid' => '9756894d70bfebbde8c2b1fa9ee15fb8']); test_assert($id && ($count = $s->count_sql()), 'x' . $count); /** @var sessions_item $session */ $session = $s->load_only_id($id); test_assert($session->uip == 3285203570, '3285203570 <> ' . $session->uip . ' : ' . $session->uip_string); // test_assert($session->skey === 'e19766aad5b5e70c941abbe03d7a29ba', 'e19766aad5b5e70c941abbe03d7a29ba <> ' . $session->skey); test_assert($session->sid === '9756894d70bfebbde8c2b1fa9ee15fb8', $session->sid); dd($session->as_array());
<?php // sqlite fails this tests require '../loader.php'; $core = core::get_instance(); /** @var abs_collection $collection */ $collection = $core->model('test_images'); $collection->remove_all_fast(); test_assert($collection->check_unique_value('title', 'оДин')); $collection->create(array('title' => 'Один')); $collection->create(array('title' => 'Второй')); test_assert(!$collection->check_unique_value('title', 'оДин')); // is this necessary? $db = core::lib('db'); $sql = "SELECT count(*) as count FROM sat_test_images WHERE LOWER(title) = 'один'"; $result = $db->fetch_row($db->query($sql)); test_assert(1 === $result['count']);
{ } $config = new test_config(); test_assert($config instanceof registry, 'registry'); test_assert(null === $config->test, 'registry get 1'); $config->test = array('title' => 'hello'); if (!test_assert(array('title' => 'hello') === ($test = $config->test), 'registry get 2')) { test_print($test); } $config->set('simple', 657); if (!test_assert(657 === ($test = $config->get('simple')), 'registry get 2.1')) { test_print($test); } $config->clear('test'); test_assert(null === $config->get('test'), 'registry get 3'); test_assert(null === $config->test, 'registry get 4'); // aregistry $ar = new aregistry(); $ar->set('key', 123); $ar['sub'] = array('a1' => '-a1-'); test_assert(isset($ar['key']), 'isset1'); test_assert(!empty($ar['key']), 'isset2'); test_assert(isset($ar['sub']['a1']), 'isset3'); unset($ar['key']); test_assert(!isset($ar['key']), 'isset4'); $ar->set('sub.a2', '44'); test_assert($ar['sub']['a2'] === '44'); // Indirect modification of overloaded element of aregistry has no effect @($ar['sub']['a2'] = 1); test_assert($ar['sub']['a2'] === '44');
// $item = $collection->alloc(); test_assert($item instanceof abs_collection_item, 'alloc.1'); test_assert($item->is_allocated(), 'is-alloc'); test_assert($item->is_new(), 'is-new'); $item->title = "@title.2"; $item->save(); test_assert(($id = $item->get_id()) > 0, 'last-id'); test_assert(!$item->is_allocated(), 'is-alloc.2'); test_assert(!$item->is_new(), 'is-new.2'); // clone one $item->set_id(null)->save(); $item = $collection->clear(true)->load_only_id($id); test_assert($item, 'check item'); test_assert($collection->count() == 1, 'check item count'); if (!$item) { return; } test_assert($item->id === $id, 'allocated load Id'); test_assert($item->title === "@title.2", 'allocated load Id Title'); // // fields set // $collection->set_working_fields(['title']); $item = $collection->load_only_id($id); $item->text = "not-changed"; $item->save(); $query = $item->connection()->get_last_query(); test_assert(count($item->render()) === 2, 'WORKING-SET fields count'); test_assert(strpos($query, 'text') === false, 'WORKING-SET text unchanged');