LanguageTypesTest.php 1.78 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Drupal\Tests\language\Unit\process;

use Drupal\language\Plugin\migrate\process\LanguageTypes;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
7
use Drupal\migrate\MigrateException;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

/**
 * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes
 * @group language
 */
class LanguageTypesTest extends MigrateProcessTestCase {

  /**
   * Tests successful transformation of all language types.
   */
  public function testTransformAll() {
    $this->plugin = new LanguageTypes([], 'map', []);
    $source = [
      'language' => TRUE,
      'language_url' => FALSE,
      'language_content' => FALSE,
    ];
    $expected = [
      0 => 'language_url',
      1 => 'language_content',
      2 => 'language_interface',
    ];
30
    $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    $this->assertSame($value, $expected);
  }

  /**
   * Tests successful transformation of configurable language types.
   */
  public function testTransformConfigurable() {
    $this->plugin = new LanguageTypes(['filter_configurable' => TRUE], 'map', []);
    $source = [
      'language' => TRUE,
      'language_url' => FALSE,
      'language_content' => FALSE,
    ];
    $expected = [
      0 => 'language_interface',
    ];
47
    $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
48 49 50 51 52 53 54 55
    $this->assertSame($value, $expected);
  }

  /**
   * Tests string input.
   */
  public function testStringInput() {
    $this->plugin = new LanguageTypes([], 'map', []);
56 57
    $this->expectException(MigrateException::class);
    $this->expectExceptionMessage('The input should be an array');
58
    $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destination_property');
59 60 61
  }

}