X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmigrate_plus%2Ftests%2Fsrc%2FUnit%2Fprocess%2FArrayShiftTest.php;fp=web%2Fmodules%2Fcontrib%2Fmigrate_plus%2Ftests%2Fsrc%2FUnit%2Fprocess%2FArrayShiftTest.php;h=6c6950fee1109105d8ea9d3eb9001771b7db746a;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/modules/contrib/migrate_plus/tests/src/Unit/process/ArrayShiftTest.php b/web/modules/contrib/migrate_plus/tests/src/Unit/process/ArrayShiftTest.php new file mode 100644 index 000000000..6c6950fee --- /dev/null +++ b/web/modules/contrib/migrate_plus/tests/src/Unit/process/ArrayShiftTest.php @@ -0,0 +1,71 @@ +plugin = new ArrayShift([], 'array_shift', []); + parent::setUp(); + } + + /** + * Data provider for testArrayShift(). + * + * @return array + * An array containing input values and expected output values. + */ + public function arrayShiftDataProvider() { + return [ + 'indexed array' => [ + 'input' => ['v1', 'v2', 'v3'], + 'expected_output' => 'v1', + ], + 'associative array' => [ + 'input' => ['i1' => 'v1', 'i2' => 'v2', 'i3' => 'v3'], + 'expected_output' => 'v1', + ], + 'empty array' => [ + 'input' => [], + 'expected_output' => NULL, + ], + ]; + } + + /** + * Test array shift plugin. + * + * @param array $input + * The input values. + * @param mixed $expected_output + * The expected output. + * + * @dataProvider arrayShiftDataProvider + */ + public function testArrayShift(array $input, $expected_output) { + $output = $this->plugin->transform($input, $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame($output, $expected_output); + } + + /** + * Test invalid input. + */ + public function testArrayShiftFromString() { + $this->setExpectedException(MigrateException::class, 'Input should be an array.'); + $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); + } + +}