8422293c2721bbe24e406411567889a5f362f496
[yaffs-website] / web / core / modules / taxonomy / tests / src / Unit / Plugin / migrate / field / TaxonomyTermReferenceFieldTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Unit\Plugin\migrate\field;
4
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\taxonomy\Plugin\migrate\field\TaxonomyTermReference;
8 use Prophecy\Argument;
9
10 /**
11  * @coversDefaultClass \Drupal\taxonomy\Plugin\migrate\field\TaxonomyTermReference
12  * @group taxonomy
13  */
14 class TaxonomyTermReferenceFieldTest extends UnitTestCase {
15
16   /**
17    * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
18    */
19   protected $plugin;
20
21   /**
22    * @var \Drupal\migrate\Plugin\MigrationInterface
23    */
24   protected $migration;
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     $this->plugin = new TaxonomyTermReference([], 'taxonomy', []);
31
32     $migration = $this->prophesize(MigrationInterface::class);
33
34     // The plugin's processFieldValues() method will call
35     // setProcessOfProperty() and return nothing. So, in order to examine the
36     // process pipeline created by the plugin, we need to ensure that
37     // getProcess() always returns the last input to setProcessOfProperty().
38     $migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
39       ->will(function ($arguments) use ($migration) {
40         $migration->getProcess()->willReturn($arguments[1]);
41       });
42
43     $this->migration = $migration->reveal();
44   }
45
46   /**
47    * @covers ::processFieldValues
48    */
49   public function testProcessFieldValues() {
50     $this->plugin->processFieldValues($this->migration, 'somefieldname', []);
51
52     $expected = [
53       'plugin' => 'sub_process',
54       'source' => 'somefieldname',
55       'process' => [
56         'target_id' => 'tid',
57       ],
58     ];
59     $this->assertSame($expected, $this->migration->getProcess());
60   }
61
62 }