<?php

declare(strict_types=1);

namespace Drupal\Tests\tandoor\Kernel;

use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Attributes\Group;

/**
 * Tests theme info.
 */
#[Group('DCG')]
final class InfoTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->container->get('theme_installer')->install(['azalea']);
  }

  /**
   * Test callback.
   */
  public function testInfo(): void {
    $theme = $this->container
      ->get('theme_handler')
      ->getTheme('azalea');
    self::assertSame('theme', $theme->getType());
    self::assertSame('azalea', $theme->getName());
    self::assertSame('azalea.info.yml', $theme->getFilename());
    self::assertThemeInfo($theme->info);
  }

  /**
   * Asserts theme info.
   */
  private static function assertThemeInfo(array $info): void {
    $expected_info = [
      'name' => 'Azalea',
      'type' => 'theme',
      'base theme' => 'claro',
      'description' => 'Simple responsive theme generated by DCG.',
      'package' => 'DCG',
      'core_version_requirement' => '^10 || ^11',
      'libraries' => ['azalea/global'],
      'regions' =>
        [
          'header' => 'Header',
          'primary_menu' => 'Primary menu',
          'secondary_menu' => 'Secondary menu',
          'page_top' => 'Page top',
          'page_bottom' => 'Page bottom',
          'featured' => 'Featured',
          'breadcrumb' => 'Breadcrumb',
          'content' => 'Content',
          'sidebar_first' => 'Sidebar first',
          'sidebar_second' => 'Sidebar second',
          'footer' => 'Footer',
        ],
      'core_incompatible' => FALSE,
      'lifecycle' => 'stable',
      'engine' => 'twig',
      'features' =>
        [
          'favicon',
          'logo',
          'node_user_picture',
          'comment_user_picture',
          'comment_user_verification',
        ],
      'screenshot' => 'themes/azalea/screenshot.png',
      'version' => NULL,
      'php' => '8.3.0',
      'libraries_extend' => [],
      'libraries_override' => [],
      'dependencies' => ['claro'],
    ];
    unset($info['mtime']);
    self::assertSame($expected_info, $info);
  }

}
