2019-09-06 02:06:29 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Onboarding Tasks REST API Test
|
|
|
|
*
|
|
|
|
* @package WooCommerce Admin\Tests\API
|
|
|
|
*/
|
|
|
|
|
|
|
|
use \Automattic\WooCommerce\Admin\API\OnboardingTasks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC Tests API Onboarding Tasks
|
|
|
|
*/
|
|
|
|
class WC_Tests_API_Onboarding_Tasks extends WC_REST_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Endpoints.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-11-12 18:15:55 +00:00
|
|
|
protected $endpoint = '/wc-admin/onboarding/tasks';
|
2019-09-06 02:06:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup test data. Called before every test.
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->user = $this->factory->user->create(
|
|
|
|
array(
|
|
|
|
'role' => 'administrator',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that sample product data is imported.
|
|
|
|
*/
|
|
|
|
public function test_import_sample_products() {
|
|
|
|
wp_set_current_user( $this->user );
|
|
|
|
|
|
|
|
$request = new WP_REST_Request( 'POST', $this->endpoint . '/import_sample_products' );
|
|
|
|
$response = $this->server->dispatch( $request );
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals( 200, $response->get_status() );
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'failed', $data );
|
|
|
|
$this->assertArrayHasKey( 'imported', $data );
|
|
|
|
$this->assertArrayHasKey( 'skipped', $data );
|
|
|
|
$this->assertArrayHasKey( 'updated', $data );
|
|
|
|
}
|
2019-09-06 14:18:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that Tasks data is returned by the endpoint.
|
|
|
|
*/
|
|
|
|
public function test_create_homepage() {
|
|
|
|
wp_set_current_user( $this->user );
|
|
|
|
|
|
|
|
$request = new WP_REST_Request( 'POST', $this->endpoint . '/create_homepage' );
|
|
|
|
$response = $this->server->dispatch( $request );
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals( 200, $response->get_status() );
|
|
|
|
$this->assertEquals( 'success', $data['status'] );
|
|
|
|
$this->assertEquals( get_option( 'woocommerce_onboarding_homepage_post_id' ), $data['post_id'] );
|
|
|
|
$this->assertEquals( htmlspecialchars_decode( get_edit_post_link( get_option( 'woocommerce_onboarding_homepage_post_id' ) ) ), $data['edit_post_link'] );
|
|
|
|
}
|
2020-04-08 21:26:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the default homepage template can be filtered.
|
|
|
|
*/
|
|
|
|
public function test_homepage_template_can_be_filtered() {
|
|
|
|
wp_set_current_user( $this->user );
|
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_admin_onboarding_homepage_template',
|
|
|
|
function ( $template ) {
|
|
|
|
return 'Custom post content';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$request = new WP_REST_Request( 'POST', $this->endpoint . '/create_homepage' );
|
|
|
|
$response = $this->server->dispatch( $request );
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertSame( 'Custom post content', get_the_content( null, null, $data['post_id'] ) );
|
|
|
|
}
|
2019-09-06 02:06:29 +00:00
|
|
|
}
|