From 5239ebef6351dc226bb0c27f5ac9eb321a317509 Mon Sep 17 00:00:00 2001 From: Patrick Weston Date: Fri, 11 Dec 2015 12:16:51 -0600 Subject: [PATCH] Fix for date fields with both a start and end date --- .../Context/EntityDataContext.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Palantirnet/PalantirBehatExtension/Context/EntityDataContext.php b/src/Palantirnet/PalantirBehatExtension/Context/EntityDataContext.php index dc481ac..4ed8f5e 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/EntityDataContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/EntityDataContext.php @@ -298,6 +298,15 @@ public function assertEntityFieldValueEntityReference($field, $value) * The value to look for. * * @throws \Exception + * + * @todo : Update method to handle date fields with start and end dates + * The call to $wrapper->$field->value() returns either an array or a scalar + * because entity_metadata_wrapper() makes the date field values array + * unpredictable. When working with date fields that have both a start and + * end time, an array is returned instead of a scalar. If we want to test + * for start and end dates, we would want to use Behat syntax similar to + * "Then entity field ":field should contain " - ". + * This method would need to be updated to handle that approach. */ public function assertEntityFieldValueDatetime($field, $value) { @@ -313,6 +322,22 @@ public function assertEntityFieldValueDatetime($field, $value) } foreach ($field_value as $v) { + if (is_array($v)) { + // Check the start date + if (array_key_exists('value', $v)) { + if (strtotime($value) == strtotime($v['value'])) { + return; + } + } + + // Check the end date + if (array_key_exists('value2', $v)) { + if (strtotime($value) == strtotime($v['value2'])) { + return; + } + } + } + if (strtotime($value) == $v) { return; }