View source
<?php
namespace Mailchimp\Tests;
use PHPUnit\Framework\TestCase;
class MailchimpEcommerceTest extends TestCase {
public function testGetStores() {
$mc = new MailchimpEcommerce();
$mc
->getStores();
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores', $mc
->getClient()->uri);
}
public function testGetStore() {
$store_id = 'MC002';
$mc = new MailchimpEcommerce();
$mc
->getStore($store_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id, $mc
->getClient()->uri);
}
public function testAddStore() {
$id = 'MC001';
$store = [
'list_id' => '205d96e6b4',
'name' => "Freddie's Merchandise",
'currency_code' => 'USD',
];
$mc = new MailchimpEcommerce();
$mc
->addStore($id, $store);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($id, $request_body->id);
$this
->assertEquals($store['list_id'], $request_body->list_id);
$this
->assertEquals($store['name'], $request_body->name);
$this
->assertEquals($store['currency_code'], $request_body->currency_code);
}
public function testUpdateStore() {
$store_id = 'MC001';
$name = "Freddie's Merchandise";
$currency_code = 'USD';
$mc = new MailchimpEcommerce();
$mc
->updateStore($store_id, $name, $currency_code);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id, $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($name, $request_body->name);
$this
->assertEquals($currency_code, $request_body->currency_code);
}
public function testDeleteStore() {
$store_id = 'MC002';
$mc = new MailchimpEcommerce();
$mc
->deleteStore($store_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id, $mc
->getClient()->uri);
}
public function testGetCarts() {
$store_id = 'MC001';
$mc = new MailchimpEcommerce();
$mc
->getCarts($store_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts', $mc
->getClient()->uri);
}
public function testGetCart() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$mc = new MailchimpEcommerce();
$mc
->getCart($store_id, $cart_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id, $mc
->getClient()->uri);
}
public function testAddCart() {
$store_id = 'MC001';
$id = 'cart0001';
$customer = [
'id' => 'cust0005',
'email_address' => 'freddy@freddiesjokes.com',
'opt_in_status' => TRUE,
];
$cart = [
'currency_code' => 'USD',
'order_total' => 12.45,
'lines' => [
'id' => 'LINE001',
'product_id' => 'PROD001',
'product_title' => "Freddie's Jokes",
'product_variant_id' => 'PROD001A',
'product_variant_title' => "Freddie's Jokes Volume 1",
'quantity' => 2,
'price' => 10,
],
];
$mc = new MailchimpEcommerce();
$mc
->addCart($store_id, $id, $customer, $cart);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($id, $request_body->id);
$this
->assertEquals($customer['id'], $request_body->customer->id);
$this
->assertEquals($customer['email_address'], $request_body->customer->email_address);
$this
->assertEquals($customer['opt_in_status'], $request_body->customer->opt_in_status);
$this
->assertEquals($cart['currency_code'], $request_body->currency_code);
$this
->assertEquals($cart['order_total'], $request_body->order_total);
$this
->assertEquals($cart['lines'], $request_body->lines);
$this
->assertEquals($cart['lines']['id'], $request_body->lines['id']);
$this
->assertEquals($cart['lines']['product_id'], $request_body->lines['product_id']);
$this
->assertEquals($cart['lines']['product_title'], $request_body->lines['product_title']);
$this
->assertEquals($cart['lines']['product_variant_id'], $request_body->lines['product_variant_id']);
$this
->assertEquals($cart['lines']['product_variant_title'], $request_body->lines['product_variant_title']);
$this
->assertEquals($cart['lines']['quantity'], $request_body->lines['quantity']);
$this
->assertEquals($cart['lines']['price'], $request_body->lines['price']);
}
public function testUpdateCart() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$mc = new MailchimpEcommerce();
$mc
->updateCart($store_id, $cart_id);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id, $mc
->getClient()->uri);
}
public function testDeleteCart() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$mc = new MailchimpEcommerce();
$mc
->deleteCart($store_id, $cart_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndPoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id, $mc
->getClient()->uri);
}
public function testGetCartLines() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$mc = new MailchimpEcommerce();
$mc
->getCartLines($store_id, $cart_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines', $mc
->getClient()->uri);
}
public function testGetCartLine() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$line_id = 'line002';
$mc = new MailchimpEcommerce();
$mc
->getCartLine($store_id, $cart_id, $line_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines/' . $line_id, $mc
->getClient()->uri);
}
public function testAddCartLine() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$id = 'L001';
$product = [
'product_id' => 'PROD001',
'product_variant_id' => "Freddie's Jokes",
'quantity' => 1,
'price' => 5,
];
$mc = new MailchimpEcommerce();
$mc
->addCartLine($store_id, $cart_id, $id, $product);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($id, $request_body->id);
$this
->assertEquals($product['product_id'], $request_body->product_id);
$this
->assertEquals($product['product_variant_id'], $request_body->product_variant_id);
$this
->assertEquals($product['quantity'], $request_body->quantity);
$this
->assertEquals($product['price'], $request_body->price);
}
public function testUpdateCartLine() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$line_id = 'L001';
$mc = new MailchimpEcommerce();
$mc
->updateCartLine($store_id, $cart_id, $line_id);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines/' . $line_id, $mc
->getClient()->uri);
}
public function testDeleteCartLine() {
$store_id = 'MC001';
$cart_id = 'cart0001';
$line_id = 'L001';
$mc = new MailchimpEcommerce();
$mc
->deleteCartLine($store_id, $cart_id, $line_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndPoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines/' . $line_id, $mc
->getClient()->uri);
}
public function testGetCustomers() {
$store_id = 'MC001';
$mc = new MailchimpEcommerce();
$mc
->getCustomers($store_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndPoint() . '/ecommerce/stores/' . $store_id . '/customers', $mc
->getClient()->uri);
}
public function testGetCustomer() {
$store_id = 'MC001';
$customer_id = 'cust0001';
$mc = new MailchimpEcommerce();
$mc
->getCustomer($store_id, $customer_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/customers/' . $customer_id, $mc
->getClient()->uri);
}
public function testAddCustomer() {
$store_id = 'MC001';
$customer = [
'id' => 'cust0001',
'email_address' => 'freddie@freddiesjokes.com',
'opt_in_status' => TRUE,
];
$mc = new MailchimpEcommerce();
$mc
->addCustomer($store_id, $customer);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/customers', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($customer['id'], $request_body->id);
$this
->assertEquals($customer['email_address'], $request_body->email_address);
$this
->assertEquals($customer['opt_in_status'], $request_body->opt_in_status);
}
public function testUpdateCustomer() {
$store_id = 'MC001';
$customer = [
'id' => 'cust0001',
'email_address' => 'freddie@freddiesjokes.com',
'opt_in_status' => TRUE,
];
$mc = new MailchimpEcommerce();
$mc
->updateCustomer($store_id, $customer);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/customers/' . $customer['id'], $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($customer['id'], $request_body->id);
$this
->assertEquals($customer['email_address'], $request_body->email_address);
$this
->assertEquals($customer['opt_in_status'], $request_body->opt_in_status);
}
public function testDeleteCustomer() {
$store_id = 'MC001';
$customer_id = 'cust0003';
$mc = new MailchimpEcommerce();
$mc
->deleteCustomer($store_id, $customer_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndPoint() . '/ecommerce/stores/' . $store_id . '/customers/' . $customer_id, $mc
->getClient()->uri);
}
public function testGetOrders() {
$store_id = 'MC001';
$mc = new MailchimpEcommerce();
$mc
->getOrders($store_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders', $mc
->getClient()->uri);
}
public function testGetOrder() {
$store_id = 'MC001';
$order_id = 'ord0001';
$mc = new MailchimpEcommerce();
$mc
->getOrder($store_id, $order_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id, $mc
->getClient()->uri);
}
public function testAddOrder() {
$store_id = 'MC001';
$order_id = 'ord0001';
$customer = [
'id' => 'cust0005',
'email_address' => 'freddy@freddiesjokes.com',
'opt_in_status' => TRUE,
];
$order = [
'currency_code' => 'USD',
'order_total' => 12.45,
'lines' => [
'id' => 'LINE001',
'product_id' => 'PROD001',
'product_title' => "Freddie's Jokes",
'product_variant_id' => 'PROD001A',
'product_variant_title' => "Freddie's Jokes Volume 1",
'quantity' => 2,
'price' => 10,
],
];
$mc = new MailchimpEcommerce();
$mc
->addOrder($store_id, $order_id, $customer, $order);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($order_id, $request_body->id);
$this
->assertEquals($customer['id'], $request_body->customer->id);
$this
->assertEquals($customer['email_address'], $request_body->customer->email_address);
$this
->assertEquals($customer['opt_in_status'], $request_body->customer->opt_in_status);
$this
->assertEquals($order['currency_code'], $request_body->currency_code);
$this
->assertEquals($order['order_total'], $request_body->order_total);
$this
->assertEquals($order['lines'], $request_body->lines);
$this
->assertEquals($order['lines']['id'], $request_body->lines['id']);
$this
->assertEquals($order['lines']['product_id'], $request_body->lines['product_id']);
$this
->assertEquals($order['lines']['product_title'], $request_body->lines['product_title']);
$this
->assertEquals($order['lines']['product_variant_id'], $request_body->lines['product_variant_id']);
$this
->assertEquals($order['lines']['product_variant_title'], $request_body->lines['product_variant_title']);
$this
->assertEquals($order['lines']['quantity'], $request_body->lines['quantity']);
$this
->assertEquals($order['lines']['price'], $request_body->lines['price']);
}
public function testUpdateOrder() {
$store_id = 'MC001';
$order_id = 'ord0001';
$mc = new MailchimpEcommerce();
$mc
->updateOrder($store_id, $order_id);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id, $mc
->getClient()->uri);
}
public function testDeleteOrder() {
$store_id = 'MC002';
$order_id = 'ord0001';
$mc = new MailchimpEcommerce();
$mc
->deleteOrder($store_id, $order_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id, $mc
->getClient()->uri);
}
public function testGetOrderLines() {
$store_id = 'MC001';
$order_id = 'ord0001';
$mc = new MailchimpEcommerce();
$mc
->getOrderLines($store_id, $order_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndPoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id . '/lines', $mc
->getClient()->uri);
}
public function testGetOrderLine() {
$store_id = 'MC001';
$order_id = 'ord0001';
$line_id = 'L001';
$mc = new MailchimpEcommerce();
$mc
->getOrderLine($store_id, $order_id, $line_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndPoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id . '/lines/' . $line_id, $mc
->getClient()->uri);
}
public function testAddOrderLine() {
$store_id = 'MC001';
$order_id = 'ord0001';
$id = 'L002';
$product = [
'product_id' => 'PROD001',
'product_variant_id' => "Freddie's Jokes",
'quantity' => 1,
'price' => 5,
];
$mc = new MailchimpEcommerce();
$mc
->addOrderLine($store_id, $order_id, $id, $product);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id . '/lines', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($id, $request_body->id);
$this
->assertEquals($product['product_id'], $request_body->product_id);
$this
->assertEquals($product['product_variant_id'], $request_body->product_variant_id);
$this
->assertEquals($product['quantity'], $request_body->quantity);
$this
->assertEquals($product['price'], $request_body->price);
}
public function testsGetProducts() {
$store_id = 'MC001';
$mc = new MailchimpEcommerce();
$mc
->getProducts($store_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products', $mc
->getClient()->uri);
}
public function testGetProduct() {
$store_id = 'MC001';
$product_id = 'sku0001';
$mc = new MailchimpEcommerce();
$mc
->getProduct($store_id, $product_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id, $mc
->getClient()->uri);
}
public function testAddProduct() {
$store_id = 'MC001';
$id = 'sku0001';
$title = 'Test Product 001';
$url = 'http://example.org/';
$variant_1 = (object) [
'id' => 'PROD001A',
'title' => "Freddie's Jokes Volume 1",
];
$variants = [
$variant_1,
];
$mc = new MailchimpEcommerce();
$mc
->addProduct($store_id, $id, $title, $url, $variants);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($id, $request_body->id);
$this
->assertEquals($title, $request_body->title);
$this
->assertEquals($variant_1->id, $request_body->variants[0]->id);
$this
->assertEquals($variant_1->title, $request_body->variants[0]->title);
}
public function testUpdateProduct() {
$store_id = 'MC001';
$id = 'sku0001';
$variant_1 = (object) [
'id' => 'PROD001A',
'title' => "Freddie's Jokes Volume 1",
];
$variant_2 = (object) [
'id' => 'PROD002A',
'title' => "Freddie's Jokes Volume 2",
];
$variants = [
$variant_1,
$variant_2,
];
$mc = new MailchimpEcommerce();
$mc
->updateProduct($store_id, $id, $variants);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $id, $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($variant_1->id, $request_body->variants[0]->id);
$this
->assertEquals($variant_1->title, $request_body->variants[0]->title);
$this
->assertEquals($variant_2->id, $request_body->variants[1]->id);
$this
->assertEquals($variant_2->title, $request_body->variants[1]->title);
}
public function testDeleteProduct() {
$store_id = 'MC001';
$product_id = 'sku0001';
$mc = new MailchimpEcommerce();
$mc
->deleteProduct($store_id, $product_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id, $mc
->getClient()->uri);
}
public function testAddProductVariant() {
$store_id = 'MC001';
$product_id = 'sku0001';
$params = [
'id' => 'var001',
'title' => 'Var Title',
];
$mc = new MailchimpEcommerce();
$mc
->addProductVariant($store_id, $product_id, $params);
$this
->assertEquals('POST', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants', $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($params['id'], $request_body->id);
$this
->assertEquals($params['title'], $request_body->title);
}
public function testDeleteVariant() {
$store_id = 'MC001';
$product_id = 'sku0001';
$variant_id = 'var001';
$mc = new MailchimpEcommerce();
$mc
->deleteProductVariant($store_id, $product_id, $variant_id);
$this
->assertEquals('DELETE', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc
->getClient()->uri);
}
public function testGetVariant() {
$store_id = 'MC001';
$product_id = 'sku0001';
$variant_id = 'var001';
$mc = new MailchimpEcommerce();
$mc
->getProductVariant($store_id, $product_id, $variant_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc
->getClient()->uri);
}
public function testGetVariants() {
$store_id = 'MC001';
$product_id = 'sku0001';
$mc = new MailchimpEcommerce();
$mc
->getProductVariants($store_id, $product_id);
$this
->assertEquals('GET', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants', $mc
->getClient()->uri);
}
public function testUpdateVariant() {
$store_id = 'MC001';
$product_id = 'sku0001';
$variant_id = 'var001';
$params = [
'title' => 'New Title',
'url' => 'http://www.example.com',
'sku' => 'abc0042',
];
$mc = new MailchimpEcommerce();
$mc
->updateProductVariant($store_id, $product_id, $variant_id, $params);
$this
->assertEquals('PATCH', $mc
->getClient()->method);
$this
->assertEquals($mc
->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc
->getClient()->uri);
$this
->assertNotEmpty($mc
->getClient()->options['json']);
$request_body = $mc
->getClient()->options['json'];
$this
->assertEquals($params['url'], $request_body->url);
$this
->assertEquals($params['title'], $request_body->title);
$this
->assertEquals($params['sku'], $request_body->sku);
}
}