Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for date fields with both a start and end date #12

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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