public function CartCacheContextTest::testCartCacheContext in Commerce Core 8.2
Tests commerce 'cart' cache context.
File
- modules/
cart/ tests/ src/ Unit/ CartCacheContextTest.php, line 20
Class
- CartCacheContextTest
- @coversDefaultClass \Drupal\commerce_cart\Cache\Context\CartCacheContext @group commerce
Namespace
Drupal\Tests\commerce_cart\UnitCode
public function testCartCacheContext() {
$account = $this
->createMock(AccountInterface::class);
$cartProvider = $this
->createMock(CartProviderInterface::class);
$cartProvider
->expects($this
->once())
->method('getCartIds')
->willReturn([
'23',
'34',
]);
$cartProvider
->expects($this
->once())
->method('getCarts')
->willReturn([
new TestCacheableDependency([], [
'commerce_cart:23',
], 0),
new TestCacheableDependency([], [
'commerce_cart:24',
], 0),
]);
$cartCache = new CartCacheContext($account, $cartProvider);
$this
->assertEquals('23:34', $cartCache
->getContext());
$this
->assertEquals([
'commerce_cart:23',
'commerce_cart:24',
], $cartCache
->getCacheableMetadata()
->getCacheTags());
}