You are here

public function MachineNameTest::testMachineNames in Drupal 10

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

Tests machine name transformation of non-alphanumeric characters.

@dataProvider providerTestMachineNames

Parameters

string $human_name: The human-readable name that will be converted in the test.

array $configuration: The plugin configuration.

string $expected_result: The expected result of the transformation.

File

core/modules/migrate/tests/src/Unit/process/MachineNameTest.php, line 50

Class

MachineNameTest
Tests the machine name process plugin.

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function testMachineNames(string $human_name, array $configuration, string $expected_result) : void {

  // Test for calling transliterate on mock object.
  $this->transliteration
    ->expects($this
    ->once())
    ->method('transliterate')
    ->with($human_name)
    ->willReturnCallback(function (string $string) : string {
    return str_replace([
      'á',
      'é',
      'ő',
    ], [
      'a',
      'e',
      'o',
    ], $string);
  });
  $plugin = new MachineName($configuration, 'machine_name', [], $this->transliteration);
  $value = $plugin
    ->transform($human_name, $this->migrateExecutable, $this->row, 'destination_property');
  $this
    ->assertEquals($expected_result, $value);
}