You are here

public function CartAddResourceTest::testInvalidPurchasedEntity in Commerce Cart API 8

Tests invalid purchased entity.

File

tests/src/Functional/CartAddResourceTest.php, line 58

Class

CartAddResourceTest
Tests the cart add resource.

Namespace

Drupal\Tests\commerce_cart_api\Functional

Code

public function testInvalidPurchasedEntity() {
  $url = Url::fromUri('base:cart/add');
  $url
    ->setOption('query', [
    '_format' => static::$format,
  ]);
  $request_options = $this
    ->getAuthenticationRequestOptions('POST');
  $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;

  // Add item when no cart exists.
  $request_options[RequestOptions::BODY] = '[{ "purchased_entity_type": "commerce_product_variation", "purchased_entity_id": "99", "quantity": "1"}]';
  $response = $this
    ->request('POST', $url, $request_options);
  $this
    ->assertResourceResponse(200, FALSE, $response);
  $response_body = Json::decode((string) $response
    ->getBody());
  $this
    ->assertEmpty($response_body);
}