Exemplo n.º 1
0
 function test()
 {
     Tap::is_instance_of('db successfully initializes', 'Db', 'getDao', 'mysqli', NULL);
     // $all_tables = array('Classes', 'Professors', 'Student_classes', 'Students');
     // Tap::is('read existing tables', 'Db', 'getAllTables', $all_tables, NULL);
     // $no_tables = array('status' => false);
     $table_name = 'taptest_table_' . Util::randString(10, 'lowercase');
     $creation_statement = 'CREATE TABLE `' . $table_name . '` ( `id` int(10) NOT NULL auto_increment, `test_str` varchar(128) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;';
     Tap::is('create new table', 'Db', 'createTable', '1', $creation_statement);
     $all_tables[] = $table_name;
     Tap::is('read existing tables', 'Db', 'getAllTables', $all_tables, NULL);
     array_pop($all_tables);
     //create row
     array('');
     //Tap::is('add a new row', 'Db', 'add', '', );
     //read row
     //update row
     //read row
     //delete row
     //read row
     Tap::is('drop the random table created', 'Db', 'dropTable', $all_tables, $table_name);
     Tap::is('read existing tables', 'Db', 'getAllTables', NULL, '');
 }
$stockpile->add($item_id, 1, array('event' => 'halloween'));
$txn->commit();
$rows = $stockpile->history(array('limit' => 1));
Tap::is($rows[0]['event'], 'halloween', 'add an item with meta information. the information shows up in the log');
$stockpile->subtract($item_id, 1, array('event' => 'xmas'));
$txn->commit();
$rows = $stockpile->history(array('limit' => 1));
Tap::is($rows[0]['event'], 'xmas', 'subtract an item with meta information. the information shows up in the log');
$user_id = uniqueUserID();
$item_id = uniqueNumber(1, 1000000);
$txn = txn();
$stockpile = stockpile($app, $user_id, $txn);
$stockpile->add($item_id, 1, array('event' => $teststring = 'äó'));
$txn->commit();
$rows = $stockpile->history(array('item_id' => $item_id, 'limit' => 1));
Tap::is($rows[0]['event'], $teststring, 'utf8 characters come through');
$user_id = uniqueUserID();
$item_id = uniqueNumber(1, 1000000);
$txn = txn();
$stockpile = stockpile($app, $user_id, $txn);
for ($i = 0; $i < 20; $i++) {
    $stockpile->add($item_id, $i + 1);
    advanceCurrentTime(3600 * 12);
}
$txn->commit();
$diff = abs(count($history = $stockpile->history()) - 14);
Tap::cmp_ok($diff, '<', 2, 'after logging two entries a day over 10 days, we get back only 7 days worth of data');
$start = $history[0]['touch'];
$last_row = array_pop($history);
$end = $last_row['touch'];
$diff = abs(floor(($start - $end) / (3600 * 24)));