function testNewPageFieldForm()
 {
     $this->doLoginBasic();
     global $DB;
     $DB = $this->DB;
     $this->get('http://localhost/digitalfieldnotebooks/ajax_actions/specimen.php?action=create&unique=ABC123&notebook_page_id=1101');
     $this->checkBasicAsserts();
     $expected = '<div class="specimen embedded">' . "\n" . Specimen::renderFormInteriorForNewSpecimen('ABC123', $this->DB) . "\n</div>";
     $results = json_decode($this->getBrowser()->getContent());
     $this->assertEqual('success', $results->status);
     $this->assertEqual($expected, $results->html_output);
     $this->assertNoPattern('/IMPLEMENTED/');
 }
    exit;
}
# 2. confirm that the user is allowed to take that action
// global specimen create
// additional permission checks are handled at the save point for notebook pages and authoritative plants respectively
$has_permission = $USER->flag_is_system_admin;
if (!$has_permission) {
    $USER->cacheRoleActionTargets();
    // check global specimen perms (indiv specimen perms are only for editing, not creating, as indiv perms require a specific object ID as a target for the permission)
    if (in_array('global_specimen', array_keys($USER->cached_role_action_targets_hash_by_target_type_by_id))) {
        foreach ($USER->cached_role_action_targets_hash_by_target_type_by_id['global_specimen'] as $glob_rat) {
            if ($glob_rat->action_id == $ACTIONS['create']->action_id) {
                $has_permission = true;
                break;
            }
        }
    }
}
if (!$has_permission) {
    $results['note'] = util_lang('no_permission');
    echo json_encode($results);
    exit;
}
# 3. branch behavior based on the action
#      create - return an appropriate form field set
if ($has_permission && $action == 'create') {
    $results['html_output'] = '<div class="specimen embedded">' . "\n" . Specimen::renderFormInteriorForNewSpecimen($unique_str, $DB) . "\n</div>";
    $results['status'] = 'success';
}
echo json_encode($results);
exit;
 function testRenderFormInteriorForNewSpecimen()
 {
     global $USER;
     $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB);
     $unique_str = 'XYZ789';
     $s = Specimen::createNewSpecimenForNotebookPage(0, $this->DB);
     $s->specimen_id = $unique_str;
     $canonical = '<h3><input type="text" name="specimen-name_' . $s->specimen_id . '" id="specimen-name_' . $s->specimen_id . '" value="' . htmlentities($s->name) . '"/></h3>' . "\n" . '<ul class="base-info">' . "\n" . '  <li><div class="field-label">' . util_lang('coordinates') . '</div> : <div class="field-value"><input type="text" name="specimen-gps_longitude_' . $s->specimen_id . '" id="specimen-gps_longitude_' . $s->specimen_id . '" value="' . htmlentities($s->gps_longitude) . '"/>, <input type="text" name="specimen-gps_latitude_' . $s->specimen_id . '" id="specimen-gps_latitude_' . $s->specimen_id . '" value="' . htmlentities($s->gps_latitude) . '"/></div></li>' . "\n" . '  <li><div class="field-label">' . util_lang('notes') . '</div> : <div class="field-value"><textarea name="specimen-notes_' . $s->specimen_id . '" id="specimen-notes_' . $s->specimen_id . '" class="specimen-notes" row="4" cols="120">' . htmlentities($s->notes) . '</textarea></div></li>' . "\n" . '  <li><div class="field-label">' . util_lang('catalog_identifier') . '</div> : <div class="field-value"><input type="text" name="specimen-catalog_identifier_' . $s->specimen_id . '" id="specimen-catalog_identifier_' . $s->specimen_id . '" value="' . htmlentities($s->catalog_identifier) . '"/></div></li>' . "\n" . '  <li><b><i>' . util_lang('msg_save_page_before_image_upload', 'ucfirst') . '</i></b></li>' . "\n" . '</ul>';
     $rendered = Specimen::renderFormInteriorForNewSpecimen($unique_str, $this->DB);
     //            echo "<pre>\n".htmlentities($canonical)."\n------------------\n".htmlentities($rendered)."\n</pre>";
     //            echo "<pre>-----------\n";
     //            $ch_c = substr($canonical,125,1);
     //            $ch_r = substr($rendered,125,1);
     //            echo $ch_c . '('.ord($ch_c).'):' . $ch_r.'('.ord($ch_r).')';
     //            echo "\n-----------\n";
     //            echo "</pre>";
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
 }