You are here

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

@covers ::getCart @covers ::cartExists

File

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

Class

CartHandlerTest
Tests cart handler methods.

Namespace

Drupal\Tests\mailchimp_ecommerce\Unit

Code

public function testGetCart() {

  // Test positive case.
  $this->helper
    ->expects($this
    ->at(0))
    ->method('getStoreId')
    ->willReturn('my_store');
  $cart = new \stdClass();
  $cart->foo = 'bar';
  $this->mcEcommerce
    ->expects($this
    ->at(0))
    ->method('getCart')
    ->willReturn($cart);
  $this
    ->assertTrue($this->handler
    ->cartExists('my_cart'));

  // Test negative case.
  $this->helper
    ->expects($this
    ->at(0))
    ->method('getStoreId')
    ->willReturn('my_store');
  $this->mcEcommerce
    ->expects($this
    ->at(0))
    ->method('getCart')
    ->willReturn(NULL);
  $this
    ->assertFalse($this->handler
    ->cartExists('my_cart'));

  // Test error handling.
  $this->helper
    ->expects($this
    ->at(0))
    ->method('getStoreId')
    ->willReturn('');
  $this->handler
    ->cartExists('my_cart');
  $this
    ->assertContains('Cannot get the requested cart without a store ID.', $this->errors);
}