2018-03-14 14:29:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Privacy data exporter.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tests\Util
|
|
|
|
*/
|
|
|
|
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-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
|
|
|
/**
|
|
|
|
* Clean up after test.
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
foreach ( $this->orders as $object ) {
|
|
|
|
$object->delete( true );
|
|
|
|
}
|
|
|
|
foreach ( $this->customers as $object ) {
|
|
|
|
$object->delete( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: Customer data exporter.
|
|
|
|
*/
|
|
|
|
public function test_customer_data_exporter() {
|
2018-03-14 15:14:45 +00:00
|
|
|
// Test a non existing user.
|
2018-04-13 17:25:51 +00:00
|
|
|
$response = WC_Privacy::customer_data_exporter( 'doesnotexist@test.com', 1 );
|
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-04-13 17:25:51 +00:00
|
|
|
$response = WC_Privacy::customer_data_exporter( 'test1@test.com', 1 );
|
|
|
|
$this->assertTrue( $response['done'] );
|
2018-03-14 15:14:45 +00:00
|
|
|
$this->assertEquals( array(
|
2018-03-15 10:54:32 +00:00
|
|
|
array(
|
2018-04-13 17:25:51 +00:00
|
|
|
'group_id' => 'woocommerce_customer',
|
|
|
|
'group_label' => 'Customer Data',
|
|
|
|
'item_id' => 'user',
|
|
|
|
'data' => array(
|
|
|
|
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(
|
|
|
|
'name' => 'Billing Country',
|
|
|
|
'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(
|
|
|
|
'name' => 'Shipping Country',
|
|
|
|
'value' => 'US',
|
|
|
|
),
|
|
|
|
),
|
2018-03-15 10:54:32 +00:00
|
|
|
),
|
2018-03-14 15:14:45 +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() {
|
|
|
|
$response = WC_Privacy::order_data_exporter( 'test1@test.com', 1 );
|
|
|
|
|
|
|
|
$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-04-13 17:25:51 +00:00
|
|
|
$response = WC_Privacy::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
|
|
|
}
|
|
|
|
}
|