public function testImportExport() { /* ### test empty tree ### */ $this->assertEquals(array(), json_decode(Baobab::export(self::$db, self::$forest_name), TRUE)); Baobab::import(self::$db, self::$forest_name, '[]'); $this->assertEquals(NULL, $this->baobab->getTree()); $empty_json_tree = '[{"fields":["id","lft","rgt","label"],"values":null}]'; Baobab::import(self::$db, self::$forest_name, $empty_json_tree); $this->assertEquals(NULL, $this->baobab->getTree()); /* ### test import/export not empty tree with non numeric values ### */ $json_tree = '[{ "fields":["id","lft","label","rgt"], "values": [5,1,"AAA",14,[ [3,2,"BBB",7,[ [4,3,"CCC",4,[]], [6,5,"DDD",6,[]] ]], [1,8,"EEE",13,[ [2,9,"FFF",10,[]], [7,11,"GGG",12,[]] ]] ]] }]'; Baobab::import(self::$db, self::$forest_name, $json_tree); $this->assertEquals(array(array("tree_id" => 1, "fields" => array("id", "label", "rgt"), "values" => array(5, "AAA", 14, array(array(3, "BBB", 7, array(array(4, "CCC", 4, array()), array(6, "DDD", 6, array()))), array(1, "EEE", 13, array(array(2, "FFF", 10, array()), array(7, "GGG", 12, array()))))))), json_decode(Baobab::export(self::$db, self::$forest_name, array("id", "label", "rgt")), TRUE)); }
function _fillAnyIdTree($tree_id) { $t = new Baobab(self::$db, self::$forest_name, $tree_id); $t->clean(); Baobab::import(self::$db, self::$forest_name, '[{' . ($tree_id ? '"tree_id":' . $tree_id . ',' : '') . ' "fields":["id","lft","rgt"], "values": [100001,1,14,[ [100002,2,7,[ [100003,3,4,[]], [100004,5,6,[]] ]], [100005,8,13,[ [100006,9,10,[]], [100007,11,12,[]] ]] ]] }]'); }