function MakeUniqueEntityFieldTest::testMakeUniqueEntityField

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php \Drupal\Tests\migrate\Unit\process\MakeUniqueEntityFieldTest::testMakeUniqueEntityField()
  2. 8.9.x core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php \Drupal\Tests\migrate\Unit\process\MakeUniqueEntityFieldTest::testMakeUniqueEntityField()
  3. 11.x 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 69

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) : void {
    $configuration = [
        'entity_type' => 'test_entity_type',
        'field' => 'test_field',
    ];
    if ($postfix) {
        $configuration['postfix'] = $postfix;
    }
    $configuration['start'] = $start;
    $configuration['length'] = $length;
    $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, 'foo');
    $expected = mb_substr($value, $start ?? 0, $length);
    $expected .= $count ? $postfix . $count : '';
    $this->assertSame($expected, $actual);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.