You are here

public function TestMapper::testSetFieldsInCommon in Feeds Paragraphs 8

@covers ::setFieldsInCommon

File

tests/src/Unit/TestMapper.php, line 137

Class

TestMapper
@group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\Mapper

Namespace

Drupal\Tests\feeds_para_mapper\Unit

Code

public function testSetFieldsInCommon() {
  $conf = new FieldConfig('Bundle two field two', 'bundle_two_field_two', 'text', 4, 1, array(
    'handler_settings' => array(),
  ), array(), 'paragraph', 'bundle_two', 'bundle_one_bundle_two', 3);
  $path = array(
    array(
      'bundle' => 'bundle_one',
      'host_field' => 'paragraph_field',
      'host_entity' => 'node',
      'order' => 0,
    ),
  );
  $firstTargetInfo = $this
    ->getTargetInfo();
  $firstTargetInfo->path = $path;
  $secondTargetInfo = $this
    ->getTargetInfo();
  $secondTargetInfo->path = $path;
  $field = $this->fieldHelper
    ->getBundleFields('bundle_two')[0]
    ->reveal();
  $field
    ->set('target_info', $firstTargetInfo);
  $second_field = $this->fieldHelper
    ->getField($conf)
    ->reveal();
  $second_field
    ->set('target_info', $secondTargetInfo);
  $fields = array(
    $second_field,
  );
  $method = $this
    ->getMethod(Mapper::class, 'setFieldsInCommon');
  $method
    ->invokeArgs($this->mapper, array(
    &$field,
    &$fields,
  ));
  $inCommonExists = count($firstTargetInfo->in_common) && count($secondTargetInfo->in_common);
  $message = "in common field are added for both fields";
  self::assertTrue($inCommonExists, $message);
  $first_field_name = $field
    ->getName();
  $second_field_name = $second_field
    ->getName();
  $field_two_has_one = $secondTargetInfo->in_common[0]['name'] === $first_field_name;
  self::assertTrue($field_two_has_one, "First field has the second in common");
  $field_one_has_two = $firstTargetInfo->in_common[0]['name'] === $second_field_name;
  self::assertTrue($field_one_has_two, "Second field has the first in common");
}