public function test_compute_miss_formed_command()
 {
     $connection = stack_connection_helper::make();
     // This will induce a timeout on the CAS because we don't have a well formed CAS statement.
     $strin = 'cab:block([],print("[TimeStamp= [ 0 ];';
     $return = $connection->compute($strin);
     $expected = array();
     $this->assertEquals($return, $expected);
 }
예제 #2
0
echo html_writer::tag('dt', stack_string('texdisplaystyle'));
echo html_writer::tag('dd', format_text(stack_string('healthchecksampledisplaytex')));
echo html_writer::tag('dt', stack_string('texinlinestyle'));
echo html_writer::tag('dd', format_text(stack_string('healthchecksampleinlinetex')));
if ($config->mathsdisplay === 'mathjax') {
    $settingsurl = new moodle_url('/admin/settings.php', array('section' => 'additionalhtml'));
    echo html_writer::tag('p', stack_string('healthchecklatexmathjax', $settingsurl->out()));
    echo html_writer::tag('textarea', s(stack_maths_output_mathjax::get_mathjax_code()), array('readonly' => 'readonly', 'wrap' => 'virtual', 'rows' => '12', 'cols' => '100'));
} else {
    $settingsurl = new moodle_url('/admin/filters.php');
    echo html_writer::tag('p', stack_string('healthcheckfilters', array('filter' => stack_maths::configured_output_name(), 'url' => $settingsurl->out())));
}
// Maxima config.
echo $OUTPUT->heading(stack_string('healthcheckconfig'), 3);
// Try to list available versions of Maxima (linux only, without the DB).
$connection = stack_connection_helper::make();
if (is_a($connection, 'stack_cas_connection_unix')) {
    echo html_writer::tag('pre', $connection->get_maxima_available());
}
// Check for location of Maxima.
$maximalocation = stack_cas_configuration::confirm_maxima_win_location();
if ('' != $maximalocation) {
    $message = stack_string('healthcheckconfigintro1') . ' ' . html_writer::tag('tt', $maximalocation);
    echo html_writer::tag('p', $message);
    $summary[] = array(null, $message);
}
// Check if the current options for library packaes are permitted (maximalibraries).
list($valid, $message) = stack_cas_configuration::validate_maximalibraries();
if (!$valid) {
    echo html_writer::tag('p', $message);
    $summary[] = array(false, $message);
 public function instantiate()
 {
     if (null === $this->valid) {
         $this->validate();
     }
     if (!$this->valid) {
         return false;
     }
     // Lazy instantiation - only do this once...
     // Empty session.  Nothing to do.
     if ($this->instantiated || null === $this->session) {
         return true;
     }
     $connection = stack_connection_helper::make();
     $results = $connection->compute($this->construct_maxima_command());
     $this->debuginfo = $connection->get_debuginfo();
     // Now put the information back into the correct slots.
     $session = $this->session;
     $newsession = array();
     $newerrors = '';
     $allfail = true;
     $i = 0;
     // We loop over each entry in the session, not over the result.
     // This way we can add an error for missing values.
     foreach ($session as $cs) {
         $gotvalue = false;
         if ('' == $cs->get_key()) {
             $key = 'dumvar' . $i;
         } else {
             $key = $cs->get_key();
         }
         if (array_key_exists($i, $results)) {
             $allfail = false;
             // We at least got one result back from the CAS!
             $result = $results["{$i}"];
             // GOCHA!  Results have string represenations of numbers, not int....
             if ('' != $result['error'] and false === strstr($result['error'], 'clipped')) {
                 $cs->add_errors($result['error']);
                 $cs->decode_maxima_errors($result['error']);
                 $newerrors .= stack_maxima_format_casstring($cs->get_raw_casstring());
                 $newerrors .= ' ' . stack_string("stackCas_CASErrorCaused") . ' ' . $result['error'] . ' ';
             }
             if (array_key_exists('value', $result)) {
                 $val = str_replace('QMCHAR', '?', $result['value']);
                 $cs->set_value($val);
                 $gotvalue = true;
             } else {
                 $cs->add_errors(stack_string("stackCas_failedReturnOne"));
             }
             if (array_key_exists('display', $result)) {
                 // Need to add this in here also because strings may contain question mark characters.
                 $disp = str_replace('QMCHAR', '?', $result['display']);
                 $cs->set_display($disp);
             }
             if (array_key_exists('valid', $result)) {
                 $cs->set_valid($result['valid']);
             }
             if (array_key_exists('answernote', $result)) {
                 $cs->set_answernote($result['answernote']);
             }
             if (array_key_exists('feedback', $result)) {
                 $cs->set_feedback($result['feedback']);
             }
         } else {
             if (!$gotvalue) {
                 $errstr = stack_string("stackCas_failedReturn") . ' ' . stack_maxima_format_casstring($cs->get_raw_casstring());
                 $cs->add_errors($errstr);
                 $cs->set_answernote('CASFailedReturn');
                 $newerrors .= $errstr;
             }
         }
         $newsession[] = $cs;
         $i++;
     }
     $this->session = $newsession;
     if ('' != $newerrors) {
         $this->errors .= '<span class="error">' . stack_string('stackCas_CASError') . '</span>' . $newerrors;
     }
     if ($allfail) {
         $this->errors = '<span class="error">' . stack_string('stackCas_allFailed') . '</span>';
     }
     $this->instantiated = true;
 }