Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / migrate_plus / tests / src / Unit / process / ArrayPopTest.php
diff --git a/web/modules/contrib/migrate_plus/tests/src/Unit/process/ArrayPopTest.php b/web/modules/contrib/migrate_plus/tests/src/Unit/process/ArrayPopTest.php
new file mode 100644 (file)
index 0000000..84316d7
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+namespace Drupal\Tests\migrate_plus\Unit\process;
+
+use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
+use Drupal\migrate_plus\Plugin\migrate\process\ArrayPop;
+use Drupal\migrate\MigrateException;
+
+/**
+ * Tests the array pop process plugin.
+ *
+ * @group migrate
+ * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\ArrayPop
+ */
+class ArrayPopTest extends MigrateProcessTestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    $this->plugin = new ArrayPop([], 'array_pop', []);
+    parent::setUp();
+  }
+
+  /**
+   * Data provider for testArrayPop().
+   *
+   * @return array
+   *   An array containing input values and expected output values.
+   */
+  public function arrayPopDataProvider() {
+    return [
+      'indexed array' => [
+        'input' => ['v1', 'v2', 'v3'],
+        'expected_output' => 'v3',
+      ],
+      'associative array' => [
+        'input' => ['i1' => 'v1', 'i2' => 'v2', 'i3' => 'v3'],
+        'expected_output' => 'v3',
+      ],
+      'empty array' => [
+        'input' => [],
+        'expected_output' => NULL,
+      ],
+    ];
+  }
+
+  /**
+   * Test array pop plugin.
+   *
+   * @param array $input
+   *   The input values.
+   * @param mixed $expected_output
+   *   The expected output.
+   *
+   * @dataProvider arrayPopDataProvider
+   */
+  public function testArrayPop(array $input, $expected_output) {
+    $output = $this->plugin->transform($input, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertSame($output, $expected_output);
+  }
+
+  /**
+   * Test invalid input.
+   */
+  public function testArrayPopFromString() {
+    $this->setExpectedException(MigrateException::class, 'Input should be an array.');
+    $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
+  }
+
+}