function testCreateNewMetadataStructure()
 {
     $new = Metadata_Structure::createNewMetadataStructure(10, $this->DB);
     // 'metadata_structure_id', 'created_at', 'updated_at', 'parent_metadata_structure_id', 'name', 'ordering', 'description', 'details', 'metadata_term_set_id', 'flag_active', 'flag_delete'
     $this->assertEqual('NEW', $new->metadata_structure_id);
     $this->assertNotEqual('', $new->created_at);
     $this->assertNotEqual('', $new->updated_at);
     $this->assertEqual(10, $new->parent_metadata_structure_id);
     $this->assertEqual(util_lang('new_metadata_structure_name'), $new->name);
     $this->assertEqual('0', $new->ordering);
     $this->assertEqual(util_lang('new_metadata_structure_description'), $new->description);
     $this->assertEqual(util_lang('new_metadata_structure_details'), $new->details);
     $this->assertEqual(0, $new->metadata_term_set_id);
     $this->assertEqual(true, $new->flag_active);
     //            $this->assertEqual('',$new->flag_workflow_published);
     //            $this->assertEqual('',$new->flag_workflow_validated);
     $this->assertEqual(false, $new->flag_delete);
 }
//util_prePrintR('#d#');
# 2. figure out which metadata structure is being acted on (if none specified then list all visible)
$mds = '';
if ($action == 'create') {
    //util_prePrintR('#e#');
    //        $mds = new Metadata_Structure(['name'=>util_lang('new_metadata_structure').' '.util_currentDateTimeString(),'DB'=>$DB]);
    $mds = Metadata_Structure::createNewMetadataStructure(0, $DB);
    if (isset($_REQUEST['parent_metadata_structure_id']) && is_numeric($_REQUEST['parent_metadata_structure_id'])) {
        $parent = Metadata_Structure::getOneFromDb(['metadata_structure_id' => $_REQUEST['parent_metadata_structure_id']], $DB);
        if ($parent && $parent->matchesDb) {
            $mds->parent_metadata_structure_id = $parent->metadata_structure_id;
        }
    }
} elseif ($action == 'update' && $_REQUEST['metadata_structure_id'] == 'NEW') {
    //util_prePrintR('#f#');
    $mds = Metadata_Structure::createNewMetadataStructure(0, $DB);
} elseif ($action != 'list' && isset($_REQUEST['metadata_structure_id']) && is_numeric($_REQUEST['metadata_structure_id'])) {
    //util_prePrintR('#g#');
    $mds = Metadata_Structure::getOneFromDb(['metadata_structure_id' => $_REQUEST['metadata_structure_id']], $DB);
}
//util_prePrintR('#h#');
if (!$mds || $mds->metadata_structure_id != 'NEW' && !$mds->matchesDb) {
    //util_prePrintR('#i#');
    $action = 'list';
}
# 3. confirm that the user is allowed to take that action on that object (if not, redirect them to the home page with an appropriate warning)
//util_prePrintR('#j#');
if ($action != 'list' && !$USER->canActOnTarget($ACTIONS[$action], $mds)) {
    //util_prePrintR('#k#');
    util_redirectToAppPage('app_code/metadata_structure.php?action=list', 'failure', util_lang('no_permission'));
}