You are here

public function ReferencedEntitiesReindexingTest::referencedEntityChangedDataProvider in Search API 8

Provides test data for testReferencedEntityChanged().

Return value

array[] An array of argument arrays for testReferencedEntityChanged().

See also

\Drupal\Tests\search_api\Kernel\ReferencedEntitiesReindexingTest::testReferencedEntityChanged()

File

tests/src/Kernel/Datasource/ReferencedEntitiesReindexingTest.php, line 163

Class

ReferencedEntitiesReindexingTest
Tests that changes in related entities are correctly tracked.

Namespace

Drupal\Tests\search_api\Kernel\Datasource

Code

public function referencedEntityChangedDataProvider() : array {
  $parents_expected = [
    'entity:node/3:en',
    'entity:node/4:en',
  ];
  $child_variants = [
    'child',
    'unrelated',
  ];
  $field_variants = [
    'indexed',
    'not_indexed',
  ];
  $tests = [];
  foreach ($child_variants as $child) {
    foreach ($field_variants as $field) {
      if ($child == 'child' && $field == 'indexed') {

        // This is how Search API represents our "parent" node in its tracking
        // data.
        $expected = $parents_expected;
      }
      else {
        $expected = [];
      }
      $tests["changing value of {$field} field within the {$child} entity"] = [
        [
          'child' => [
            'title' => 'Child',
            'indexed' => 'Original indexed value',
            'not_indexed' => 'Original not indexed value.',
          ],
          'unrelated' => [
            'title' => 'Unrelated child',
            'indexed' => 'Original indexed value',
            'not_indexed' => 'Original not indexed value.',
          ],
        ],
        [
          $child => [
            $field => "New {$field} value.",
          ],
        ],
        $expected,
      ];
      $tests["appending value of {$field} field within the {$child} entity"] = [
        [
          'child' => [
            'title' => 'Child',
            'indexed' => 'Original indexed value',
          ],
          'unrelated' => [
            'title' => 'Unrelated child',
            'indexed' => 'Original indexed value',
          ],
        ],
        [
          $child => [
            $field => "New {$field} value.",
          ],
        ],
        $expected,
      ];
      $tests["removing value of {$field} field within the {$child} entity"] = [
        [
          'child' => [
            'title' => 'Child',
            'indexed' => 'Original indexed value',
            'not_indexed' => 'Original not indexed value.',
          ],
          'unrelated' => [
            'title' => 'Unrelated child',
            'indexed' => 'Original indexed value',
            'not_indexed' => 'Original not indexed value.',
          ],
        ],
        [
          $child => [
            $field => [],
          ],
        ],
        $expected,
      ];
    }
    $tests["removing the {$child} entity"] = [
      [
        'child' => [
          'title' => 'Child',
          'indexed' => 'Original indexed value',
          'not_indexed' => 'Original not indexed value.',
        ],
        'unrelated' => [
          'title' => 'Unrelated child',
          'indexed' => 'Original indexed value',
          'not_indexed' => 'Original not indexed value.',
        ],
      ],
      [
        $child => FALSE,
      ],
      $child == 'child' ? $parents_expected : [],
    ];
  }
  return $tests;
}