You are here

public function EntityReferenceFieldNormalizerTest::normalizeProvider in JSON:API 8.2

Data provider for testNormalize.

File

tests/src/Kernel/Normalizer/EntityReferenceFieldNormalizerTest.php, line 189

Class

EntityReferenceFieldNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\EntityReferenceFieldNormalizer @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function normalizeProvider() {
  return [
    'single cardinality' => [
      [
        'user1',
      ],
      'field_user',
      [
        'data' => [
          'type' => 'user--user',
          'id' => static::$userIds[0],
        ],
      ],
    ],
    'multiple cardinality' => [
      [
        'user1',
        'user2',
      ],
      'field_users',
      [
        'data' => [
          [
            'type' => 'user--user',
            'id' => static::$userIds[0],
          ],
          [
            'type' => 'user--user',
            'id' => static::$userIds[1],
          ],
        ],
      ],
    ],
    'multiple cardinality, all same values' => [
      [
        'user1',
        'user1',
      ],
      'field_users',
      [
        'data' => [
          [
            'type' => 'user--user',
            'id' => static::$userIds[0],
            'meta' => [
              'arity' => 0,
            ],
          ],
          [
            'type' => 'user--user',
            'id' => static::$userIds[0],
            'meta' => [
              'arity' => 1,
            ],
          ],
        ],
      ],
    ],
    'multiple cardinality, some same values' => [
      [
        'user1',
        'user2',
        'user1',
      ],
      'field_users',
      [
        'data' => [
          [
            'type' => 'user--user',
            'id' => static::$userIds[0],
            'meta' => [
              'arity' => 0,
            ],
          ],
          [
            'type' => 'user--user',
            'id' => static::$userIds[1],
          ],
          [
            'type' => 'user--user',
            'id' => static::$userIds[0],
            'meta' => [
              'arity' => 1,
            ],
          ],
        ],
      ],
    ],
    'single cardinality, with meta' => [
      [
        'image1',
      ],
      'field_image',
      [
        'data' => [
          'type' => 'file--file',
          'id' => static::$imageIds[0],
          'meta' => [
            'alt' => 'Cute llama',
            'title' => 'My spirit animal',
            'width' => NULL,
            'height' => NULL,
          ],
        ],
      ],
    ],
    'multiple cardinality, all same values, with meta' => [
      [
        'image1',
        'image1',
      ],
      'field_images',
      [
        'data' => [
          [
            'type' => 'file--file',
            'id' => static::$imageIds[0],
            'meta' => [
              'alt' => 'Cute llama',
              'title' => 'My spirit animal',
              'width' => NULL,
              'height' => NULL,
              'arity' => 0,
            ],
          ],
          [
            'type' => 'file--file',
            'id' => static::$imageIds[0],
            'meta' => [
              'alt' => 'Cute llama',
              'title' => 'My spirit animal',
              'width' => NULL,
              'height' => NULL,
              'arity' => 1,
            ],
          ],
        ],
      ],
    ],
    'multiple cardinality, some same values with same values but different meta' => [
      [
        'image1',
        'image1',
        'image1a',
      ],
      'field_images',
      [
        'data' => [
          [
            'type' => 'file--file',
            'id' => static::$imageIds[0],
            'meta' => [
              'alt' => 'Cute llama',
              'title' => 'My spirit animal',
              'width' => NULL,
              'height' => NULL,
              'arity' => 0,
            ],
          ],
          [
            'type' => 'file--file',
            'id' => static::$imageIds[0],
            'meta' => [
              'alt' => 'Cute llama',
              'title' => 'My spirit animal',
              'width' => NULL,
              'height' => NULL,
              'arity' => 1,
            ],
          ],
          [
            'type' => 'file--file',
            'id' => static::$imageIds[0],
            'meta' => [
              'alt' => 'Ugly llama',
              'title' => 'My alter ego',
              'width' => NULL,
              'height' => NULL,
              'arity' => 2,
            ],
          ],
        ],
      ],
    ],
  ];
}