You are here

public function CartHandlerTest::testAddOrUpdateCart in Mailchimp E-Commerce 8

@covers ::addOrUpdateCart

File

tests/src/Unit/CartHandlerTest.php, line 100

Class

CartHandlerTest
Tests cart handler methods.

Namespace

Drupal\Tests\mailchimp_ecommerce\Unit

Code

public function testAddOrUpdateCart() {

  // Test update case.
  $this->helper
    ->method('getStoreId')
    ->willReturn('my_store');
  $this->helper
    ->method('validateCustomer')
    ->willReturn(TRUE);
  $this->helper
    ->method('getCampaignId')
    ->willReturn(FALSE);
  $cart = new \stdClass();
  $cart->foo = 'bar';
  $this->mcEcommerce
    ->expects($this
    ->at(0))
    ->method('getCart')
    ->willReturn($cart);
  $this->mcEcommerce
    ->expects($this
    ->once())
    ->method('updateCart');
  $this->handler
    ->addOrUpdateCart('my_cart', [], []);

  // Test add case.
  $exception = new \Exception('', 404);
  $this->mcEcommerce
    ->expects($this
    ->at(0))
    ->method('getCart')
    ->will($this
    ->throwException($exception));
  $this->mcEcommerce
    ->expects($this
    ->once())
    ->method('addCart');
  $this->handler
    ->addOrUpdateCart('my_cart', [], []);
}