/** * Test getNextAssignmentToDo() * @return void */ 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->testbuildArray(); // Reset myArray to origninal values. $classInstance = new tutor\src\classes\AssignmentsClass(); $tempStudent591 = 'abcdefg'; // Next insure no previous lessons for this student. $numRows = $classInstance->delRowsByStudentId($tempStudent591); $this->assertTrue($numRows === 0); // Any number greater than 0 would indicate a clean-up failure in // another function. $this->myArray['tA_S_ID'] = $tempStudent591; $lastLessonId = ''; // Test 1 Check for no lessons to do because no student exists. $result = $classInstance->getNextAssignmentToDo($tempStudent591, $lastLessonId); //$log_file = fopen("/var/www/html/jimfuqua/tutor/logs/ACT_testgetNextAssignmentToDo.log", "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 = $classInstance->delRowsByStudentId($tempStudent591); // Start with none. $this->assertTrue($result === 0); $classInstance->insertRecord($this->myArray); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); // $log_file = fopen("/var/www/html/jimfuqua/tutor/logs/testgetNextAssignmentToDo.log", "w"); // $v = var_export($result, true); // $string = __LINE__.' AC $result = '.$v."\n"; // fwrite($log_file, $string); $numRows = count($result); $v = var_export($numRows, true); // $string = __LINE__.' AC $numRows = '.$v."\n"; // fwrite($log_file, $string); $this->assertTrue($numRows === 1); $lastLessonId = ''; $result = $classInstance->getNextAssignmentToDo($tempStudent591, $lastLessonId); $numRows = count($result); $v = var_export($numRows, true); // $string = __LINE__.' AC $numRows = '.$v."\n"; // fwrite($log_file, $string); $this->assertTrue($numRows === 24); // Test 3 add an identical lesson and test for number of lessons = 2. $classInstance->insertRecord($this->myArray); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 2); // Test 4 Delete all lessons and add one specific lesson back. // Test that it is returned. $result = $classInstance->delRowsByStudentId($tempStudent591); // Start with none. $this->myArray['tG_AssignmentName'] = 'fffff'; $classInstance->insertRecord($this->myArray); // Add a record. $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 1); // Get it back. $lastLessonId = ''; $result = $classInstance->getNextAssignmentToDo($tempStudent591, $lastLessonId); $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'] === $tempStudent591); $result = $classInstance->delRowsByStudentId($tempStudent591); // Insure no previous lessons for this student. $this->assertTrue($result === 1); // Any number greater than 1 would indicate a clean-up failure. $this->testbuildArray(); // Reset myArray to original values. unset($classInstance); // 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 $tempStudent591. unset($classInstance); $this->testbuildArray(); // Reset myArray. $tempStudent591 = 'abcdefg'; $classInstance = new tutor\src\classes\AssignmentsClass(); $this->myArray['tA_S_ID'] = $tempStudent591; $classInstance->delRowsByStudentId($tempStudent591); // Insure no previous lessons for this student. $this->myArray['tA_PercentTime'] = '150'; $this->myArray['tG_AssignmentName'] = 'klm'; $classInstance->insertRecord($this->myArray); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 1); // Now add another row with 0 % time. $this->myArray['tA_PercentTime'] = '0'; $this->myArray['tG_AssignmentName'] = 'nop'; $classInstance->insertRecord($this->myArray); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 2); $result = $classInstance->getNextAssignmentToDo($tempStudent591, $lastLessonId); $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($classInstance); // Reset myArray to origninal values. $this->testbuildArray(); // 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 $tempStudent591. unset($classInstance); $this->testbuildArray(); // Reset myArray. $tempStudent591 = 'abcdefg'; $classInstance = new tutor\src\classes\AssignmentsClass(); $this->myArray['tA_S_ID'] = $tempStudent591; // Insure no previous lessons for this student. $classInstance->delRowsByStudentId($tempStudent591); $this->myArray['tA_PercentTime'] = '0'; $this->myArray['tG_AssignmentName'] = 'klm'; $classInstance->insertRecord($this->myArray); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 1); // Now add another row with 0 % time. $this->myArray['tA_PercentTime'] = '150'; $this->myArray['tG_AssignmentName'] = 'klm'; $classInstance->insertRecord($this->myArray); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 2); $lastLessonId = ''; $result = $classInstance->getNextAssignmentToDo($tempStudent591, $lastLessonId); $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($classInstance); // Reset myArray to origninal values. $this->testbuildArray(); // Test 7 Add three new lessons and check frequency of return. $this->testbuildArray(); // Reset myArray. $tempStudent591 = 'asdfg hjkl'; $this->myArray['tA_S_ID'] = $tempStudent591; $classInstance = new tutor\src\classes\AssignmentsClass(); $classInstance->delRowsByStudentId($tempStudent591); // Previous line insures no previous lessons for this student. $this->myArray['tG_AssignmentName'] = 'aaaaa'; $this->myArray['tA_PercentTime'] = '33'; $result = $classInstance->insertRecord($this->myArray); // Add a record. $this->assertTrue($result === 1); // This is a post date time. $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $this->assertTrue(is_array($result)); // Look our for post date issues. $numRows = count($result); $this->assertTrue($numRows === 1); $this->myArray['tG_AssignmentName'] = 'bbbbb'; $this->myArray['tA_PercentTime'] = '33'; $classInstance->insertRecord($this->myArray); // Add a record. $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $this->assertTrue($numRows === 2); $this->myArray['tG_AssignmentName'] = 'ccccc'; $this->myArray['tA_PercentTime'] = '33'; $classInstance->insertRecord($this->myArray); // Add a record. $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $this->assertTrue(count($result) === 3); // Now get back a bunch of lessons and check frequency of return // against assigned values. $totalAaaaa = 0; $totalBbbbb = 0; $totalCcccc = 0; $count = 0; for ($i = 1; $i <= 100; $i++) { // Run through 100 selections and see if they follow % assigned. $classInstance = new tutor\src\classes\AssignmentsClass(); $result = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent591); $numRows = count($result); $count++; if ($numRows > 0) { foreach ($result as $key => $value) { // Is an array of arrays. if ($value['tG_AssignmentName'] === 'aaaaa') { $totalAaaaa++; } if ($value['tG_AssignmentName'] === 'bbbbb') { $totalBbbbb++; } if ($value['tG_AssignmentName'] === 'accccc') { $totalCccccc++; } } } } //end for $classInstance->delRowsByStudentId($tempStudent591); // Next reset myArray to origninal values. $this->testbuildArray(); // Clean Up. $classInstance->delRowsByStudentId($this->myArray['tA_S_ID']); $classInstance->delRowsByStudentId('abcdefg'); unset($classInstance); }