3 namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d6;
5 use Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults;
6 use Drupal\migrate\MigrateException;
7 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
10 * Tests D6 fields defaults.
12 * @coversDefaultClass \Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults
15 class FieldTypeDefaultsTest extends MigrateProcessTestCase {
20 protected function setUp() {
22 $this->plugin = new FieldTypeDefaults([], 'd6_field_type_defaults', []);
26 * Tests various default cases.
30 public function testDefaults() {
31 $this->row->expects($this->once())
32 ->method('getSourceProperty')
35 // Assert common values are passed through without modification.
36 $this->assertNull($this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'property'));
37 $this->assertEquals('string', $this->plugin->transform('string', $this->migrateExecutable, $this->row, 'property'));
38 $this->assertEquals(1234, $this->plugin->transform(1234, $this->migrateExecutable, $this->row, 'property'));
39 // Assert that an array checks that this is a date field(above mock assert)
40 // and returns "datetime_default".
41 $this->assertEquals('datetime_default', $this->plugin->transform([], $this->migrateExecutable, $this->row, 'property'));
45 * Tests an exception is thrown when the input is not a date field.
49 public function testDefaultsException() {
50 $this->setExpectedException(MigrateException::class,
51 sprintf('Failed to lookup field type %s in the static map.', var_export([], TRUE)));
52 $this->plugin->transform([], $this->migrateExecutable, $this->row, 'property');