Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / ExtractTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\Plugin\migrate\process\Extract;
7
8 /**
9  * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Extract
10  * @group migrate
11  */
12 class ExtractTest extends MigrateProcessTestCase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function setUp() {
18     $configuration['index'] = ['foo'];
19     $this->plugin = new Extract($configuration, 'map', []);
20     parent::setUp();
21   }
22
23   /**
24    * Tests successful extraction.
25    */
26   public function testExtract() {
27     $value = $this->plugin->transform(['foo' => 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
28     $this->assertSame($value, 'bar');
29   }
30
31   /**
32    * Tests invalid input.
33    */
34   public function testExtractFromString() {
35     $this->setExpectedException(MigrateException::class, 'Input should be an array.');
36     $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty');
37   }
38
39   /**
40    * Tests unsuccessful extraction.
41    */
42   public function testExtractFail() {
43     $this->setExpectedException(MigrateException::class, 'Array index missing, extraction failed.');
44     $this->plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
45   }
46
47   /**
48    * Tests unsuccessful extraction.
49    */
50   public function testExtractFailDefault() {
51     $plugin = new Extract(['index' => ['foo'], 'default' => 'test'], 'map', []);
52     $value = $plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
53     $this->assertSame($value, 'test', '');
54   }
55
56 }