Ejemplo n.º 1
0
 public function test_strings_in_castext_escaped()
 {
     $vars = 'st:"This is a string with escaped \\" strings...."';
     $at1 = new stack_cas_keyval($vars, null, 123, 't', true, 0);
     $this->assertTrue($at1->get_valid());
     $at2 = new stack_cas_text('\\[@st@\\]', $at1->get_session(), 0, 't');
     $this->assertTrue($at2->get_valid());
     $at2->get_display_castext();
     $this->assertEquals($at2->get_display_castext(), '\\[\\mbox{This is a string with escaped " strings....}\\]');
 }
 /**
  * Validate a CAS string field to make sure that: 1. it fits in the DB, and
  * 2. that it is syntactically valid.
  * @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.
  * @return array updated $errors array.
  */
 protected function validate_cas_keyval($errors, $value, $fieldname)
 {
     if ('' == trim($value)) {
         return $errors;
     }
     $keyval = new stack_cas_keyval($value, $this->options, $this->seed, 't');
     if (!$keyval->get_valid()) {
         $errors[$fieldname][] = $keyval->get_errors();
     }
     return $errors;
 }
Ejemplo n.º 3
0
 public function test_remove_comment_fail()
 {
     $at1 = new stack_cas_keyval("a:1\n /* This is a comment \n b:2\n */\n c:3", null, 123, 's', true, 0);
     $this->assertTrue($at1->get_valid());
     $a3 = array('a:1', 'c:4');
     $s3 = array();
     foreach ($a3 as $s) {
         $s3[] = new stack_cas_casstring($s);
     }
     $cs3 = new stack_cas_session($s3, null, 123);
     $cs3->instantiate();
     $at1->instantiate();
     // This looks strange, but the cache layer gives inconsistent results if the first
     // of these populates the cache, and the second one uses it.
     $this->assertNotEquals($cs3->get_session(), $at1->get_session()->get_session());
 }