You are here

protected function ConditionalFieldControllerTest::setUp in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 tests/src/Unit/ConditionalFieldControllerTest.php \Drupal\Tests\conditional_fields\Unit\ConditionalFieldControllerTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/ConditionalFieldControllerTest.php, line 33

Class

ConditionalFieldControllerTest
ConditionalFieldController units tests.

Namespace

Drupal\Tests\conditional_fields\Unit

Code

protected function setUp() {
  parent::setUp();
  $entity_types = [];

  // `content_a` should appear in test results.
  $entity_types['content_a'] = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityType')
    ->disableOriginalConstructor()
    ->getMock();
  $entity_types['content_a']
    ->expects($this
    ->any())
    ->method('getLabel')
    ->will($this
    ->returnValue("contentA"));

  // `content_b` shouldn't appear in test results.
  $entity_types['content_b'] = $this
    ->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
  $entity_types['content_b']
    ->expects($this
    ->any())
    ->method('getLabel')
    ->will($this
    ->returnValue("contentB"));

  // Setup Drupal Container.
  $entity_type_manager = $this
    ->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $entity_type_manager
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue($entity_types));

  // For only one test case this classes not used,
  // change this after adding new test cases.
  $form_builder = $this
    ->createMock('Drupal\\Core\\Form\\FormBuilderInterface');
  $form_builder
    ->expects($this
    ->never())
    ->method($this
    ->anything());
  $entity_type_bundle_info = $this
    ->createMock('Drupal\\Core\\Entity\\EntityTypeBundleInfoInterface');
  $entity_type_bundle_info
    ->expects($this
    ->never())
    ->method($this
    ->anything());
  $entity_field_manager = $this
    ->createMock('Drupal\\Core\\Entity\\EntityFieldManagerInterface');
  $entity_field_manager
    ->expects($this
    ->never())
    ->method($this
    ->anything());

  // ConditionalFieldController::create();
  $this->controller = new ConditionalFieldController($entity_type_manager, $form_builder, $entity_type_bundle_info, $entity_field_manager);
}