You are here

protected function SchemaFormBuilderTest::getMockSchemaFormBuilder 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::getMockSchemaFormBuilder()

Get a mock schema manager which will always serve a specified definition.

1 call to SchemaFormBuilderTest::getMockSchemaFormBuilder()
SchemaFormBuilderTest::testSchemaFormBuilder in tests/src/Unit/SchemaFormBuilderTest.php
Test that the schema form builder works.

File

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

Class

SchemaFormBuilderTest
Test that the schema form builder works.

Namespace

Drupal\Tests\migrate_api\Unit

Code

protected function getMockSchemaFormBuilder($definition) {
  $data = $this
    ->createMock('Drupal\\Core\\TypedData\\TraversableTypedDataInterface');
  $data
    ->method('getDataDefinition')
    ->willReturn($definition);
  $manager = $this
    ->createMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
  $manager
    ->method('get')
    ->willReturn($data);
  $form_builder = $this
    ->getMockBuilder('Drupal\\migrate_api\\SchemaFormBuilder');
  $form_builder
    ->setConstructorArgs([
    $manager,
  ]);
  $form_builder
    ->addMethods([
    'uniqueAjaxId',
    't',
  ]);
  $form_builder_mock = $form_builder
    ->getMock();
  $form_builder_mock
    ->method('uniqueAjaxId')
    ->willReturn('ajax_id');
  $form_builder_mock
    ->method('t')
    ->willReturnCallback(function ($string) {
    return $string;
  });
  return $form_builder_mock;
}