You are here

protected function QueryStringWebformSourceEntityTest::getMockSourceEntity in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php \Drupal\Tests\webform\Unit\Plugin\WebformSourceEntity\QueryStringWebformSourceEntityTest::getMockSourceEntity()

Get mocked source entity.

Parameters

array $options: Mock source entity options.

\Drupal\webform\WebformInterface $webform: A mocked webform.

Return value

array An array containing a mocked source entity and its translated source entity.

1 call to QueryStringWebformSourceEntityTest::getMockSourceEntity()
QueryStringWebformSourceEntityTest::testGetCurrentSourceEntity in tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php
Tests detection of source entity via query string.

File

tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php, line 188

Class

QueryStringWebformSourceEntityTest
Tests the "query_string" webform source entity plugin.

Namespace

Drupal\Tests\webform\Unit\Plugin\WebformSourceEntity

Code

protected function getMockSourceEntity(array $options, WebformInterface $webform) {

  // Mock source entity.
  $source_entity = $this
    ->getMockBuilder(ContentEntityInterface::class)
    ->getMock();
  $source_entity
    ->method('access')
    ->willReturnMap([
    [
      'view',
      NULL,
      FALSE,
      $options['source_entity_view_access_result'],
    ],
  ]);
  $source_entity->webform_field_name = [
    (object) [
      'target_id' => $options['source_entity_has_webform_field'] && !$options['source_entity_has_translation'] ? $webform
        ->id() : 'other_webform',
    ],
  ];

  // Mock source entity translation.
  $source_entity_translation = $this
    ->getMockBuilder(ContentEntityInterface::class)
    ->getMock();
  $source_entity_translation
    ->method('access')
    ->willReturnMap([
    [
      'view',
      NULL,
      FALSE,
      $options['source_entity_view_access_result'],
    ],
  ]);
  $source_entity_translation->webform_field_name = [
    (object) [
      'target_id' => $options['source_entity_has_webform_field'] && $options['source_entity_has_translation'] ? $webform
        ->id() : 'other_webform',
    ],
  ];

  // Add translation to source entity.
  $source_entity
    ->method('hasTranslation')
    ->willReturnMap([
    [
      'es',
      $options['source_entity_has_translation'],
    ],
  ]);
  $source_entity
    ->method('getTranslation')
    ->willReturnMap([
    [
      'es',
      $source_entity_translation,
    ],
  ]);
  return [
    $source_entity,
    $source_entity_translation,
  ];
}