function EntityDisplayRepositoryTest::testViewDisplay

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest::testViewDisplay()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest::testViewDisplay()
  3. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest::testViewDisplay()

@covers ::getViewDisplay

File

core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php, line 64

Class

EntityDisplayRepositoryTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityDisplayRepository.php/class/EntityDisplayRepository/11.x" title="Provides a repository for entity display objects (view modes and form modes)." class="local">\Drupal\Core\Entity\EntityDisplayRepository</a>

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testViewDisplay() : void {
    $display = $this->displayRepository
        ->getViewDisplay('user', 'user');
    $this->assertInstanceOf(EntityViewDisplayInterface::class, $display);
    $this->assertTrue($display->isNew(), 'Default view display was created on demand.');
    $this->assertSame(EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE, $display->getMode());
    $display->createCopy('pastafazoul')
        ->save();
    $display = $this->displayRepository
        ->getViewDisplay('user', 'user', 'pastafazoul');
    $this->assertInstanceOf(EntityViewDisplayInterface::class, $display);
    $this->assertFalse($display->isNew(), 'An existing view display was loaded.');
    $this->assertSame('pastafazoul', $display->getMode());
    $display = $this->displayRepository
        ->getViewDisplay('user', 'user', 'magic');
    $this->assertInstanceOf(EntityViewDisplayInterface::class, $display);
    $this->assertTrue($display->isNew(), 'A new non-default view display was created on demand.');
    $this->assertSame('magic', $display->getMode());
}

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