ContactLinkTest.php

Same filename in this branch
  1. 11.x core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php
Same filename in other branches
  1. 9 core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php
  2. 8.9.x core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php
  3. 10 core/modules/contact/tests/src/Unit/ContactLinkTest.php
  4. 10 core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php

Namespace

Drupal\Tests\contact\Unit

File

core/modules/contact/tests/src/Unit/ContactLinkTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\contact\Unit;

use Drupal\contact\Plugin\views\field\ContactLink;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\views\Traits\ViewsLoggerTestTrait;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;

/**
 * @coversDefaultClass \Drupal\contact\Plugin\views\field\ContactLink
 * @group contact
 */
class ContactLinkTest extends UnitTestCase {
    use ViewsLoggerTestTrait;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->setUpMockLoggerWithMissingEntity();
        $container = \Drupal::getContainer();
        $container->set('string_translation', $this->createMock(TranslationInterface::class));
        \Drupal::setContainer($container);
    }
    
    /**
     * Test the render method when getEntity returns NULL.
     *
     * @covers ::render
     */
    public function testRenderNullEntity() : void {
        $row = new ResultRow();
        $field = new ContactLink([
            'entity_type' => 'foo',
            'entity field' => 'bar',
        ], '', [], $this->createMock(AccessManagerInterface::class), $this->createMock(EntityTypeManagerInterface::class), $this->createMock(EntityRepositoryInterface::class), $this->createMock(LanguageManagerInterface::class));
        $view = $this->createMock(ViewExecutable::class);
        $display = $this->createMock(DisplayPluginBase::class);
        $field->init($view, $display);
        $this->assertEmpty($field->render($row));
    }

}

Classes

Title Deprecated Summary
ContactLinkTest @coversDefaultClass \Drupal\contact\Plugin\views\field\ContactLink @group contact

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