You are here

public function CartAccessApiResourceTest::testInvalidOrderItemCart in Commerce Cart API 8

Check no access for order item not in cart (cart update item);

File

tests/src/Functional/CartAccessApiResourceTest.php, line 128

Class

CartAccessApiResourceTest
Tests cart api access check.

Namespace

Drupal\Tests\commerce_cart_api\Functional

Code

public function testInvalidOrderItemCart() {
  $request_options = $this
    ->getAuthenticationRequestOptions('PATCH');
  $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;

  // Create a cart with an order item.
  $cart = $this->cartProvider
    ->createCart('default', $this->store, $this->account);
  $this->cartManager
    ->addEntity($cart, $this->variation, 2);
  $url = Url::fromUri('base:cart/' . $cart
    ->id() . '/items/2');
  $url
    ->setOption('query', [
    '_format' => static::$format,
  ]);
  $request_options[RequestOptions::BODY] = '{"quantity":"1"}';

  // Create order item in another cart.
  $another_cart = $this->cartProvider
    ->createCart('default', $this->store);
  $this->cartManager
    ->addEntity($another_cart, $this->variation, 2);
  $response = $this
    ->request('PATCH', $url, $request_options);
  $this
    ->assertResourceErrorResponse(403, '', $response);
}