You are here

protected function EntityReferenceNormalizerTest::assertEntityReferenceNormalization in Commerce Cart API 8

Tests the field overrides and keys to check.

@note This was the test method using a data provider, but the setUp method is only called once per test method and not again for each test data.

4 calls to EntityReferenceNormalizerTest::assertEntityReferenceNormalization()
EntityReferenceNormalizerTest::testDefaults in tests/src/Kernel/Normalizer/EntityReferenceNormalizerTest.php
Tests default configuration.
EntityReferenceNormalizerTest::testWithAttributeColor in tests/src/Kernel/Normalizer/EntityReferenceNormalizerTest.php
Tests adding attribute color.
EntityReferenceNormalizerTest::testWithProductId in tests/src/Kernel/Normalizer/EntityReferenceNormalizerTest.php
Tests adding product ID
EntityReferenceNormalizerTest::testWithProductIdAttributeColor in tests/src/Kernel/Normalizer/EntityReferenceNormalizerTest.php
Tests adding product ID and attribute color.

File

tests/src/Kernel/Normalizer/EntityReferenceNormalizerTest.php, line 223

Class

EntityReferenceNormalizerTest
@group commerce_cart_api

Namespace

Drupal\Tests\commerce_cart_api\Kernel\Normalizer

Code

protected function assertEntityReferenceNormalization(array $field_overrides, array $keys_exists, array $keys_not_exist) {
  $params = $this->container
    ->getParameter('commerce_cart_api');
  if ($field_overrides === []) {
    $field_overrides = [
      'order_items',
      'purchased_entity',
    ];
  }
  $this
    ->assertEquals($field_overrides, $params['normalized_entity_references']);
  $serializer = $this->container
    ->get('serializer');
  $data = $serializer
    ->normalize($this->order, 'json');
  foreach ($keys_exists as $parents) {
    $this
      ->assertTrue(NestedArray::keyExists($data, $parents), sprintf('Parent keys %s not found.', implode('.', $parents)));
  }
  foreach ($keys_not_exist as $parents) {
    $this
      ->assertFalse(NestedArray::keyExists($data, $parents), sprintf('Parent keys %s should not be found.', implode('.', $parents)));
  }
}