You are here

public function MailchimpEcommerceTest::testUpdateVariant in Mailchimp 8

Test updating a variant.

File

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

Class

MailchimpEcommerceTest
Mailchimp Ecommerce test library.

Namespace

Mailchimp\Tests

Code

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

  // Check method.
  $this
    ->assertEquals('PATCH', $mc
    ->getClient()->method);

  // Check URI being used.
  $this
    ->assertEquals($mc
    ->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc
    ->getClient()->uri);

  // Test the contents of the body of the request for the params.
  $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);
}