Address PR feedback and fix PHP unit tests

This commit is contained in:
Lourens Schep 2022-04-06 10:08:22 -03:00
parent a7ec024471
commit 828e34a974
3 changed files with 6 additions and 19 deletions

View File

@ -350,10 +350,11 @@ class TaskList {
*/ */
public function get_json() { public function get_json() {
$this->possibly_track_completion(); $this->possibly_track_completion();
// Track completion of non viewable tasks. $tasks_json = array();
foreach ( $this->tasks as $task ) { foreach ( $this->tasks as $task ) {
if ( ! $task->can_view() ) { $json = $task->get_json();
$task->possibly_track_completion(); if ( $json['canView'] ) {
$tasks_json[] = $json;
} }
} }
@ -363,12 +364,7 @@ class TaskList {
'isHidden' => $this->is_hidden(), 'isHidden' => $this->is_hidden(),
'isVisible' => $this->is_visible(), 'isVisible' => $this->is_visible(),
'isComplete' => $this->is_complete(), 'isComplete' => $this->is_complete(),
'tasks' => array_map( 'tasks' => $tasks_json,
function( $task ) {
return $task->get_json();
},
$this->get_viewable_tasks()
),
'eventPrefix' => $this->prefix_event( '' ), 'eventPrefix' => $this->prefix_event( '' ),
'displayProgressHeader' => $this->display_progress_header, 'displayProgressHeader' => $this->display_progress_header,
); );

View File

@ -394,7 +394,7 @@ class WC_Admin_Tests_OnboardingTasks_Task extends WC_Unit_Test_Case {
*/ */
public function test_get_list_id() { public function test_get_list_id() {
$task = new TestTask( $task = new TestTask(
new TaskList( array( 'id' => 'setup' ) ), new TaskList( array( 'id' => 'extended' ) ),
array( array(
'id' => 'wc-unit-test-task', 'id' => 'wc-unit-test-task',
) )

View File

@ -96,15 +96,6 @@ class TestTask extends Task {
return $this->content; return $this->content;
} }
/**
* Parent ID.
*
* @return string
*/
public function get_parent_id() {
return 'extended';
}
/** /**
* Level. * Level.
* *