public function test_discard()
 {
     // Set up.
     $stack = new xhtml_container_stack();
     $stack->push('test1', '</somethingdistinctive>');
     $stack->discard();
     // Exercise SUT.
     $stack = null;
     // Verify outcome
     $this->assertDebuggingNotCalled();
 }
示例#2
0
文件: lib.php 项目: anilch/Personel
function cobaltexception_format($ex) {
    global $CFG, $DB, $OUTPUT, $USER, $FULLME, $SESSION, $PAGE;
    $output = '';
    $obbuffer = '';
    $expinfo = get_cobaltexception_info($ex);
    $debuginfo = $expinfo->debuginfo;
    $link = $expinfo->link;
    $backtrace = $expinfo->backtrace;
 
    if ($OUTPUT->has_started()) {
        // we can not always recover properly here, we have problems with output buffering,
        // html tables, etc.
        $container = new xhtml_container_stack();
        $output .= $container->pop_all_but_last();
       
    } else {
       
        // It is really bad if library code throws exception when output buffering is on,
        // because the buffered text would be printed before our start of page.
        // NOTE: this hack might be behave unexpectedly in case output buffering is enabled in PHP.ini
        error_reporting(0); // disable notices from gzip compression, etc.
        while (ob_get_level() > 0) {
            $buff = ob_get_clean();
            if ($buff === false) {
                break;
            }
            $obbuffer .= $buff;
        }
        error_reporting($CFG->debug);
        // Output not yet started.
        $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
        if (empty($_SERVER['HTTP_RANGE'])) {
            @header($protocol . ' 404 Not Found');
        } else {
            // Must stop byteserving attempts somehow,
            // this is weird but Chrome PDF viewer can be stopped only with 407!
            @header($protocol . ' 407 Proxy Authentication Required');
        }

        $output .= $PAGE->set_context(null);
        $output .= $PAGE->set_url('/');
        $output .= $PAGE->set_title(get_string('error'));
        $output .= $OUTPUT->header();
    }

    $message = '<p style="text-align:center" class="errormessage">' . $expinfo->message . '</p>';
    if (empty($CFG->rolesactive)) {
        $message .= '<p  style="text-align:center" class="errormessage">' . get_string('installproblem', 'error') . '</p>';
        //It is usually not possible to recover from errors triggered during installation, you may need to create a new database or use a different database prefix for new installation.
    }
    $output .= $message;

    if (debugging('', DEBUG_DEVELOPER)) {
        if (!empty($debuginfo)) {
            //$debuginfo = s($debuginfo); // removes all nasty JS
            $debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines
            $output .= $OUTPUT->notification('<strong style="text-align:center">Debug info:</strong> ' . $debuginfo, 'notifytiny');
        }
        if (!empty($backtrace)) {
            $output .= $OUTPUT->notification('<strong style="text-align:center">Stack trace:</strong> ' . format_backtrace($backtrace), 'notifytiny');
        }
        if ($obbuffer !== '') {
            $output .= $OUTPUT->notification('<strong style="text-align:center">Output buffer:</strong> ' . s($obbuffer), 'notifytiny');
        }
    }

    if (empty($CFG->rolesactive)) {
        // continue does not make much sense if moodle is not installed yet because error is most probably not recoverable
    } else
        $output .= $OUTPUT->continue_button($link);
    $output .= $OUTPUT->footer();

    // Padding to encourage IE to display our error page, rather than its own.
    $output .= str_repeat(' ', 512);

    echo $output;
}
 public function test_discard()
 {
     // Set up.
     $stack = new xhtml_container_stack();
     $stack->push('test1', '</somethingdistinctive>');
     $stack->discard();
     // Exercise SUT.
     $this->start_capture();
     $stack = null;
     $errors = $this->end_capture();
     // Verify outcome
     $this->assertEquals('', $errors);
 }