You are here

public function RelationshipNormalizerTest::normalizeProvider in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/Normalizer/RelationshipNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\RelationshipNormalizerTest::normalizeProvider()

Data provider for testNormalize.

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/RelationshipNormalizerTest.php, line 189

Class

RelationshipNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\RelationshipNormalizer @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,
            ],
          ],
        ],
      ],
    ],
  ];
}