Skip to content

Commit

Permalink
Merge pull request #12 from palantirnet/date-start-end
Browse files Browse the repository at this point in the history
Fix for date fields with both a start and end date
  • Loading branch information
becw committed Dec 14, 2015
2 parents f642d9e + 5239ebe commit 62a3a61
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<start_date> - <end_date>".
* This method would need to be updated to handle that approach.
*/
public function assertEntityFieldValueDatetime($field, $value)
{
Expand All @@ -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;
}
Expand Down

0 comments on commit 62a3a61

Please sign in to comment.