You are here

public function MailchimpEcommerceTest::testUpdateProduct in Mailchimp 8

Test updating a product.

File

lib/mailchimp-api-php/tests/MailchimpEcommerceTest.php, line 617

Class

MailchimpEcommerceTest
Mailchimp Ecommerce test library.

Namespace

Mailchimp\Tests

Code

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);
}