1a4c8e1ff404c92eafeb60b6d242a6bdce824e50
[yaffs-website] / web / core / modules / field / tests / src / Unit / Plugin / migrate / process / d6 / FieldTypeDefaultsTest.php
1 <?php
2
3 namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d6;
4
5 use Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults;
6 use Drupal\migrate\MigrateException;
7 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
8
9 /**
10  * Tests D6 fields defaults.
11  *
12  * @coversDefaultClass \Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults
13  * @group field
14  */
15 class FieldTypeDefaultsTest extends MigrateProcessTestCase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function setUp() {
21     parent::setUp();
22     $this->plugin = new FieldTypeDefaults([], 'd6_field_type_defaults', []);
23   }
24
25   /**
26    * Tests various default cases.
27    *
28    * @covers ::transform
29    */
30   public function testDefaults() {
31     $this->row->expects($this->once())
32       ->method('getSourceProperty')
33       ->willReturn('date');
34
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'));
42   }
43
44   /**
45    * Tests an exception is thrown when the input is not a date field.
46    *
47    * @covers ::transform
48    */
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');
53   }
54
55 }