From 148b87f5cf52715c280766289552f387377ec0aa Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 20 Nov 2018 12:37:12 +0000 Subject: [PATCH] Issue #3011069 by Jo Fitzgerald, quietone: Incomplete testing for format_date process plugin --- .../src/Plugin/migrate/process/FormatDate.php | 2 +- .../tests/src/Unit/process/FormatDateTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/modules/migrate/src/Plugin/migrate/process/FormatDate.php b/core/modules/migrate/src/Plugin/migrate/process/FormatDate.php index 9448ca2fff2..a40681921b5 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/FormatDate.php +++ b/core/modules/migrate/src/Plugin/migrate/process/FormatDate.php @@ -136,7 +136,7 @@ class FormatDate extends ProcessPluginBase { throw new MigrateException(sprintf('Format date plugin could not transform "%s" using the format "%s". Error: %s', $value, $fromFormat, $e->getMessage()), $e->getCode(), $e); } catch (\UnexpectedValueException $e) { - throw new MigrateException(sprintf('Format date plugin could not transform "%s" using the format "%s". Error: %s', $value, $fromFormat, $e->getMessage()), $e->getCode(), $e); + throw new MigrateException(sprintf('Format date plugin could not transform "%s" using the format "%s" for destination "%s". Error: %s', $value, $fromFormat, $destination_property, $e->getMessage()), $e->getCode(), $e); } return $transformed; diff --git a/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php b/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php index 994de3855fb..5fbc5dde64f 100644 --- a/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php +++ b/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php @@ -56,6 +56,20 @@ class FormatDateTest extends MigrateProcessTestCase { $this->plugin->transform('January 5, 1955', $this->migrateExecutable, $this->row, 'field_date'); } + /** + * Tests that an unexpected date value will throw an exception. + */ + public function testMigrateExceptionUnexpectedValue() { + $configuration = [ + 'from_format' => 'm/d/Y', + 'to_format' => 'Y-m-d', + ]; + + $this->setExpectedException(MigrateException::class, 'Format date plugin could not transform "01/05/55" using the format "m/d/Y" for destination "field_date". Error: The created date does not match the input value.'); + $this->plugin = new FormatDate($configuration, 'test_format_date', []); + $this->plugin->transform('01/05/55', $this->migrateExecutable, $this->row, 'field_date'); + } + /** * Tests that "timezone" configuration key triggers deprecation error. *