Add a unit test for `woocommerce_admin_experimental_onboarding_tasklists` filter (#36827)

* Add a unit test for woocommerce_admin_experimental_onboarding_tasklists filter

* Add changelog

* Reformat

* Update plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/task-lists.php

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>

---------

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
This commit is contained in:
Chi-Hsuan Huang 2023-02-20 09:03:41 +08:00 committed by GitHub
parent 30409fa8c3
commit 2d5fdfe578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Add a unit test for woocommerce_admin_experimental_onboarding_tasklists filter

View File

@ -0,0 +1,59 @@
<?php
/**
* Test the TaskLists class.
*
* @package WooCommerce\Admin\Tests\OnboardingTasks
*/
/**
* Test task fixture.
*/
require_once __DIR__ . '/test-task.php';
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
/**
* Class WC_Tests_OnboardingTasks_TaskLists
*/
class WC_Tests_OnboardingTasks_TaskLists extends WC_Unit_Test_Case {
/**
* Setup test data. Called before every test.
*/
public function setUp(): void {
parent::setUp();
TaskLists::clear_lists();
}
/**
* Tests that the "woocommerce_admin_experimental_onboarding_tasklists" filter is able to append tasks to any tasklist.
*/
public function test_default_tasklists_can_be_add_by_onboarding_filter() {
// Filter the default task lists.
add_filter(
'woocommerce_admin_experimental_onboarding_tasklists',
function(
$task_lists
) {
$this->assertIsArray( $task_lists );
// Add a new task list.
$task_lists['test'] = new TaskList(
array(
'id' => 'test',
'title' => 'Test',
'tasks' => array(),
'isHidden' => false,
)
);
return $task_lists;
}
);
// Initialize the default task lists.
TaskLists::init_default_lists();
// Assert that the new task list is added.
$this->assertNotEmpty( TaskLists::get_list( 'test' ) );
}
}