View source
<?php
namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d6;
use Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults;
use Drupal\migrate\MigrateException;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
class FieldTypeDefaultsTest extends MigrateProcessTestCase {
protected function setUp() {
parent::setUp();
$this->plugin = new FieldTypeDefaults([], 'd6_field_type_defaults', []);
}
public function testDefaults() {
$this->row
->expects($this
->once())
->method('getSourceProperty')
->willReturn('date');
$this
->assertNull($this->plugin
->transform(NULL, $this->migrateExecutable, $this->row, 'property'));
$this
->assertEquals('string', $this->plugin
->transform('string', $this->migrateExecutable, $this->row, 'property'));
$this
->assertEquals(1234, $this->plugin
->transform(1234, $this->migrateExecutable, $this->row, 'property'));
$this
->assertEquals('datetime_default', $this->plugin
->transform([], $this->migrateExecutable, $this->row, 'property'));
}
public function testDefaultsException() {
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage(sprintf('Failed to lookup field type %s in the static map.', var_export([], TRUE)));
$this->plugin
->transform([], $this->migrateExecutable, $this->row, 'property');
}
}