protected function EntityUrlTest::getEntity in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
- 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
Returns a mock entity for testing.
Parameters
string $class: The class name to mock. Should be \Drupal\Core\Entity\Entity or a subclass.
array $values: An array of entity values to construct the mock entity with.
array $methods: (optional) An array of additional methods to mock on the entity object. The getEntityType() and entityTypeBundleInfo() methods are always mocked.
Return value
\Drupal\Core\Entity\Entity|\PHPUnit\Framework\MockObject\MockObject
8 calls to EntityUrlTest::getEntity()
- EntityUrlTest::testToUrlLinkTemplateAddForm in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with the 'revision' link template.
- EntityUrlTest::testToUrlLinkTemplateNoId in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with link templates without an entity ID.
- EntityUrlTest::testToUrlLinkTemplateRevision in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with the 'revision' link template.
- EntityUrlTest::testToUrlLinkTemplates in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with simple link templates.
- EntityUrlTest::testToUrlNoId in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method without an entity ID.
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php, line 428
Class
- EntityUrlTest
- Tests URL handling of the \Drupal\Core\Entity\EntityBase class.
Namespace
Drupal\Tests\Core\EntityCode
protected function getEntity($class, array $values, array $methods = []) {
$methods = array_merge($methods, [
'getEntityType',
'entityTypeBundleInfo',
]);
// Prophecy does not allow prophesizing abstract classes while actually
// calling their code. We use Prophecy below because that allows us to
// add method prophecies later while still revealing the prophecy now.
$entity = $this
->getMockBuilder($class)
->setConstructorArgs([
$values,
$this->entityTypeId,
])
->onlyMethods($methods)
->getMockForAbstractClass();
$this->entityType = $this
->prophesize(EntityTypeInterface::class);
$this->entityType
->getLinkTemplates()
->willReturn([]);
$this->entityType
->getKey('langcode')
->willReturn(FALSE);
$entity
->method('getEntityType')
->willReturn($this->entityType
->reveal());
$this->entityTypeBundleInfo = $this
->prophesize(EntityTypeBundleInfoInterface::class);
$entity
->method('entityTypeBundleInfo')
->willReturn($this->entityTypeBundleInfo
->reveal());
return $entity;
}