Skip to content

Commit

Permalink
Merge pull request #7670 from Automattic/fix/report-not-exporting
Browse files Browse the repository at this point in the history
Fix some reports not exporting all rows
  • Loading branch information
donnapep committed Aug 22, 2024
2 parents 226c7ac + e2d2c6b commit d2ee44e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-report-not-exporting
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Some reports not exporting all rows
10 changes: 6 additions & 4 deletions includes/class-sensei-analysis-course-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ public function generate_report( $report ) {
$this->search = $search;

$args = array(
'number' => -1,
'offset' => 0,
'orderby' => $orderby,
'order' => $order,
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-sensei-analysis-lesson-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function generate_report( $report ) {
$this->search = $search;

$args = array(
'number' => -1,
'number' => '',
'offset' => 0,
'orderby' => $orderby,
'order' => $order,
Expand Down
45 changes: 45 additions & 0 deletions tests/unit-tests/test-class-sensei-analysis-course-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
55 changes: 55 additions & 0 deletions tests/unit-tests/test-class-sensei-analysis-lesson-list-table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* Sensei Analysis Lesson List Table Unit Test.
*
* @covers Sensei_Analysis_Lesson_List_Table
*/
class Sensei_Analysis_Lesson_List_Table_Test extends WP_UnitTestCase {
/**
* Factory object.
*
* @var Sensei_Factory
*/
protected $factory;

/**
* Set up the test.
*/
public function setUp(): void {
parent::setUp();

$this->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.
}
}

0 comments on commit d2ee44e

Please sign in to comment.