function ComponentMetadataTest::dataProviderMetadata

Same name in this branch
  1. 11.x core/modules/sdc/tests/src/Unit/ComponentMetadataTest.php \Drupal\Tests\sdc\Unit\ComponentMetadataTest::dataProviderMetadata()
Same name and namespace in other branches
  1. 10 core/modules/sdc/tests/src/Unit/ComponentMetadataTest.php \Drupal\Tests\sdc\Unit\ComponentMetadataTest::dataProviderMetadata()
  2. 10 core/tests/Drupal/Tests/Core/Theme/Component/ComponentMetadataTest.php \Drupal\Tests\Core\Theme\Component\ComponentMetadataTest::dataProviderMetadata()

Data provider for the test testMetadataEnforceSchema.

Return value

array[] The batches of data.

File

core/tests/Drupal/Tests/Core/Theme/Component/ComponentMetadataTest.php, line 55

Class

ComponentMetadataTest
Unit tests for the component metadata class.

Namespace

Drupal\Tests\Core\Theme\Component

Code

public static function dataProviderMetadata() : array {
  return [
    'minimal example without schemas' => [
      [
        'path' => 'foo/bar/component-name',
        'id' => 'core:component-name',
        'name' => 'Component Name',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'description' => 'My description',
      ],
      [
        'path' => 'bar/component-name',
        'status' => 'stable',
        'thumbnail' => '',
        'props' => NULL,
      ],
      TRUE,
    ],
    'complete example with schema, but no meta:enum' => [
      [
        '$schema' => 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
        'id' => 'core:my-button',
        'machineName' => 'my-button',
        'path' => 'foo/my-other/path',
        'name' => 'Button',
        'description' => 'JavaScript enhanced button that tracks the number of times a user clicked it.',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'properties' => [
            'text' => [
              'type' => 'string',
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => 'string',
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
            ],
          ],
        ],
      ],
      [
        'path' => 'my-other/path',
        'status' => 'stable',
        'thumbnail' => '',
        'group' => 'my-group',
        'additionalProperties' => FALSE,
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'additionalProperties' => FALSE,
          'properties' => [
            'text' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => new TranslatableMarkup('power', [], [
                  'context' => '',
                ]),
                'like' => new TranslatableMarkup('like', [], [
                  'context' => '',
                ]),
                'external' => new TranslatableMarkup('external', [], [
                  'context' => '',
                ]),
              ],
            ],
          ],
        ],
      ],
      FALSE,
    ],
    'complete example with schema, but no matching meta:enum' => [
      [
        '$schema' => 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
        'id' => 'core:my-button',
        'machineName' => 'my-button',
        'path' => 'foo/my-other/path',
        'name' => 'Button',
        'description' => 'JavaScript enhanced button that tracks the number of times a user clicked it.',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'properties' => [
            'text' => [
              'type' => 'string',
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => 'string',
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => 'Power',
                'fav' => 'Favorite',
                'external' => 'External',
              ],
            ],
          ],
        ],
      ],
      [
        'path' => 'my-other/path',
        'status' => 'stable',
        'thumbnail' => '',
        'group' => 'my-group',
        'additionalProperties' => FALSE,
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'additionalProperties' => FALSE,
          'properties' => [
            'text' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => new TranslatableMarkup('Power', [], [
                  'context' => '',
                ]),
                'like' => new TranslatableMarkup('like', [], [
                  'context' => '',
                ]),
                'external' => new TranslatableMarkup('External', [], [
                  'context' => '',
                ]),
              ],
            ],
          ],
        ],
      ],
      FALSE,
    ],
    'complete example with schema, but no meta:enum, prop value not as string' => [
      [
        '$schema' => 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
        'id' => 'core:my-button',
        'machineName' => 'my-button',
        'path' => 'foo/my-other/path',
        'name' => 'Button',
        'description' => 'JavaScript enhanced button that tracks the number of times a user clicked it.',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'properties' => [
            'col' => [
              'type' => 'string',
              'title' => 'Column',
              'enum' => [
                1,
                2,
                3,
              ],
            ],
          ],
        ],
      ],
      [
        'path' => 'my-other/path',
        'status' => 'stable',
        'thumbnail' => '',
        'group' => 'my-group',
        'additionalProperties' => FALSE,
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'additionalProperties' => FALSE,
          'properties' => [
            'col' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Column',
              'enum' => [
                1,
                2,
                3,
              ],
              'meta:enum' => [
                1 => new TranslatableMarkup('1', [], [
                  'context' => '',
                ]),
                2 => new TranslatableMarkup('2', [], [
                  'context' => '',
                ]),
                3 => new TranslatableMarkup('3', [], [
                  'context' => '',
                ]),
              ],
            ],
          ],
        ],
      ],
      FALSE,
    ],
    'complete example with schema (including meta:enum)' => [
      [
        '$schema' => 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
        'id' => 'core:my-button',
        'machineName' => 'my-button',
        'path' => 'foo/my-other/path',
        'name' => 'Button',
        'description' => 'JavaScript enhanced button that tracks the number of times a user clicked it.',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'properties' => [
            'text' => [
              'type' => 'string',
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => 'string',
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => 'Power',
                'like' => 'Like',
                'external' => 'External',
              ],
            ],
          ],
        ],
      ],
      [
        'path' => 'my-other/path',
        'status' => 'stable',
        'thumbnail' => '',
        'group' => 'my-group',
        'additionalProperties' => FALSE,
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'additionalProperties' => FALSE,
          'properties' => [
            'text' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => new TranslatableMarkup('Power', [], [
                  'context' => '',
                ]),
                'like' => new TranslatableMarkup('Like', [], [
                  'context' => '',
                ]),
                'external' => new TranslatableMarkup('External', [], [
                  'context' => '',
                ]),
              ],
            ],
          ],
        ],
      ],
      FALSE,
    ],
    'complete example with schema (including meta:enum and x-translation-context)' => [
      [
        '$schema' => 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
        'id' => 'core:my-button',
        'machineName' => 'my-button',
        'path' => 'foo/my-other/path',
        'name' => 'Button',
        'description' => 'JavaScript enhanced button that tracks the number of times a user clicked it.',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'properties' => [
            'text' => [
              'type' => 'string',
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => 'string',
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => 'Power',
                'like' => 'Like',
                'external' => 'External',
              ],
              'x-translation-context' => 'Icon Type',
            ],
          ],
        ],
      ],
      [
        'path' => 'my-other/path',
        'status' => 'stable',
        'thumbnail' => '',
        'group' => 'my-group',
        'additionalProperties' => FALSE,
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'additionalProperties' => FALSE,
          'properties' => [
            'text' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'iconType' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Icon Type',
              'enum' => [
                'power',
                'like',
                'external',
              ],
              'meta:enum' => [
                'power' => new TranslatableMarkup('Power', [], [
                  'context' => 'Icon Type',
                ]),
                'like' => new TranslatableMarkup('Like', [], [
                  'context' => 'Icon Type',
                ]),
                'external' => new TranslatableMarkup('External', [], [
                  'context' => 'Icon Type',
                ]),
              ],
              'x-translation-context' => 'Icon Type',
            ],
          ],
        ],
      ],
      FALSE,
    ],
    'complete example with schema (including meta:enum and x-translation-context and an empty value)' => [
      [
        '$schema' => 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
        'id' => 'core:my-button',
        'machineName' => 'my-button',
        'path' => 'foo/my-other/path',
        'name' => 'Button',
        'description' => 'JavaScript enhanced button that tracks the number of times a user clicked it.',
        'libraryOverrides' => [
          'dependencies' => [
            'core/drupal',
          ],
        ],
        'group' => 'my-group',
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'properties' => [
            'text' => [
              'type' => 'string',
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'target' => [
              'type' => 'string',
              'title' => 'Icon Type',
              'enum' => [
                '',
                '_blank',
              ],
              'meta:enum' => [
                '' => 'Opens in same window',
                '_blank' => 'Opens in new window',
              ],
              'x-translation-context' => 'Link target',
            ],
          ],
        ],
      ],
      [
        'path' => 'my-other/path',
        'status' => 'stable',
        'thumbnail' => '',
        'group' => 'my-group',
        'additionalProperties' => FALSE,
        'props' => [
          'type' => 'object',
          'required' => [
            'text',
          ],
          'additionalProperties' => FALSE,
          'properties' => [
            'text' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Title',
              'description' => 'The title for the button',
              'minLength' => 2,
              'examples' => [
                'Press',
                'Submit now',
              ],
            ],
            'target' => [
              'type' => [
                'string',
                'object',
              ],
              'title' => 'Icon Type',
              'enum' => [
                '',
                '_blank',
              ],
              'meta:enum' => [
                '' => new TranslatableMarkup('Opens in same window', [], [
                  'context' => 'Link target',
                ]),
                '_blank' => new TranslatableMarkup('Opens in new window', [], [
                  'context' => 'Link target',
                ]),
              ],
              'x-translation-context' => 'Link target',
            ],
          ],
        ],
      ],
      FALSE,
    ],
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.