class EntityDisplayRepositoryTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayRepositoryTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest
@coversDefaultClass \Drupal\Core\Entity\EntityDisplayRepository
@group Entity
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Entity\EntityDisplayRepositoryTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of EntityDisplayRepositoryTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDisplayRepositoryTest.php, line 15
Namespace
Drupal\KernelTests\Core\EntityView source
class EntityDisplayRepositoryTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'user',
];
/**
* The entity display repository under test.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $displayRepository;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->displayRepository = \Drupal::service('entity_display.repository');
// Create a new view mode for users.
$this->container
->get('entity_type.manager')
->getStorage('entity_view_mode')
->create([
'id' => 'user.pastafazoul',
'label' => $this->randomMachineName(),
'targetEntityType' => 'user',
])
->save();
// Create a new form mode for users.
$this->container
->get('entity_type.manager')
->getStorage('entity_form_mode')
->create([
'id' => 'user.register',
'label' => $this->randomMachineName(),
'targetEntityType' => 'user',
])
->save();
}
/**
* @covers ::getViewDisplay
*/
public function testViewDisplay() {
$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());
}
/**
* @covers ::getFormDisplay
*/
public function testFormDisplay() {
$display = $this->displayRepository
->getFormDisplay('user', 'user');
$this->assertInstanceOf(EntityFormDisplayInterface::class, $display);
$this->assertTrue($display->isNew(), 'Default form display was created on demand.');
$this->assertSame(EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE, $display->getMode());
$display->createCopy('register')
->save();
$display = $this->displayRepository
->getFormDisplay('user', 'user', 'register');
$this->assertInstanceOf(EntityFormDisplayInterface::class, $display);
$this->assertFalse($display->isNew(), 'An existing form display was loaded.');
$this->assertSame('register', $display->getMode());
$display = $this->displayRepository
->getFormDisplay('user', 'user', 'magic');
$this->assertInstanceOf(EntityFormDisplayInterface::class, $display);
$this->assertTrue($display->isNew(), 'A new non-default form 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.