2018-03-14 14:29:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Privacy data exporter.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tests\Util
|
|
|
|
*/
|
2020-02-04 12:45:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for WC_Privacy_Exporters class.
|
|
|
|
*/
|
2018-03-14 14:29:03 +00:00
|
|
|
class WC_Test_Privacy_Export extends WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Order tracking for cleanup.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $orders = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customer tracking for cleanup.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $customers = array();
|
|
|
|
|
|
|
|
/**
|
2018-04-13 17:25:51 +00:00
|
|
|
* Load up the importer classes since they aren't loaded by default.
|
2018-03-14 14:29:03 +00:00
|
|
|
*/
|
2018-04-13 17:25:51 +00:00
|
|
|
public function setUp() {
|
2018-04-20 18:48:00 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2018-03-14 14:29:03 +00:00
|
|
|
$customer1 = WC_Helper_Customer::create_customer( 'customer1', 'password', 'test1@test.com' );
|
|
|
|
$customer1->set_billing_email( 'customer1@test.com' );
|
|
|
|
$customer1->save();
|
|
|
|
|
|
|
|
$customer2 = WC_Helper_Customer::create_customer( 'customer2', 'password', 'test2@test.com' );
|
|
|
|
$customer2->set_billing_email( 'customer2@test.com' );
|
|
|
|
$customer2->save();
|
|
|
|
|
|
|
|
$this->customers[] = $customer1;
|
|
|
|
$this->customers[] = $customer2;
|
|
|
|
|
|
|
|
// Create a bunch of dummy orders for some users.
|
2018-03-14 15:14:45 +00:00
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer1->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer2->get_id() );
|
|
|
|
$this->orders[] = WC_Helper_Order::create_order( $customer2->get_id() );
|
2018-04-13 17:25:51 +00:00
|
|
|
}
|
2018-03-14 15:14:45 +00:00
|
|
|
|
2018-04-13 17:25:51 +00:00
|
|
|
/**
|
|
|
|
* Test: Customer data exporter.
|
|
|
|
*/
|
|
|
|
public function test_customer_data_exporter() {
|
2018-03-14 15:14:45 +00:00
|
|
|
// Test a non existing user.
|
2018-06-07 15:25:13 +00:00
|
|
|
$response = WC_Privacy_Exporters::customer_data_exporter( 'doesnotexist@test.com' );
|
2018-03-14 15:14:45 +00:00
|
|
|
$this->assertEquals( array(), $response['data'] );
|
2018-03-14 14:29:03 +00:00
|
|
|
|
|
|
|
// Do a test export and check response.
|
2018-06-07 15:25:13 +00:00
|
|
|
$response = WC_Privacy_Exporters::customer_data_exporter( 'test1@test.com' );
|
2018-04-13 17:25:51 +00:00
|
|
|
$this->assertTrue( $response['done'] );
|
2018-04-20 17:53:06 +00:00
|
|
|
$this->assertEquals(
|
2018-03-15 10:54:32 +00:00
|
|
|
array(
|
2018-04-20 17:53:06 +00:00
|
|
|
array(
|
2020-02-04 20:57:31 +00:00
|
|
|
'group_id' => 'woocommerce_customer',
|
|
|
|
'group_label' => 'Customer Data',
|
|
|
|
'group_description' => 'User’s WooCommerce customer data.',
|
|
|
|
'item_id' => 'user',
|
|
|
|
'data' => array(
|
2018-04-20 17:53:06 +00:00
|
|
|
array(
|
|
|
|
'name' => 'Billing Address 1',
|
|
|
|
'value' => '123 South Street',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Billing Address 2',
|
|
|
|
'value' => 'Apt 1',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Billing City',
|
|
|
|
'value' => 'Philadelphia',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Billing Postal/Zip Code',
|
|
|
|
'value' => '19123',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Billing State',
|
|
|
|
'value' => 'PA',
|
|
|
|
),
|
|
|
|
array(
|
2020-02-04 12:45:28 +00:00
|
|
|
'name' => 'Billing Country / Region',
|
2018-04-20 17:53:06 +00:00
|
|
|
'value' => 'US',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Email Address',
|
|
|
|
'value' => 'customer1@test.com',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shipping Address 1',
|
|
|
|
'value' => '123 South Street',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shipping Address 2',
|
|
|
|
'value' => 'Apt 1',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shipping City',
|
|
|
|
'value' => 'Philadelphia',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shipping Postal/Zip Code',
|
|
|
|
'value' => '19123',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shipping State',
|
|
|
|
'value' => 'PA',
|
|
|
|
),
|
|
|
|
array(
|
2020-02-04 12:45:28 +00:00
|
|
|
'name' => 'Shipping Country / Region',
|
2018-04-20 17:53:06 +00:00
|
|
|
'value' => 'US',
|
|
|
|
),
|
2018-04-13 17:25:51 +00:00
|
|
|
),
|
|
|
|
),
|
2018-03-15 10:54:32 +00:00
|
|
|
),
|
2018-04-20 17:53:06 +00:00
|
|
|
$response['data']
|
|
|
|
);
|
2018-04-13 17:25:51 +00:00
|
|
|
}
|
2018-03-14 15:14:45 +00:00
|
|
|
|
2018-04-13 17:25:51 +00:00
|
|
|
/**
|
|
|
|
* Test: Order data exporter.
|
|
|
|
*/
|
|
|
|
public function test_order_data_exporter() {
|
2018-05-01 15:53:05 +00:00
|
|
|
$response = WC_Privacy_Exporters::order_data_exporter( 'test1@test.com', 1 );
|
2018-04-13 17:25:51 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'woocommerce_orders', $response['data'][0]['group_id'] );
|
|
|
|
$this->assertEquals( 'Orders', $response['data'][0]['group_label'] );
|
|
|
|
$this->assertContains( 'order-', $response['data'][0]['item_id'] );
|
|
|
|
$this->assertArrayHasKey( 'data', $response['data'][0] );
|
|
|
|
$this->assertTrue( 8 === count( $response['data'][0]['data'] ), count( $response['data'][0]['data'] ) );
|
2018-03-14 14:29:03 +00:00
|
|
|
|
2018-03-14 15:14:45 +00:00
|
|
|
// Next page should be orders.
|
2018-05-01 15:53:05 +00:00
|
|
|
$response = WC_Privacy_Exporters::order_data_exporter( 'test1@test.com', 2 );
|
2018-03-14 15:14:45 +00:00
|
|
|
$this->assertTrue( $response['done'] );
|
2018-04-13 17:25:51 +00:00
|
|
|
$this->assertTrue( 8 === count( $response['data'][0]['data'] ), count( $response['data'][0]['data'] ) );
|
2018-03-14 14:29:03 +00:00
|
|
|
}
|
|
|
|
}
|