3 namespace Drupal\Tests\migrate\Unit\process;
5 use Drupal\migrate\Plugin\migrate\process\MachineName;
8 * Tests the machine name process plugin.
12 class MachineNameTest extends MigrateProcessTestCase {
15 * The mock transliteration.
17 * @var \Drupal\Component\Transliteration\TransliterationInterface
19 protected $transliteration;
24 protected function setUp() {
25 $this->transliteration = $this->getMockBuilder('Drupal\Component\Transliteration\TransliterationInterface')
26 ->disableOriginalConstructor()
28 $this->row = $this->getMockBuilder('Drupal\migrate\Row')
29 ->disableOriginalConstructor()
31 $this->migrateExecutable = $this->getMockBuilder('Drupal\migrate\MigrateExecutable')
32 ->disableOriginalConstructor()
38 * Tests machine name transformation of non-alphanumeric characters.
40 public function testMachineNames() {
42 // Tests the following transformations:
43 // - non-alphanumeric character (including spaces) -> underscore,
44 // - Uppercase -> lowercase,
45 // - Multiple consecutive underscore -> single underscore.
46 $human_name_ascii = 'foo2, the.bar;2*&the%baz!YEE____HaW ';
47 $human_name = $human_name_ascii . 'áéő';
48 $expected_result = 'foo2_the_bar_2_the_baz_yee_haw_aeo';
49 // Test for calling transliterate on mock object.
50 $this->transliteration
51 ->expects($this->once())
52 ->method('transliterate')
54 ->will($this->returnValue($human_name_ascii . 'aeo'));
56 $plugin = new MachineName([], 'machine_name', [], $this->transliteration);
57 $value = $plugin->transform($human_name, $this->migrateExecutable, $this->row, 'destinationproperty');
58 $this->assertEquals($expected_result, $value);