IconsTwigExtensionTest.php

Same filename and directory in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Theme/Icon/IconsTwigExtensionTest.php

Namespace

Drupal\Tests\Core\Theme\Icon

File

core/tests/Drupal/Tests/Core/Theme/Icon/IconsTwigExtensionTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\Core\Theme\Icon;

use Drupal\Core\Template\IconsTwigExtension;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

/**
 * Tests Drupal\Core\Template\IconsTwigExtension.
 */
class IconsTwigExtensionTest extends TestCase {
  
  /**
   * The twig extension.
   *
   * @var \Drupal\Core\Template\IconsTwigExtension
   */
  private IconsTwigExtension $iconsTwigExtension;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    $this->iconsTwigExtension = new IconsTwigExtension();
  }
  
  /**
   * Test the IconsTwigExtension::getFunctions method.
   */
  public function testGetFunctions() : void {
    $functions = $this->iconsTwigExtension
      ->getFunctions();
    $this->assertCount(1, $functions);
    $this->assertEquals('icon', $functions[0]->getName());
  }
  
  /**
   * Test the IconsTwigExtension::getIconRenderable method.
   */
  public function testGetIconRenderable() : void {
    $settings = [
      'foo' => 'bar',
    ];
    $result = $this->iconsTwigExtension
      ->getIconRenderable('pack_id', 'icon_id', $settings);
    $expected = [
      '#type' => 'icon',
      '#pack_id' => 'pack_id',
      '#icon_id' => 'icon_id',
      '#settings' => $settings,
    ];
    $this->assertEquals($expected, $result);
  }

}

Classes

Title Deprecated Summary
IconsTwigExtensionTest Tests Drupal\Core\Template\IconsTwigExtension.

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