You are here

public function EntityFinderTest::fieldsDataProvider in UI Patterns 8

Test data provider.

Return value

array Test data.

File

modules/ui_patterns_field_group/tests/src/Unit/EntityFinderTest.php, line 33

Class

EntityFinderTest
Test entity finder utility.

Namespace

Drupal\Tests\ui_patterns_field_group\Unit

Code

public function fieldsDataProvider() {
  $good = $this
    ->getMockBuilder(ContentEntityBase::class)
    ->disableOriginalConstructor()
    ->getMock();
  $bad = new \stdClass();
  return [
    // Found with singe value per field.
    [
      'fields' => [
        'foo' => [
          '#object' => $good,
        ],
        'bar' => [
          '#object' => $bad,
        ],
      ],
      'expected' => $good,
    ],
    // Found with singe value per field.
    [
      'fields' => [
        'bar' => [
          '#object' => $bad,
        ],
        'foo' => [
          '#object' => $good,
        ],
      ],
      'expected' => $good,
    ],
    // Found with multiple values per field.
    [
      'fields' => [
        'foo' => [
          [
            '#object' => $good,
          ],
        ],
        'bar' => [
          [
            '#object' => $bad,
          ],
        ],
      ],
      'expected' => $good,
    ],
    // Found with multiple values per field.
    [
      'fields' => [
        'bar' => [
          [
            '#object' => $bad,
          ],
          [
            '#object' => $good,
          ],
        ],
        'foo' => [
          [
            '#object' => $bad,
          ],
          [
            '#object' => $bad,
          ],
        ],
      ],
      'expected' => $good,
    ],
    // Found with one empty array field and multiple values per field.
    [
      'fields' => [
        'foo' => [
          [],
          [
            '#object' => $good,
          ],
        ],
      ],
      'expected' => $good,
    ],
    // Found with one empty null field and multiple values per field.
    [
      'fields' => [
        'foo' => [
          NULL,
          [
            '#object' => $good,
          ],
        ],
      ],
      'expected' => $good,
    ],
    // Not found with one empty null field and multiple values per field.
    [
      'fields' => [
        'foo' => [
          NULL,
          [
            '#object' => $bad,
          ],
        ],
      ],
      'expected' => NULL,
    ],
  ];
}