예제 #1
0
 public function testgetAllGenericAssgignmentNamesFromDbJson()
 {
     $logFile = fopen("/var/www/jimfuqua/tutor/logs/testgetAllGenericAssgignmentNamesFromDbJson", "w");
     $string = "\n" . 'testgetAllGenericAssgignmentNamesFromDbJson()' . "\n";
     fwrite($logFile, $string);
     $this->BuildArray();
     // reset variables.
     $returned_json = null;
     $classInstance = new tutor\src\classes\GenericAClass();
     $r = $classInstance->deleteRowsNamed("xx");
     $r = $classInstance->deleteRowsNamed("xxy");
     $r = $classInstance->deleteRowsNamed("xxz");
     $r = $classInstance->deleteRowsNamed("Test");
     //get all records and count them.
     $result = $classInstance->insertRecord($this->myArray);
     $this->myArray['tG_AssignmentName'] = 'Test2';
     $result2 = $classInstance->insertRecord($this->myArray);
     $result_json = $classInstance->getAllGenericAssgignmentNamesFromDbJson();
     $result_1 = json_decode($result_json, true);
     $v = var_export($result_json, true);
     $string = "\n" . __LINE__ . ' $result_json = ' . "{$v}\n";
     fwrite($logFile, $string);
     $v = var_export($result_1, true);
     $string = "\n" . __LINE__ . ' $result_1 = ' . "{$v}\n";
     fwrite($logFile, $string);
     $this->assertTrue(is_array($result_1));
     $this->myArray['tG_AssignmentName'] = 'xx';
     //$this->myArray['id'] = '';
     $result = $classInstance->insertRecord($this->myArray);
     $this->assertTrue($result === 1);
     $result = $classInstance->getAllGenericAssgignmentNamesFromDbJson();
     $result_2 = json_encode($result_1);
     //$this->assertTrue($result_1 === $result_2);
     $this->myArray['tG_AssignmentName'] = 'xxy';
     //$this->myArray['id'] = '';
     $result = $classInstance->insertRecord($this->myArray);
     $this->assertTrue($result === 1);
     $result = $classInstance->getAllGenericAssgignmentNamesFromDbJson();
     $result_3 = json_decode($result);
     //$this->assertTrue(count($result_3) === (count($result_1) + 2));
     switch (json_last_error()) {
         case JSON_ERROR_DEPTH:
             $message = "";
             $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 records that were added.
     $r = $classInstance->deleteRowsNamed("xx");
     // returns affected rows.
     $this->assertTrue($r === 1);
     $r = $classInstance->deleteRowsNamed("xxy");
     $this->assertTrue($r === 1);
     $r = $classInstance->deleteRowsNamed("xxz");
     $r = $classInstance->deleteRowsNamed("Test");
     $r = $classInstance->deleteRowsNamed('Test2');
     $this->BuildArray();
     // reset variables.
 }