function test_walkIntersectTree()
 {
     $tree = array("children" => array("1" => array("slug" => "aaa", "parent" => 0, "node_id" => 1), "2" => array("slug" => "bbb", "parent" => 0, "node_id" => 2, "children" => array("5" => array("slug" => "eee", "parent" => 2, "node_id" => 5, "children" => array("14" => array("slug" => "aaa", "parent" => 5, "node_id" => 14), "15" => array("slug" => "bbb", "parent" => 5, "node_id" => 15, "children" => array("17" => array("slug" => "xxx", "parent" => 15, "node_id" => 17))), "16" => array("slug" => "ccc", "parent" => 5, "node_id" => 16, "children" => array("18" => array("slug" => "yyy", "parent" => 16, "node_id" => 18), "19" => array("slug" => "zzz", "parent" => 16, "node_id" => 19))))), "6" => array("slug" => "fff", "parent" => 2, "node_id" => 6), "7" => array("slug" => "ggg", "parent" => 2, "node_id" => 7))), "3" => array("slug" => "ccc", "parent" => 0, "node_id" => 3, "children" => array("8" => array("slug" => "hhh", "parent" => 3, "node_id" => 8), "9" => array("slug" => "iii", "parent" => 3, "node_id" => 9), "10" => array("slug" => "jjj", "parent" => 3, "node_id" => 10))), "4" => array("slug" => "ddd", "parent" => 0, "node_id" => 4, "children" => array("11" => array("slug" => "hhh", "parent" => 4, "node_id" => 11), "12" => array("slug" => "iii", "parent" => 4, "node_id" => 12), "13" => array("slug" => "jjj", "parent" => 4, "node_id" => 13)))));
     // Exact match
     // ===============================================
     $walk = array("0" => "bbb", "1" => "eee", "2" => "aaa");
     $check = array("endpoint_id" => 14, "endpoint_name" => "aaa", "walk_key" => 2, "transect" => array());
     $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error);
     $this->assertEquals($check, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Walk longer than graph
     // ===============================================
     $walk = array("0" => "bbb", "1" => "eee", "2" => "ccc", "3" => "qqq", "4" => "ttt");
     $check = array("endpoint_id" => 16, "endpoint_name" => "ccc", "walk_key" => 2, "transect" => array("qqq", "ttt"));
     $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error);
     $this->assertEquals($check, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Graph longer than walk
     // ===============================================
     $walk = array("0" => "ccc");
     $check = array("endpoint_id" => 3, "endpoint_name" => "ccc", "walk_key" => 0, "transect" => array());
     $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error);
     $this->assertEquals($check, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Null intersect
     // ===============================================
     $walk = array("0" => "zzz");
     $check = array("endpoint_id" => null, "endpoint_name" => null, "walk_key" => null, "transect" => array());
     $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error);
     $this->assertEquals($check, $result, FOX_debug::formatError_print($error));
     unset($error);
 }
 public function dump($depth = null)
 {
     if ($depth == 1) {
         FOX_debug::dump($this->data);
     } else {
         FOX_debug::dump(FOX_debug::formatError_print($this->data, $depth));
     }
 }
 function test_getParentAlbum()
 {
     // Clear the albums table, medias table, and caches
     // ===================================================
     $this->alb->truncate();
     $this->alb->flushCache();
     $this->med->truncate();
     $this->med->flushCache();
     // Load albums class with test data
     // ===================================================
     $test_data = array(array('date_created' => "2011-01-01 15:14:13", 'title' => "Test Title", 'caption' => "Test Caption", 'privacy' => 3, 'module_id' => 1), array('date_created' => "2011-01-01 15:14:14", 'title' => "Test Title", 'caption' => "Test Caption", 'privacy' => 2, 'module_id' => 1), array('date_created' => "2011-01-01 15:14:15", 'title' => "Test Title", 'caption' => "Test Caption", 'privacy' => 1, 'module_id' => 2));
     $result = $this->alb->addItemMulti($user_id = 1, $test_data, $error);
     // Return result should be "true" because its a multi-add
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     // Add media items to test albums
     // ===================================================
     $test_data = array('owner_id' => 1, 'album_id' => 3, 'title' => "Test Media Title 01", 'caption' => "Test Media Caption 01", 'date_created' => "2011-02-02 17:18:19", 'module_slug' => "slug_01");
     $result = $this->med->addItem($test_data, $media_object, $error);
     $this->assertEquals(1, $result, FOX_debug::formatError_print($error));
     $test_data = array('owner_id' => 1, 'album_id' => 2, 'title' => "Test Media Title 02", 'caption' => "Test Media Caption 02", 'date_created' => "2011-02-02 17:18:19", 'module_slug' => "slug_01");
     $result = $this->med->addItem($test_data, $media_object, $error);
     $this->assertEquals(2, $result, FOX_debug::formatError_print($error));
     $test_data = array('owner_id' => 1, 'album_id' => 1, 'title' => "Test Media Title 03", 'caption' => "Test Media Caption 03", 'date_created' => "2011-02-02 17:18:19", 'module_slug' => "slug_01");
     $result = $this->med->addItem($test_data, $media_object, $error);
     $this->assertEquals(3, $result, FOX_debug::formatError_print($error));
     // Fetch parent album
     // ===================================================
     $result = $this->alb->getParentAlbum($media_id = 3);
     $this->assertEquals(1, $result);
 }
 function test_data_integrity()
 {
     // Clear the table and cache
     // ===================================================
     $result = $this->cls->truncate($error);
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     unset($error);
     $result = $this->cls->flushCache($error);
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Load test data
     // ===================================================
     $insert_data = array(array("slug" => "slug_01", "name" => "name_01", "php_class" => "class_01", "active" => true), array("slug" => "slug_02", "name" => "name_02", "php_class" => "class_02", "active" => true), array("slug" => "slug_03", "name" => "name_03", "php_class" => "class_03", "active" => false), array("slug" => "slug_04", "name" => "name_04", "php_class" => "class_04", "active" => true), array("slug" => "slug_05", "name" => "name_05", "php_class" => "class_05", "active" => false));
     $check_ids = array(0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5);
     $result = $this->cls->addMulti($insert_data, $error);
     $this->assertEquals($check_ids, $result, FOX_debug::formatError_print($error));
     // Verify correct ids are returned
     unset($error);
     // Verify correct data is returned
     // ===================================================
     $check_db = array(1 => array("module_id" => 1, "slug" => "slug_01", "name" => "name_01", "php_class" => "class_01", "active" => true), 2 => array("module_id" => 2, "slug" => "slug_02", "name" => "name_02", "php_class" => "class_02", "active" => true), 3 => array("module_id" => 3, "slug" => "slug_03", "name" => "name_03", "php_class" => "class_03", "active" => false), 4 => array("module_id" => 4, "slug" => "slug_04", "name" => "name_04", "php_class" => "class_04", "active" => true), 5 => array("module_id" => 5, "slug" => "slug_05", "name" => "name_05", "php_class" => "class_05", "active" => false));
     $result = $this->cls->getAllModules($error);
     $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Verify correct cache state
     // ===================================================
     $check_cache = array("module_id" => array(1 => array("module_id" => 1, "slug" => "slug_01", "name" => "name_01", "php_class" => "class_01", "active" => true), 2 => array("module_id" => 2, "slug" => "slug_02", "name" => "name_02", "php_class" => "class_02", "active" => true), 3 => array("module_id" => 3, "slug" => "slug_03", "name" => "name_03", "php_class" => "class_03", "active" => false), 4 => array("module_id" => 4, "slug" => "slug_04", "name" => "name_04", "php_class" => "class_04", "active" => true), 5 => array("module_id" => 5, "slug" => "slug_05", "name" => "name_05", "php_class" => "class_05", "active" => false)), "php_class" => array("class_01" => 1, "class_02" => 2, "class_03" => 3, "class_04" => 4, "class_05" => 5), "slug" => array("slug_01" => 1, "slug_02" => 2, "slug_03" => 3, "slug_04" => 4, "slug_05" => 5), "active_modules" => array(1 => true, 2 => true, 4 => true), "all_cached" => true);
     $this->assertEquals($check_cache, $this->cls->cache);
     unset($error);
     // Fail on missing module_id
     // =================================
     $data = array("slug" => "slug_01_updated", "name" => "name_01_updated", "php_class" => "class_01_updated", "active" => true);
     $result = $this->cls->edit($data, $unit_test = true);
     $this->assertEquals(false, $result);
     // Verify cache was not modified
     $this->assertEquals($check_cache, $this->cls->cache);
     unset($error);
     // Clear cache
     $result = $this->cls->flushCache($error);
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Verify db was not modified
     $result = $this->cls->getAllModules($error);
     $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Fail on slug collision
     // =================================
     $data = array("module_id" => 1, "slug" => "slug_02");
     $result = $this->cls->edit($data, $unit_test = true);
     $this->assertEquals(false, $result);
     // Verify cache was not modified
     $this->assertEquals($check_cache, $this->cls->cache);
     unset($error);
     // Clear cache
     $result = $this->cls->flushCache($error);
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Verify db was not modified
     $result = $this->cls->getAllModules($error);
     $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Fail on php_class collision
     // =================================
     $data = array("module_id" => 1, "php_class" => "class_02");
     $result = $this->cls->edit($data, $unit_test = true);
     $this->assertEquals(false, $result);
     // Verify cache was not modified
     $this->assertEquals($check_cache, $this->cls->cache);
     unset($error);
     // Clear cache
     $result = $this->cls->flushCache($error);
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Verify db was not modified
     $result = $this->cls->getAllModules($error);
     $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Fail on name collision
     // =================================
     $data = array("module_id" => 1, "name" => "name_02");
     $result = $this->cls->edit($data, $unit_test = true);
     $this->assertEquals(false, $result);
     // Verify cache was not modified
     $this->assertEquals($check_cache, $this->cls->cache);
     unset($error);
     // Clear cache
     $result = $this->cls->flushCache($error);
     $this->assertEquals(true, $result, FOX_debug::formatError_print($error));
     unset($error);
     // Verify db was not modified
     $result = $this->cls->getAllModules($error);
     $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error));
     unset($error);
 }