function EntityUrlTest::getEntity

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
  3. 11.x 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

12 calls to EntityUrlTest::getEntity()
EntityUrlTest::testLink in core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
Tests the link() method.
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.

... See full list

File

core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php, line 585

Class

EntityUrlTest
Tests URL handling of the \Drupal\Core\Entity\Entity class.

Namespace

Drupal\Tests\Core\Entity

Code

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,
    ])
        ->setMethods($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;
}

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