You are here

public function CartAddResourceSelectStoreExceptionTest::testNotCurrentStoreException in Commerce Cart API 8

Tests exception when product's stores is not a current store.

File

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

Class

CartAddResourceSelectStoreExceptionTest
@group commerce_cart_api

Namespace

Drupal\Tests\commerce_cart_api\Kernel

Code

public function testNotCurrentStoreException() {
  $additional_store1 = $this
    ->createStore();
  $addiitonal_store2 = $this
    ->createStore();

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

  /** @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 can't be purchased from the current store.");
  $controller = $this
    ->getController();
  $controller
    ->post([
    [
      'purchased_entity_type' => 'commerce_product_variation',
      'purchased_entity_id' => $product_variation
        ->id(),
      'quantity' => 1,
    ],
  ], $request
    ->reveal());
}