From 15f3e9c0e46f090d2ea920c7b63f3b53cf8b68ff Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Tue, 20 Aug 2024 11:53:51 -0400 Subject: [PATCH 1/7] Revert #7647 --- includes/class-sensei-analysis-course-list-table.php | 2 +- includes/class-sensei-analysis-lesson-list-table.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-sensei-analysis-course-list-table.php b/includes/class-sensei-analysis-course-list-table.php index 5dbd08a74e..441dece346 100755 --- a/includes/class-sensei-analysis-course-list-table.php +++ b/includes/class-sensei-analysis-course-list-table.php @@ -328,7 +328,7 @@ public function generate_report( $report ) { $this->search = $search; $args = array( - 'number' => -1, + 'number' => '', 'offset' => 0, 'orderby' => $orderby, 'order' => $order, 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, From 2b1233b588d54c7604c676996a3f0d08d9546a0c Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Tue, 20 Aug 2024 12:01:32 -0400 Subject: [PATCH 2/7] Fix "Lessons in this Course" and "Students taking this Course" exports --- includes/class-sensei-analysis-course-list-table.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-sensei-analysis-course-list-table.php b/includes/class-sensei-analysis-course-list-table.php index 441dece346..3c7931dad3 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' => '', 'offset' => 0, 'orderby' => $orderby, 'order' => $order, @@ -347,12 +346,15 @@ public function generate_report( $report ) { switch ( $this->view ) { case 'user': + $args['number'] = ''; $this->items = $this->get_course_statuses( $args ); - break; + break; case 'lesson': default: + $args['number'] = -1; $this->items = $this->get_lessons( $args ); + break; } From 9223163d36a2f8cb5d1ab101c604798f97ba4c83 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Tue, 20 Aug 2024 12:12:44 -0400 Subject: [PATCH 3/7] Add change log entry --- changelog/fix-report-not-exporting | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/fix-report-not-exporting 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 From 71193526567fa7f668b49626e98151a38cba4040 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Tue, 20 Aug 2024 12:16:13 -0400 Subject: [PATCH 4/7] Fix linter issues --- includes/class-sensei-analysis-course-list-table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-sensei-analysis-course-list-table.php b/includes/class-sensei-analysis-course-list-table.php index 3c7931dad3..50680e491a 100755 --- a/includes/class-sensei-analysis-course-list-table.php +++ b/includes/class-sensei-analysis-course-list-table.php @@ -347,13 +347,13 @@ public function generate_report( $report ) { switch ( $this->view ) { case 'user': $args['number'] = ''; - $this->items = $this->get_course_statuses( $args ); + $this->items = $this->get_course_statuses( $args ); break; case 'lesson': default: $args['number'] = -1; - $this->items = $this->get_lessons( $args ); + $this->items = $this->get_lessons( $args ); break; } From 3c40a60a310a03a08e79c8202dc7855e9b0b358b Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Tue, 20 Aug 2024 16:34:53 -0400 Subject: [PATCH 5/7] Add unit tests for course report exports --- ...lass-sensei-analysis-course-list-table.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) 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(); From 77218c217febadba014477d5a1507f2e746e6b18 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Wed, 21 Aug 2024 10:23:48 -0400 Subject: [PATCH 6/7] Add unit tests for lesson report export --- ...lass-sensei-analysis-lesson-list-table.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php 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..f54a9ffd4e --- /dev/null +++ b/tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php @@ -0,0 +1,53 @@ +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. + } +} From e2d2c6babdf7905e54047a1b1ac7699355ac6f26 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Wed, 21 Aug 2024 10:35:00 -0400 Subject: [PATCH 7/7] Fix linter complaints --- .../test-class-sensei-analysis-lesson-list-table.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 index f54a9ffd4e..30fa99d539 100644 --- a/tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php +++ b/tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php @@ -25,11 +25,13 @@ public function setUp(): void { public function testGenerateReport_StudentsByLesson_ReturnsCorrectNumberOfRows() { /* Arrange. */ $course_id = $this->factory->course->create(); - $lesson_id = $this->factory->lesson->create( [ - 'meta_input' => [ - '_lesson_course' => $course_id, - ], - ] ); + $lesson_id = $this->factory->lesson->create( + [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ] + ); $user1_id = $this->factory->user->create(); $user2_id = $this->factory->user->create();