You are here

public function FieldItemListTest::providerTestEquals in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php \Drupal\Tests\Core\Field\FieldItemListTest::providerTestEquals()

Data provider for testEquals.

File

core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php, line 78

Class

FieldItemListTest
@coversDefaultClass \Drupal\Core\Field\FieldItemList @group Field

Namespace

Drupal\Tests\Core\Field

Code

public function providerTestEquals() {

  // Tests field item lists with no values.
  $datasets[] = [
    TRUE,
  ];

  /** @var \Drupal\Core\Field\FieldItemBase  $field_item_a */
  $field_item_a = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_a
    ->setValue([
    1,
  ]);

  // Tests field item lists where one has a value and one does not.
  $datasets[] = [
    FALSE,
    $field_item_a,
  ];

  // Tests field item lists where both have the same value.
  $datasets[] = [
    TRUE,
    $field_item_a,
    $field_item_a,
  ];

  /** @var \Drupal\Core\Field\FieldItemBase  $fv */
  $field_item_b = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_b
    ->setValue([
    2,
  ]);

  // Tests field item lists where both have the different values.
  $datasets[] = [
    FALSE,
    $field_item_a,
    $field_item_b,
  ];

  /** @var \Drupal\Core\Field\FieldItemBase  $fv */
  $field_item_c = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_c
    ->setValue([
    '0' => 1,
    '1' => 2,
  ]);
  $field_item_d = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_d
    ->setValue([
    '1' => 2,
    '0' => 1,
  ]);

  // Tests field item lists where both have the differently ordered values.
  $datasets[] = [
    TRUE,
    $field_item_c,
    $field_item_d,
  ];

  /** @var \Drupal\Core\Field\FieldItemBase  $field_item_e */
  $field_item_e = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_e
    ->setValue([
    '2',
  ]);

  // Tests field item lists where both have same values but different data
  // types.
  $datasets[] = [
    TRUE,
    $field_item_b,
    $field_item_e,
  ];

  /** @var \Drupal\Core\Field\FieldItemBase  $field_item_f */
  $field_item_f = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_f
    ->setValue([
    '0' => 1,
    '1' => 2,
    '2' => 3,
  ]);

  /** @var \Drupal\Core\Field\FieldItemBase  $field_item_g */
  $field_item_g = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_g
    ->setValue([
    '0' => 1,
    '1' => 2,
    '2' => 4,
  ]);

  // Tests field item lists where both have same values for the non-computed
  // properties ('0' and '1') and a different value for the computed one
  // ('2').
  $datasets[] = [
    TRUE,
    $field_item_f,
    $field_item_g,
  ];

  /** @var \Drupal\Core\Field\FieldItemBase  $field_item_h */
  $field_item_h = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_h
    ->setValue([
    '0' => 1,
    '1' => 2,
    '3' => 3,
  ]);

  /** @var \Drupal\Core\Field\FieldItemBase  $field_item_i */
  $field_item_i = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemBase', [], '', FALSE);
  $field_item_i
    ->setValue([
    '0' => 1,
    '1' => 2,
    '3' => 4,
  ]);

  // Tests field item lists where both have same values for the non-computed
  // properties ('0' and '1') and a different value for a property that does
  // 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;
}