Exemplo n.º 1
0
if (in_array("trash", $alltables)) {
    SmartTest::failedTest();
}
$db->exec("drop table `nonsense`");
//Test description: KeepInShape() tester
SmartTest::instance()->testPack = "Optimizer and Garbage collector";
$db->exec("\nCREATE TABLE  `slimtable` (\n`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,\n`col1` VARCHAR( 255 ) NOT NULL ,\n`col2` TEXT NOT NULL ,\n`col3` INT( 11 ) NOT NULL ,\nPRIMARY KEY (  `id` )\n) ENGINE = MYISAM");
$db->exec("INSERT INTO  `redbeantables` (\n`id` ,\n`tablename`\n)\nVALUES (\nNULL ,  'slimtable'\n);\n");
$db->exec("INSERT INTO  `slimtable` (\n`id` ,\n`col1` ,\n`col2` ,\n`col3`\n)\nVALUES (\nNULL ,  '1',  'mustbevarchar',  '1000'\n);\n");
$db->exec("\nCREATE TABLE  `indexer` (\n`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,\n`highcard` VARCHAR( 255 ) NOT NULL ,\n`lowcard` TEXT NOT NULL ,\n`lowcard2` INT( 11 ) NOT NULL ,\n`highcard2` LONGTEXT NOT NULL ,\nPRIMARY KEY (  `id` )\n) ENGINE = MYISAM");
$db->exec("INSERT INTO  `redbeantables` (\n`id` ,\n`tablename`\n)\nVALUES (\nNULL ,  'indexer'\n);\n");
for ($i = 0; $i < 20; $i++) {
    $db->exec("INSERT INTO  `indexer` (\n`id` ,\n`highcard` ,\n`lowcard` ,\n`lowcard2`,\n`highcard2`\n)\nVALUES (\nNULL ,  rand(),  'a',  rand(), CONCAT( rand()*100, '" . str_repeat('x', 1000) . "' )\n);\n");
}
for ($i = 0; $i < 500; $i++) {
    RedBean_OODB::keepInShape();
}
$row = $db->getRow("select * from slimtable limit 1");
SmartTest::test($row["col1"], 1);
SmartTest::test($row["col2"], "mustbevarchar");
SmartTest::test($row["col3"], 1000);
SmartTest::test(count($db->get("describe slimtable")), 4);
RedBean_OODB::dropColumn("slimtable", "col3");
SmartTest::test(count($db->get("describe slimtable")), 3);
RedBean_OODB::KeepInShape(true);
$tables = RedBean_OODB::showTables();
SmartTest::test(in_array("slimtable", $tables), false);
//Tests for each individual engine
function testsperengine()
{
    global $tests;