public function test_exception_3() { $session = new stack_cas_session(null); $this->setExpectedException('stack_exception'); $at1 = new stack_cas_text("Hello world", $session, "abc"); $at1->get_valid(); }
function output_cas_text($title, $intro, $castext) { global $OUTPUT; echo $OUTPUT->heading($title, 3); echo html_writer::tag('p', $intro); echo html_writer::tag('pre', s($castext)); $ct = new stack_cas_text($castext, null, 0, 't'); echo html_writer::tag('p', format_text(stack_ouput_castext($ct->get_display_castext()))); echo output_debug(stack_string('errors'), $ct->get_errors()); echo output_debug(stack_string('debuginfo'), $ct->get_debuginfo()); }
/** * Validate a CAS text field. * @param array $errors the errors array that validation is assembling. * @param string $value the submitted value validate. * @param string $fieldname the name of the field add any errors to. * @param string $savesession the array key to save the session to in $this->validationcasstrings. * @return array updated $errors array. */ protected function validate_cas_text($errors, $value, $fieldname, $fixingdollars, $session = null) { if (!$fixingdollars && strpos($value, '$$') !== false) { $errors[$fieldname][] = stack_string('forbiddendoubledollars'); } $castext = new stack_cas_text($value, $session, $this->seed, 't'); if (!$castext->get_valid()) { $errors[$fieldname][] = $castext->get_errors(); return $errors; } // Validate any [[facts:...]] tags. $unrecognisedtags = stack_fact_sheets::get_unrecognised_tags($value); if ($unrecognisedtags) { $errors[$fieldname][] = stack_string('unrecognisedfactstags', array('tags' => implode(', ', $unrecognisedtags))); return $errors; } if ($session) { $display = $castext->get_display_castext(); if ($castext->get_errors()) { $errors[$fieldname][] = $castext->get_errors(); return $errors; } } return $errors; }
public function test_empty_strings() { $s = '@"This is a string"@ whereas this is empty @""@.'; $at2 = new stack_cas_text($s, null, 0, 't'); $this->assertTrue($at2->get_valid()); $at2->get_display_castext(); $this->assertEquals($at2->get_display_castext(), '\\(\\mbox{This is a string}\\) whereas this is empty \\(\\mbox{ }\\).'); }
/** * Get the cattext for the general feedback, instantiated within the question's session. * @return stack_cas_text the castext. */ public function get_generalfeedback_castext() { $gftext = new stack_cas_text($this->generalfeedback, $this->session, $this->seed, 't', false, 1); if ($gftext->get_errors()) { throw new stack_exception('Error rendering the general feedback text: ' . $gftext->get_errors()); } return $gftext; }
/** * @return array of CAS strings. These cas strings include the names of all * the input variables that are required by this node. */ public function get_required_cas_strings() { $ct = new stack_cas_text($this->branches[0]['feedback'] . $this->branches[1]['feedback']); $requiredcasstrings = $ct->get_all_raw_casstrings(); $requiredcasstrings[] = $this->sans->get_raw_casstring(); $requiredcasstrings[] = $this->tans->get_raw_casstring(); if ($this->process_atoptions() && trim($this->atoptions) != '') { $requiredcasstrings[] = $this->atoptions; } return $requiredcasstrings; }
/** * Subsitute variables into the feedback text. * @param string $feedback the concatenated feedback text. * @return string the feedback with question variables substituted. */ public function substitue_variables_in_feedback($feedback) { $feedbackct = new stack_cas_text($feedback, $this->cascontext, $this->seed, 't', false, 0); $result = $feedbackct->get_display_castext(); $this->_errors = trim($this->_errors . ' ' . $feedbackct->get_errors()); return $result; }
// Initially simplification should be on. if (!$vars and !$string) { $simp = true; } if ($string) { $options = new stack_options(); $options->set_site_defaults(); $options->set_option('simplify', $simp); $session = new stack_cas_session(null, $options); if ($vars) { $keyvals = new stack_cas_keyval($vars, $options, 0, 't'); $session = $keyvals->get_session(); $varerrs = $keyvals->get_errors(); } if (!$varerrs) { $ct = new stack_cas_text($string, $session, 0, 't'); $displaytext = $ct->get_display_castext(); $errs = $ct->get_errors(); $debuginfo = $ct->get_debuginfo(); } } echo $OUTPUT->header(); echo $OUTPUT->heading($title); echo html_writer::tag('p', stack_string('chatintro')); // If we are editing the General Feedback from a question it is very helpful to see the question text. if ($questionid) { echo $OUTPUT->heading(stack_string('questiontext'), 3); echo html_writer::tag('pre', $question->questiontext, array('class' => 'questiontext')); } if (!$varerrs) { if ($string) {