function EntityDisplayTest::assertDependencyHelper

Same name in other branches
  1. 9 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::assertDependencyHelper()
  2. 8.9.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::assertDependencyHelper()
  3. 11.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::assertDependencyHelper()

Provides a helper for dependency assertions.

@internal

Parameters

bool $assertion: Assertion: positive or negative.

string $type: The dependency type: 'config', 'content', 'module' or 'theme'.

string $key: The string to be checked.

\Drupal\Core\Entity\Display\EntityDisplayInterface $display: The entity display object to get dependencies from.

2 calls to EntityDisplayTest::assertDependencyHelper()
EntityDisplayTest::assertDependency in core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
Asserts that $key is a $type type dependency of $display config entity.
EntityDisplayTest::assertNoDependency in core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
Asserts that $key is not a $type type dependency of $display config entity.

File

core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php, line 700

Class

EntityDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

protected function assertDependencyHelper(bool $assertion, string $type, string $key, EntityDisplayInterface $display) : void {
    $all_dependencies = $display->getDependencies();
    $dependencies = !empty($all_dependencies[$type]) ? $all_dependencies[$type] : [];
    $context = $display instanceof EntityViewDisplayInterface ? 'View' : 'Form';
    $value = $assertion ? in_array($key, $dependencies) : !in_array($key, $dependencies);
    $display_id = $display->id();
    $message = $assertion ? "{$context} display '{$display_id}' depends on {$type} '{$key}'." : "{$context} display '{$display_id}' do not depend on {$type} '{$key}'.";
    $this->assertTrue($value, $message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.