You are here

public function CartAddResourceSelectStoreExceptionTest::testNoStoresException in Commerce Cart API 8

Tests exception when product has no stores.

File

tests/src/Kernel/CartAddResourceSelectStoreExceptionTest.php, line 48

Class

CartAddResourceSelectStoreExceptionTest
@group commerce_cart_api

Namespace

Drupal\Tests\commerce_cart_api\Kernel

Code

public function testNoStoresException() {

  /** @var \Drupal\commerce_product\Entity\Product $product */
  $product = Product::create([
    'type' => 'default',
  ]);

  /** @var \Drupal\commerce_product\Entity\ProductVariation $product_variation */
  $product_variation = ProductVariation::create([
    'type' => 'default',
  ]);
  $product_variation
    ->save();
  $product
    ->addVariation($product_variation);
  $product
    ->save();
  $request = $this
    ->prophesize(Request::class);
  $this
    ->expectException(UnprocessableEntityHttpException::class);
  $this
    ->expectExceptionMessage('The given entity is not assigned to any store.');
  $controller = $this
    ->getController();
  $controller
    ->post([
    [
      'purchased_entity_type' => 'commerce_product_variation',
      'purchased_entity_id' => $product_variation
        ->id(),
      'quantity' => 1,
    ],
  ], $request
    ->reveal());
}