You are here

public function TranslationCartAddResourceTest::testProperTranslatedPurchasedEntityAdded in Commerce Cart API 8

Asserts the proper translation used based on langcode path prefix.

File

tests/src/Functional/TranslationCartAddResourceTest.php, line 101

Class

TranslationCartAddResourceTest
Tests the cart add resource.

Namespace

Drupal\Tests\commerce_cart_api\Functional

Code

public function testProperTranslatedPurchasedEntityAdded() {
  $url = Url::fromUri('base:fr/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": "1", "quantity": "1"}]';
  $response = $this
    ->request('POST', $url, $request_options);
  $this
    ->assertResourceResponse(200, FALSE, $response);
  $response_body = Json::decode((string) $response
    ->getBody());
  $this
    ->assertEquals(count($response_body), 1);
  $this
    ->assertEquals(count($response_body), 1);
  $this
    ->assertEquals(1, $response_body[0]['order_item_id']);
  $this
    ->assertEquals(1, $response_body[0]['purchased_entity']['variation_id']);
  $this
    ->assertEquals('Mon super produit', $response_body[0]['purchased_entity']['title']);
  $this
    ->assertEquals(1, $response_body[0]['quantity']);
  $this
    ->assertEquals(1000, $response_body[0]['unit_price']['number']);
  $this
    ->assertEquals('USD', $response_body[0]['unit_price']['currency_code']);
  $this
    ->assertEquals(1000, $response_body[0]['total_price']['number']);
  $this
    ->assertEquals('USD', $response_body[0]['total_price']['currency_code']);
}