3 namespace Drupal\Tests\migrate\Unit\process;
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\Plugin\migrate\process\Extract;
9 * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Extract
12 class ExtractTest extends MigrateProcessTestCase {
17 protected function setUp() {
18 $configuration['index'] = ['foo'];
19 $this->plugin = new Extract($configuration, 'map', []);
24 * Tests successful extraction.
26 public function testExtract() {
27 $value = $this->plugin->transform(['foo' => 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
28 $this->assertSame($value, 'bar');
32 * Tests invalid input.
34 public function testExtractFromString() {
35 $this->setExpectedException(MigrateException::class, 'Input should be an array.');
36 $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty');
40 * Tests unsuccessful extraction.
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');
48 * Tests unsuccessful extraction.
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', '');