Commit 998d2146 authored by catch's avatar catch
Browse files

Issue #2988309 by Krzysztof Domański, Berdir, hchonov: Ensure that all field...

Issue #2988309 by Krzysztof Domański, Berdir, hchonov: Ensure that all field types return TRUE on equals() for the same values

(cherry picked from commit 29e32469)
parent 32e82729
......@@ -393,6 +393,15 @@ public function equals(FieldItemListInterface $list_to_compare) {
$callback = function (&$value) use ($non_computed_properties) {
if (is_array($value)) {
$value = array_intersect_key($value, $non_computed_properties);
// Also filter out properties with a NULL value as they might exist in
// one field item and not in the other, depending on how the values are
// set. Do not filter out empty strings or other false-y values as e.g.
// a NULL or FALSE in a boolean field is not the same.
$value = array_filter($value, function ($property) {
return $property !== NULL;
});
ksort($value);
}
};
......
......@@ -135,6 +135,25 @@ public function providerTestEquals() {
// not exist ('3').
$datasets[] = [TRUE, $field_item_h, $field_item_i];
/** @var \Drupal\Core\Field\FieldItemBase $field_item_j */
$field_item_j = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
$field_item_j->setValue(['0' => 1]);
/** @var \Drupal\Core\Field\FieldItemBase $field_item_k */
$field_item_k = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
$field_item_k->setValue(['0' => 1, '1' => NULL]);
/** @var \Drupal\Core\Field\FieldItemBase $field_item_l */
$field_item_l = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
$field_item_l->setValue(['0' => 1, '1' => FALSE]);
/** @var \Drupal\Core\Field\FieldItemBase $field_item_m */
$field_item_m = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
$field_item_m->setValue(['0' => 1, '1' => '']);
// Tests filter properties with a NULL value. Empty strings or other false-y
// values are not filtered.
$datasets[] = [TRUE, $field_item_j, $field_item_k];
$datasets[] = [FALSE, $field_item_j, $field_item_l];
$datasets[] = [FALSE, $field_item_j, $field_item_m];
return $datasets;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment