You are here

public function SchemaFormBuilderTest::schemaDefinitionsWithExpectedForms in Migrate API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/SchemaFormBuilderTest.php \Drupal\Tests\migrate_api\Unit\SchemaFormBuilderTest::schemaDefinitionsWithExpectedForms()

A data provider containing schema definitions and forms.

Return value

array An array of test cases.

File

tests/src/Unit/SchemaFormBuilderTest.php, line 25
Contains Drupal\Tests\migrate_api\Unit\SchemaFormBuilderTest.

Class

SchemaFormBuilderTest
Test that the schema form builder works.

Namespace

Drupal\Tests\migrate_api\Unit

Code

public function schemaDefinitionsWithExpectedForms() {
  return [
    'Simple element' => [
      [
        'type' => 'product',
        'mapping' => [
          'title' => [
            'label' => 'Product Title',
            'type' => 'string',
          ],
        ],
      ],
      [
        'title' => [
          '#title' => 'Product Title',
          '#type' => 'textfield',
        ],
      ],
    ],
    'Nested mappings' => [
      [
        'type' => 'product',
        'mapping' => [
          'pricing' => [
            'label' => 'Pricing',
            'type' => 'mapping',
            'mapping' => [
              'price' => [
                'label' => 'Price',
                'type' => 'integer',
              ],
              'currency' => [
                'label' => 'Currency',
                'type' => 'string',
              ],
            ],
          ],
        ],
      ],
      [
        'pricing' => [
          '#title' => 'Pricing',
          '#type' => 'fieldset',
          'price' => [
            '#title' => 'Price',
            '#type' => 'number',
          ],
          'currency' => [
            '#title' => 'Currency',
            '#type' => 'textfield',
          ],
        ],
      ],
    ],
    'Simple sequence' => [
      [
        'type' => 'product',
        'label' => 'Product',
        'mapping' => [
          'reviews' => [
            'type' => 'sequence',
            'label' => 'Reviews',
            'sequence' => [
              'type' => 'string',
              'label' => 'Review',
            ],
          ],
        ],
      ],
      [
        'reviews' => [
          '#type' => 'fieldset',
          '#title' => 'Reviews',
          '0' => [
            '#type' => 'textfield',
            '#title' => 'Review',
          ],
          'add' => [
            '#type' => 'submit',
            '#value' => 'Add another',
            '#name' => 'ajax_id',
            '#submit' => [
              [
                'class',
                'sequenceHandlerSubmit',
              ],
            ],
            '#ajax' => [
              'callback' => [
                'class',
                'sequenceHandlerAjax',
              ],
              'wrapper' => 'ajax_id',
            ],
          ],
          '#prefix' => '<div id="ajax_id">',
          '#suffix' => '</div>',
        ],
      ],
    ],
    'Mapping and nested sequence' => [
      [
        'type' => 'product',
        'label' => 'Product',
        'mapping' => [
          'reviews' => [
            'type' => 'sequence',
            'label' => 'Reviews',
            'sequence' => [
              'label' => 'Review',
              'type' => 'mapping',
              'mapping' => [
                'name' => [
                  'type' => 'string',
                  'label' => 'Username',
                ],
                'rating' => [
                  'label' => 'Rating',
                  'type' => 'integer',
                ],
                'comments' => [
                  'type' => 'sequence',
                  'label' => 'Comments',
                  'sequence' => [
                    'type' => 'string',
                    'label' => 'Comment',
                  ],
                ],
              ],
            ],
          ],
        ],
      ],
      [
        'reviews' => [
          '#type' => 'fieldset',
          '#title' => 'Reviews',
          '0' => [
            '#title' => 'Review',
            '#type' => 'fieldset',
            'name' => [
              '#title' => 'Username',
              '#type' => 'textfield',
            ],
            'rating' => [
              '#title' => 'Rating',
              '#type' => 'number',
            ],
            'comments' => [
              '#type' => 'fieldset',
              '#title' => 'Comments',
              '0' => [
                '#title' => 'Comment',
                '#type' => 'textfield',
              ],
              'add' => [
                '#type' => 'submit',
                '#value' => 'Add another',
                '#name' => 'ajax_id',
                '#submit' => [
                  [
                    'class',
                    'sequenceHandlerSubmit',
                  ],
                ],
                '#ajax' => [
                  'callback' => [
                    'class',
                    'sequenceHandlerAjax',
                  ],
                  'wrapper' => 'ajax_id',
                ],
              ],
              '#prefix' => '<div id="ajax_id">',
              '#suffix' => '</div>',
            ],
          ],
          'add' => [
            '#type' => 'submit',
            '#value' => 'Add another',
            '#name' => 'ajax_id',
            '#submit' => [
              [
                'class',
                'sequenceHandlerSubmit',
              ],
            ],
            '#ajax' => [
              'callback' => [
                'class',
                'sequenceHandlerAjax',
              ],
              'wrapper' => 'ajax_id',
            ],
          ],
          '#prefix' => '<div id="ajax_id">',
          '#suffix' => '</div>',
        ],
      ],
    ],
  ];
}