public function test_check_external_forbidden_words()
 {
     // Remember, this function returns true if the literal is found.
     $cases = array(array('sin(ta)', array('ta'), true), array('sin(ta)', array('ta', 'a', 'b'), true), array('sin(ta)', array('sa'), false), array('sin(a)', array('a'), false), array('diff(x^2,x)', array('[[BASIC-CALCULUS]]'), true));
     foreach ($cases as $case) {
         $cs = new stack_cas_casstring($case[0]);
         $this->assertEquals($case[2], $cs->check_external_forbidden_words($case[1]));
     }
 }
 /**
  * This is the basic validation of the student's "answer".
  * This method is only called if the input is not blank.
  *
  * Only a few input methods need to modify this method.
  * For example, Matrix types have two dimensional contents arrays to loop over.
  *
  * @param array $contents the content array of the student's input.
  * @return array of the validity, errors strings and modified contents.
  */
 protected function validate_contents($contents, $forbiddenkeys)
 {
     $errors = $this->extra_validation($contents);
     $valid = !$errors;
     // Now validate the input as CAS code.
     $modifiedcontents = array();
     $allowwords = $this->get_parameter('allowWords', '');
     foreach ($contents as $val) {
         $answer = new stack_cas_casstring($val);
         $answer->get_valid('s', $this->get_parameter('strictSyntax', true), $this->get_parameter('insertStars', 0), $allowwords);
         // Ensure student hasn't used a variable name used by the teacher.
         if ($forbiddenkeys) {
             $answer->check_external_forbidden_words($forbiddenkeys);
         }
         $forbiddenwords = $this->get_parameter('forbidWords', '');
         if ($forbiddenwords) {
             $answer->check_external_forbidden_words_literal($forbiddenwords);
         }
         $modifiedcontents[] = $answer->get_casstring();
         $valid = $valid && $answer->get_valid();
         $errors .= $answer->get_errors();
     }
     return array($valid, $errors, $modifiedcontents);
 }