<?php

declare(strict_types=1);

namespace Drupal\Tests\comment\Unit\Plugin\views\field;

use Drupal\comment\Plugin\views\field\LinkReply;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
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;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;

/**
 * Tests Drupal\comment\Plugin\views\field\LinkReply.
 */
#[CoversClass(LinkReply::class)]
#[Group('comment')]
class LinkReplyTest extends UnitTestCase {

  use ViewsLoggerTestTrait;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->setUpMockLoggerWithMissingEntity();
    $container = \Drupal::getContainer();
    $container->set('string_translation', $this->getStringTranslationStub());
    \Drupal::setContainer($container);
  }

  /**
   * Test the render method when getEntity returns NULL.
   */
  public function testRenderNullEntity(): void {
    $row = new ResultRow();
    $field = new LinkReply(['entity_type' => 'foo', 'entity field' => 'bar'], '', [], $this->createStub(AccessManagerInterface::class), $this->createStub(EntityTypeManagerInterface::class), $this->createStub(EntityRepositoryInterface::class), $this->createStub(LanguageManagerInterface::class));
    $view = $this->createStub(ViewExecutable::class);
    $display = $this->createStub(DisplayPluginBase::class);
    $field->init($view, $display);
    $this->assertEmpty($field->render($row));
  }

}
