public function MailchimpEcommerceTest::testAddCart in Mailchimp 8
Tests library function for adding a new cart.
File
- lib/
mailchimp-api-php/ tests/ MailchimpEcommerceTest.php, line 130
Class
- MailchimpEcommerceTest
- Mailchimp Ecommerce test library.
Namespace
Mailchimp\TestsCode
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']);
}