You are here

TransliterationTest.php in Migrate Plus 8.4

Same filename and directory in other branches
  1. 8.5 tests/src/Unit/process/TransliterationTest.php

File

tests/src/Unit/process/TransliterationTest.php
View source
<?php

namespace Drupal\Tests\migrate_plus\Unit\process;

use Drupal\Component\Transliteration\PhpTransliteration;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate_plus\Plugin\migrate\process\Transliteration;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;

/**
 * Tests the transliteration process plugin.
 *
 * @group migrate_plus
 */
class TransliterationTest extends MigrateProcessTestCase {

  /**
   * A transliteration instance.
   *
   * @var \Drupal\Component\Transliteration\TransliterationInterface
   */
  protected $transliteration;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $this->transliteration = new PhpTransliteration();
    $this->row = $this
      ->getMockBuilder(Row::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->migrateExecutable = $this
      ->getMockBuilder(MigrateExecutableInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    parent::setUp();
  }

  /**
   * Tests transliteration transformation of non-alphanumeric characters.
   */
  public function testTransform() {
    $actual = '9000004351_53494854_Spøgelsesjægerneáéö';
    $expected_result = '9000004351_53494854_Spogelsesjaegerneaeo';
    $plugin = new Transliteration([], 'transliteration', [], $this->transliteration);
    $value = $plugin
      ->transform($actual, $this->migrateExecutable, $this->row, 'destinationproperty');
    $this
      ->assertEquals($expected_result, $value);
  }

}

Classes

Namesort descending Description
TransliterationTest Tests the transliteration process plugin.