Skip to content

Commit

Permalink
Add tests for register and content methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalec committed Jul 27, 2023
1 parent bcde18f commit 29f2e36
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Unit/TaskList/CompleteSetupTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\tasks;

use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService;
use Automattic\WooCommerce\GoogleListingsAndAds\TaskList\CompleteSetupTask;
use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest;
Expand All @@ -28,12 +29,30 @@ class CompleteSetupTaskTest extends UnitTest {
*/
public function setUp(): void {
parent::setUp();
// Mock tasks list.
TaskLists::clear_lists();
TaskLists::add_list( [ 'id' => 'extended' ] );
// Mock MC setup.
$this->merchant_center = $this->createMock( MerchantCenterService::class );

$this->task = new CompleteSetupTask();
$this->task->set_merchant_center_object( $this->merchant_center );
}

/**
* Test that after the task is registered and `init` fired,
* the task is added to the `extended` list and the `add_woocommerce_extended_task_list_item` action is called.
*/
public function test_register() {
$this->task->register();
do_action( 'init', 1 );

$this->assertGreaterThan( 0, did_action( 'add_woocommerce_extended_task_list_item' ) );

$this->assertNotNull( TaskLists::get_list( 'extended' )->get_task( $this->task->get_id() ) );
$this->assertEquals( $this->task, TaskLists::get_list( 'extended' )->get_task( $this->task->get_id() ) );
}

public function test_id() {
$this->assertEquals( 'gla_complete_setup', $this->task->get_id() );
}
Expand All @@ -42,9 +61,14 @@ public function test_title() {
$this->assertEquals( 'Set up Google Listings & Ads', $this->task->get_title() );
}

public function test_content() {
$this->assertEquals( '', $this->task->get_content() );
}

public function test_time() {
$this->assertEquals( '20 minutes', $this->task->get_time() );
}

public function test_dismissable() {
$this->assertTrue( $this->task->is_dismissable() );
}
Expand Down

0 comments on commit 29f2e36

Please sign in to comment.