예제 #1
0
<?php

require '../loader.php';
class test_config extends registry
{
}
$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');
예제 #2
0
<?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'));
예제 #3
0
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 
*/
예제 #4
0
<?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();});
예제 #5
0
파일: api.php 프로젝트: egregor-dev/SatCMS
$item->title = 'title<h1>header</h1>';
test_assert(function () use($item) {
    $result = $item->save();
    return $result;
}, 'Save model');
/** @var abs_collection_item $item */
$item = $collection->clear(true)->load_only_id($id);
test_assert($item instanceof abs_collection_item, 'LOAD_ONLY_ID class');
if (!test_assert($item->id === $id, '2-LOAD_ONLY_ID Id') || !test_assert($item->title === 'title<h1>header</h1>', '2-LOAD_ONLY_ID Title') || !test_assert($item->render('title') === 'title&lt;h1&gt;header&lt;/h1&gt;', '2-LOAD_ONLY_ID Render Title') || !test_assert(count($item->render(['text', 'title'])) === 2, 'Render filter []') || !test_assert($item->text === "text<h1>header</h1>", '2-LOAD_ONLY_ID Text')) {
    test_print($item->title, $item->render('title'), $item->render());
}
$item->remove();
$item = $collection->clear(true)->load_only_id($id);
test_assert(!$item, 'REMOVE-LOAD_ONLY_ID');
if (!test_assert(($count = $collection->clear()->count_sql()) === 0, 'REMOVE-COUNT')) {
    test_print($count);
}
test_except('core_exception', function () {
    core::get_instance()->model('NotExist');
}, 'exception-test');
//
// Alloc
//
$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');