Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / MachineNameTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
5 use Drupal\migrate\Plugin\migrate\process\MachineName;
6
7 /**
8  * Tests the machine name process plugin.
9  *
10  * @group migrate
11  */
12 class MachineNameTest extends MigrateProcessTestCase {
13
14   /**
15    * The mock transliteration.
16    *
17    * @var \Drupal\Component\Transliteration\TransliterationInterface
18    */
19   protected $transliteration;
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     $this->transliteration = $this->getMockBuilder('Drupal\Component\Transliteration\TransliterationInterface')
26       ->disableOriginalConstructor()
27       ->getMock();
28     $this->row = $this->getMockBuilder('Drupal\migrate\Row')
29       ->disableOriginalConstructor()
30       ->getMock();
31     $this->migrateExecutable = $this->getMockBuilder('Drupal\migrate\MigrateExecutable')
32       ->disableOriginalConstructor()
33       ->getMock();
34     parent::setUp();
35   }
36
37   /**
38    * Tests machine name transformation of non-alphanumeric characters.
39    */
40   public function testMachineNames() {
41
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')
53       ->with($human_name)
54       ->will($this->returnValue($human_name_ascii . 'aeo'));
55
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);
59   }
60
61 }