You are here

public function MakeUniqueEntityFieldTest::testMakeUniqueEntityField in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php \Drupal\Tests\migrate\Unit\process\MakeUniqueEntityFieldTest::testMakeUniqueEntityField()
  2. 10 core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php \Drupal\Tests\migrate\Unit\process\MakeUniqueEntityFieldTest::testMakeUniqueEntityField()

Tests making an entity field value unique.

@dataProvider providerTestMakeUniqueEntityField

File

core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php, line 64

Class

MakeUniqueEntityFieldTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField @group migrate

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function testMakeUniqueEntityField($count, $postfix = '', $start = NULL, $length = NULL) {
  $configuration = [
    'entity_type' => 'test_entity_type',
    'field' => 'test_field',
  ];
  if ($postfix) {
    $configuration['postfix'] = $postfix;
  }
  $configuration['start'] = isset($start) ? $start : NULL;
  $configuration['length'] = isset($length) ? $length : NULL;
  $plugin = new MakeUniqueEntityField($configuration, 'make_unique', [], $this
    ->getMigration(), $this->entityTypeManager);
  $this
    ->entityQueryExpects($count);
  $value = $this
    ->randomMachineName(32);
  $actual = $plugin
    ->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
  $expected = mb_substr($value, $start, $length);
  $expected .= $count ? $postfix . $count : '';
  $this
    ->assertSame($expected, $actual);
}