You are here

public function CartUpdateItemResourceTest::testMissingOrderItem in Commerce Cart API 8

Tests patch when order item does not exist in cart.

File

tests/src/Functional/CartUpdateItemResourceTest.php, line 49

Class

CartUpdateItemResourceTest
Tests the cart update items resource.

Namespace

Drupal\Tests\commerce_cart_api\Functional

Code

public function testMissingOrderItem() {
  $request_options = $this
    ->getAuthenticationRequestOptions('PATCH');
  $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
  $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"}';
  $response = $this
    ->request('PATCH', $url, $request_options);
  $this
    ->assertResourceErrorResponse(404, FALSE, $response);

  // Create order item in another cart.
  $another_cart = $this->cartProvider
    ->createCart('default', $this->store);
  $this->cartManager
    ->addEntity($another_cart, $this->variation, 2);

  // New order item should still be unavailable for patch.

  /* Bug here?
     $response = $this->request('PATCH', $url, $request_options);
     $this->assertResourceErrorResponse(404, FALSE, $response);
      */
}