예제 #1
0
 /**
  * Gets all of the generic assignments filtered by the fourth character in
  *   tG_AssignmentName.
  */
 public function testgetGAssignmentNamesFilteredByStartingLettersToJson()
 {
     //$logFile = fopen("/var/www/tutor/logs/
     //testGetGAssignmentNamesFilteredByStartingLettersToJson", "w");
     //$string = "\n".
     //'testGetGAssignmentNamesFilteredByStartingLettersToJson'.
     //"\n"; fwrite  ($logFile, $string);
     $this->BuildArray();
     // reset variables.
     $classInstance = new tutor\src\classes\GenericAClass();
     $r = $classInstance->deleteRowsNamed("xx");
     // get all records filtered by y and count them.
     $result_json = $classInstance->getGAssignmentNamesFilteredByStartingLettersToJson('xx');
     $this->assertTrue(is_null($result_json));
     // records start with 'tG_';
     // add a record with y.
     $this->myArray['tG_AssignmentName'] = 'xx';
     //$this->myArray['id'] = '6';
     $classInstance->insertRecord($this->myArray);
     //insert record with 'xx';
     $this->myArray['tG_AssignmentName'] = 'xxy';
     //$this->myArray['id'] = '7';
     // insert another record starting with 'xxy';
     $classInstance->insertRecord($this->myArray);
     $this->myArray['tG_AssignmentName'] = 'xxz';
     //$this->myArray['id'] = '8';
     // inserts another record starting with 'xxz';
     $classInstance->insertRecord($this->myArray);
     $result_json = $classInstance->getGAssignmentNamesFilteredByStartingLettersToJson('xx');
     //$s = var_export($result_json, true);
     //$string='$result_json = '.$s."\n"; fwrite  ($logFile, $string);
     // now evaluate the data in y as json.
     $returned_json = json_decode($result_json);
     //$this->assertTrue($returned_json->{'tG_AssignmentName'} = 'xx');
     //$s = var_export($returned_json, true);
     //$string='$returned_json = '.$s."\n";
     //fwrite  ($logFile, $string);
     $this->assertTrue(json_last_error() === JSON_ERROR_NONE);
     switch (json_last_error()) {
         case JSON_ERROR_DEPTH:
             $message = "";
             // inserts another record starting with 'xx';
             $message = ' - Maximum stack depth exceeded';
             echo $message;
             error_log($message, 0, '/var/www/tutor/logs/php_errors.log');
             break;
         case JSON_ERROR_CTRL_CHAR:
             $message = "";
             echo $message;
             $message = ' - Unexpected control character found';
             break;
         case JSON_ERROR_SYNTAX:
             $message = "";
             echo $message;
             $message = ' - Syntax error, malformed JSON';
             break;
     }
     // clean up.
     // delete the record that was added.
     $r = $classInstance->deleteRowsNamed("xx");
     $this->assertTrue($r === 1);
     $r = $classInstance->deleteRowsNamed("xxy");
     $this->assertTrue($r === 1);
     $r = $classInstance->deleteRowsNamed("xxz");
     $this->assertTrue($r === 1);
     $this->BuildArray();
     // reset variables.
 }