Example #1
0
 /**
  * Test getNextAssignmentToDo().   *    .*/
 public function testgetNextAssignmentToDo()
 {
     // File handle used for debugging messages.
     // Insert 3 new tA lessons into database for a fictitious new student.
     // Need boundary tests & bad assignments and one good assignment.
     // Run several tests to see that the correct lesson is returned.
     // First test should be simple with one zero time assigned and
     // the other 150% assigned.
     $this->resetMyArray();
     // Reset myArray to origninal values.
     $ac_class_instance = new AssignmentsClass();
     $temp_student_id591 = 'abcdefg';
     // Next insure no previous lessons for this student.
     $num_rows = $ac_class_instance->delRowsByStudentId($temp_student_id591);
     $this->assertTrue($num_rows === 0);
     // Any number greater than 0 would indicate a clean-up failure in
     // another function.
     $this->myArray['tA_S_ID'] = $temp_student_id591;
     $last_lesson_id = '';
     // Test 1 Check for no lessons to do because no student exists.
     $result = $ac_class_instance->getNextAssignmentToDo($temp_student_id591, $last_lesson_id);
     // $path_to_file = "/var/www/html/jimfuqua/tutor/logs/";
     // $file = "ACT_testgetNextAssignmentToDo.log";
     // $path_file = $path_to_file.$file;
     // $log_file = fopen($path_file, "w");
     // $v = var_export($result, true);
     // $string = __LINE__.' testgetNextAssignmentToDo = '.$result."\n\n";
     // fwrite($log_file, $string);.
     $this->assertTrue($result === 'error');
     // Test 2  Create a class instance with one lesson and test count
     // to see if it just has one lesson.
     $result = $ac_class_instance->delRowsByStudentId($temp_student_id591);
     // Start with none.
     $this->assertTrue($result === 0);
     $ac_class_instance->insertRecord($this->myArray);
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     // $v = var_export($num_rows, TRUE);
     // $string = __LINE__ . ' AC $num_rows = ' . $v . "\n";
     // fwrite($log_file, $string);.
     $this->assertTrue($num_rows === 1);
     $last_lesson_id = '';
     $result = $ac_class_instance->getNextAssignmentToDo($temp_student_id591, $last_lesson_id);
     $num_rows = count($result);
     // $v = var_export($num_rows, TRUE);
     // $string = __LINE__ . ' AC $num_rows = ' . $v . "\n";
     // fwrite($log_file, $string);.
     $this->assertTrue($num_rows === 24);
     // Test 3 add an identical lesson and test for number of lessons = 2.
     $ac_class_instance->insertRecord($this->myArray);
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 2);
     // Test 4 Delete all lessons and add one specific lesson back.
     // Test that it is returned.
     $result = $ac_class_instance->delRowsByStudentId($temp_student_id591);
     // Start with none.
     $this->myArray['tG_AssignmentName'] = 'fffff';
     $ac_class_instance->insertRecord($this->myArray);
     // Add a record.
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 1);
     // Get it back.
     $last_lesson_id = '';
     $result = $ac_class_instance->getNextAssignmentToDo($temp_student_id591, $last_lesson_id);
     $this->assertTrue(is_array($result));
     $this->assertTrue(count($result) === 24);
     // Returns FALSE only if there are no lessons.
     $this->assertTrue(is_array($result));
     $this->assertTrue($result['tG_AssignmentName'] == 'fffff');
     $this->assertTrue($result['tA_S_ID'] === $temp_student_id591);
     $result = $ac_class_instance->delRowsByStudentId($temp_student_id591);
     // Insure no previous lessons for this student.
     $this->assertTrue($result === 1);
     // Any number greater than 1 would indicate a clean-up failure.
     $this->resetMyArray();
     // Reset myArray to original values.
     unset($ac_class_instance);
     // Test 5
     // Delete all lessons and add two lessons one with 0 time assigned
     // and the other with 150% assigned.
     // Test for return of one with greater time assigned.
     // First delete all lessons for $temp_student_id591.
     unset($ac_class_instance);
     $this->resetMyArray();
     // Reset myArray.
     $temp_student_id591 = 'abcdefg';
     $ac_class_instance = new AssignmentsClass();
     $this->myArray['tA_S_ID'] = $temp_student_id591;
     $ac_class_instance->delRowsByStudentId($temp_student_id591);
     // Insure no previous lessons for this student.
     $this->myArray['tA_PercentTime'] = '150';
     $this->myArray['tG_AssignmentName'] = 'klm';
     $ac_class_instance->insertRecord($this->myArray);
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 1);
     // Now add another row with 0 % time.
     $this->myArray['tA_PercentTime'] = '0';
     $this->myArray['tG_AssignmentName'] = 'nop';
     $ac_class_instance->insertRecord($this->myArray);
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 2);
     $result = $ac_class_instance->getNextAssignmentToDo($temp_student_id591, $last_lesson_id);
     $this->assertTrue(is_array($result));
     $this->assertTrue(count($result) === 24);
     // Returns FALSE only if there are no lessons.
     $this->assertTrue($result['tG_AssignmentName'] === 'klm');
     // Clean Up.
     unset($ac_class_instance);
     // Reset myArray to origninal values.
     $this->resetMyArray();
     // Test 6
     // Delete all lessons and add two lessons one with 0 time assigned and
     // the other with 150% assigned in reverse order of previous test..
     // Test for return of one with greater time assigned.
     // First delete all lessons for $temp_student_id591.
     unset($ac_class_instance);
     $this->resetMyArray();
     // Reset myArray.
     $temp_student_id591 = 'abcdefg';
     $ac_class_instance = new AssignmentsClass();
     $this->myArray['tA_S_ID'] = $temp_student_id591;
     // Insure no previous lessons for this student.
     $ac_class_instance->delRowsByStudentId($temp_student_id591);
     $this->myArray['tA_PercentTime'] = '0';
     $this->myArray['tG_AssignmentName'] = 'klm';
     $ac_class_instance->insertRecord($this->myArray);
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 1);
     // Now add another row with 0 % time.
     $this->myArray['tA_PercentTime'] = '150';
     $this->myArray['tG_AssignmentName'] = 'klm';
     $ac_class_instance->insertRecord($this->myArray);
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 2);
     $last_lesson_id = '';
     $result = $ac_class_instance->getNextAssignmentToDo($temp_student_id591, $last_lesson_id);
     $this->assertTrue(is_array($result));
     $this->assertTrue(count($result) === 24);
     // Returns FALSE only if there are no lessons.
     $this->assertTrue($result['tG_AssignmentName'] === 'klm');
     // Clean Up.
     unset($ac_class_instance);
     // Reset myArray to origninal values.
     $this->resetMyArray();
     // Test 7    Add three new lessons and check frequency of return.
     $this->resetMyArray();
     // Reset myArray.
     $temp_student_id591 = 'asdfg  hjkl';
     $this->myArray['tA_S_ID'] = $temp_student_id591;
     $ac_class_instance = new AssignmentsClass();
     $ac_class_instance->delRowsByStudentId($temp_student_id591);
     // Previous line insures no previous lessons for this student.
     $this->myArray['tG_AssignmentName'] = 'aaaaa';
     $this->myArray['tA_PercentTime'] = '33';
     $result = $ac_class_instance->insertRecord($this->myArray);
     // Add a record.
     $this->assertTrue($result === 1);
     // This is a post date time.
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $this->assertTrue(is_array($result));
     // Look our for post date issues.
     $num_rows = count($result);
     $this->assertTrue($num_rows === 1);
     $this->myArray['tG_AssignmentName'] = 'bbbbb';
     $this->myArray['tA_PercentTime'] = '33';
     $ac_class_instance->insertRecord($this->myArray);
     // Add a record.
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $num_rows = count($result);
     $this->assertTrue($num_rows === 2);
     $this->myArray['tG_AssignmentName'] = 'ccccc';
     $this->myArray['tA_PercentTime'] = '33';
     $ac_class_instance->insertRecord($this->myArray);
     // Add a record.
     $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
     $this->assertTrue(count($result) === 3);
     // Now get back a bunch of lessons and check frequency of return
     // against assigned values.
     $total_aaaaa = 0;
     $total_bbbbb = 0;
     $total_ccccc = 0;
     $count = 0;
     for ($i = 1; $i <= 100; $i++) {
         // Run through 100 selections and see if they follow % assigned.
         $ac_class_instance = new AssignmentsClass();
         $result = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id591);
         $num_rows = count($result);
         $count++;
         if ($num_rows > 0) {
             foreach ($result as $key => $value) {
                 // Is an array of arrays.
                 if ($value['tG_AssignmentName'] === 'aaaaa') {
                     $total_aaaaa++;
                 }
                 if ($value['tG_AssignmentName'] === 'bbbbb') {
                     $total_bbbbb++;
                 }
                 if ($value['tG_AssignmentName'] === 'accccc') {
                     $total_ccccc++;
                 }
             }
         }
     }
     //end for
     $ac_class_instance->delRowsByStudentId($temp_student_id591);
     // Next reset myArray to origninal values.
     $this->resetMyArray();
     // Clean Up.
     $ac_class_instance->delRowsByStudentId($this->myArray['tA_S_ID']);
     $ac_class_instance->delRowsByStudentId('abcdefg');
     $ac_class_instance->delRowsByStudentId('x!@#$1112');
     unset($ac_class_instance);
     $this->resetMyArray();
 }
if (empty($_data['tA_S_ID']) === TRUE) {
    $msg = ' cAssignment_get_next_lesson.php    Must have "tA_S_ID" in $_data.';
    $msg = $msg . "\n" . __LINE__ . ' Missing $_data["tA_S_ID"] can not proceed';
    trigger_error($msg, E_USER_ERROR);
}
// Now get the student information and set all session variables.
$_data['tA_S_ID'] = filter_var($_data['tA_S_ID'], FILTER_UNSAFE_RAW);
$string = "\n" . __LINE__ . ' $_data["tA_S_ID"] = ' . $_data['tA_S_ID'];
fwrite($log_file, $string . "\n\n");
$_data['last_gA'] = NULL;
// Prime session with the existing relevant data.
$_SESSION = $_data;
// Get next assignment to do from the login data.
$next_lesson = new AssignmentsClass();
// Return a single lesson as a tAssignments row.
$lesson = $next_lesson->getNextAssignmentToDo($_data['tA_S_ID'], $_data['tA_id']);
$v = var_export($lesson, TRUE);
$string = "\n" . __LINE__ . ' $lesson = ' . $v . "\n\n";
fwrite($log_file, $string . "\n");
if (is_null($lesson) == TRUE) {
    $msg = $msg . "\n" . __LINE__ . ' No lesson found.';
    trigger_error($msg, E_USER_ERROR);
}
// From the assignment name retrieve the generic assignment and assign
// its variables  to the $_SESSION variable.
$my_next_ga = new GenericAClass();
$the_ga = $my_next_ga->getRowFromDbAsArray($lesson['tG_AssignmentName']);
// Pack all tGenericAssignment data into session varaiable.
foreach ($the_ga as $key => $value) {
    $_SESSION[$key] = $value;
}