diff --git a/changelog/fix-report-not-exporting b/changelog/fix-report-not-exporting new file mode 100644 index 0000000000..b0a7eb84b3 --- /dev/null +++ b/changelog/fix-report-not-exporting @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Some reports not exporting all rows diff --git a/includes/class-sensei-analysis-course-list-table.php b/includes/class-sensei-analysis-course-list-table.php index 5dbd08a74e..50680e491a 100755 --- a/includes/class-sensei-analysis-course-list-table.php +++ b/includes/class-sensei-analysis-course-list-table.php @@ -328,7 +328,6 @@ public function generate_report( $report ) { $this->search = $search; $args = array( - 'number' => -1, 'offset' => 0, 'orderby' => $orderby, 'order' => $order, @@ -347,12 +346,15 @@ public function generate_report( $report ) { switch ( $this->view ) { case 'user': - $this->items = $this->get_course_statuses( $args ); - break; + $args['number'] = ''; + $this->items = $this->get_course_statuses( $args ); + break; case 'lesson': default: - $this->items = $this->get_lessons( $args ); + $args['number'] = -1; + $this->items = $this->get_lessons( $args ); + break; } diff --git a/includes/class-sensei-analysis-lesson-list-table.php b/includes/class-sensei-analysis-lesson-list-table.php index 5e61540034..41b96c7a87 100755 --- a/includes/class-sensei-analysis-lesson-list-table.php +++ b/includes/class-sensei-analysis-lesson-list-table.php @@ -192,7 +192,7 @@ public function generate_report( $report ) { $this->search = $search; $args = array( - 'number' => -1, + 'number' => '', 'offset' => 0, 'orderby' => $orderby, 'order' => $order, diff --git a/tests/unit-tests/test-class-sensei-analysis-course-list-table.php b/tests/unit-tests/test-class-sensei-analysis-course-list-table.php index 9366614176..2b33ccd0b2 100644 --- a/tests/unit-tests/test-class-sensei-analysis-course-list-table.php +++ b/tests/unit-tests/test-class-sensei-analysis-course-list-table.php @@ -112,6 +112,51 @@ public function testPrepareItems_DefaultDateFilterSet_SetsMatchingItems() { self::assertSame( $expected, $this->export_items( $table->items ) ); } + public function testGenerateReport_LessonView_ReturnsCorrectNumberOfRows() { + /* Arrange. */ + $course_id = $this->factory->course->create(); + $lesson_args = [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ]; + + $lesson1_id = $this->factory->lesson->create( $lesson_args ); + $lesson2_id = $this->factory->lesson->create( $lesson_args ); + $lesson3_id = $this->factory->lesson->create( $lesson_args ); + + $_GET['view'] = 'lesson'; + + /* Act. */ + $table = new Sensei_Analysis_Course_List_Table( $course_id ); + $export_data = $table->generate_report( 'course-name-lessons-overview' ); + + /* Assert. */ + self::assertSame( 4, count( $export_data ) ); // Header row + 3 lessons. + } + + public function testGenerateReport_UserView_ReturnsCorrectNumberOfRows() { + /* Arrange. */ + $course_id = $this->factory->course->create(); + + $user1_id = $this->factory->user->create(); + $user2_id = $this->factory->user->create(); + $user3_id = $this->factory->user->create(); + + $activity1_id = Sensei_Utils::start_user_on_course( $user1_id, $course_id ); + $activity2_id = Sensei_Utils::start_user_on_course( $user2_id, $course_id ); + $activity3_id = Sensei_Utils::start_user_on_course( $user3_id, $course_id ); + + $_GET['view'] = 'user'; + + /* Act. */ + $table = new Sensei_Analysis_Course_List_Table( $course_id ); + $export_data = $table->generate_report( 'course-name-users-overview' ); + + /* Assert. */ + self::assertSame( 4, count( $export_data ) ); // Header row + 3 students. + } + public function testTableFooter_WhenCalledWithNoData_NotDisplayTheExportButton() { /* Arrange. */ $list_table = new Sensei_Analysis_Course_List_Table(); diff --git a/tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php b/tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php new file mode 100644 index 0000000000..30fa99d539 --- /dev/null +++ b/tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php @@ -0,0 +1,55 @@ +factory = new Sensei_Factory(); + } + + public function testGenerateReport_StudentsByLesson_ReturnsCorrectNumberOfRows() { + /* Arrange. */ + $course_id = $this->factory->course->create(); + $lesson_id = $this->factory->lesson->create( + [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ] + ); + + $user1_id = $this->factory->user->create(); + $user2_id = $this->factory->user->create(); + $user3_id = $this->factory->user->create(); + + Sensei_Utils::start_user_on_course( $user1_id, $course_id ); + Sensei_Utils::start_user_on_course( $user2_id, $course_id ); + Sensei_Utils::start_user_on_course( $user3_id, $course_id ); + + Sensei_Utils::user_start_lesson( $user1_id, $lesson_id ); + Sensei_Utils::user_start_lesson( $user2_id, $lesson_id ); + Sensei_Utils::user_start_lesson( $user3_id, $lesson_id ); + + /* Act. */ + $table = new Sensei_Analysis_Lesson_List_Table( $lesson_id ); + $export_data = $table->generate_report( 'lesson-name-learners-overview' ); + + /* Assert. */ + self::assertSame( 4, count( $export_data ) ); // Header row + 3 students. + } +}