Verified Commit d80db448 authored by Dave Long's avatar Dave Long
Browse files

Issue #3391776 by alexpott, smustgrave, catch: InfoParser returns an empty...

Issue #3391776 by alexpott, smustgrave, catch: InfoParser returns an empty array if passed a non-existing file

(cherry picked from commit 5ef2211a)
parent 04c5013c
Loading
Loading
Loading
Loading
Loading
+54 −54
Original line number Diff line number Diff line
@@ -37,9 +37,9 @@ public function __construct(string $app_root = NULL) {
   */
  public function parse($filename) {
    if (!file_exists($filename)) {
      $parsed_info = [];
      throw new InfoParserException("Unable to parse $filename as it does not exist");
    }
    else {

    try {
      $parsed_info = Yaml::decode(file_get_contents($filename));
    }
@@ -98,7 +98,7 @@ public function parse($filename) {
        throw new InfoParserException(sprintf("Extension %s (%s) has a '%s' entry that is not a valid URL.", $parsed_info['name'], $filename, ExtensionLifecycle::LIFECYCLE_LINK_IDENTIFIER));
      }
    }
    }

    return $parsed_info;
  }

+0 −2
Original line number Diff line number Diff line
@@ -633,8 +633,6 @@ protected function prepareEnvironment() {
    $this->classLoader = require __DIR__ . '/../../../../../autoload.php';
    $request = Request::createFromGlobals();
    $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
    // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
    chdir(DRUPAL_ROOT);
    $kernel->boot();
    $kernel->preHandle($request);
    $this->prepareDatabasePrefix();
+9 −69
Original line number Diff line number Diff line
@@ -2,12 +2,9 @@

namespace Drupal\KernelTests\Core\Theme;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Extension\InfoParserException;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
use org\bovigo\vfs\vfsStream;

/**
 * Tests the behavior of a theme when base_theme info key is missing.
@@ -34,80 +31,23 @@ class BaseThemeMissingTest extends KernelTestBase {
  protected function setUp(): void {
    parent::setUp();

    $this->themeInstaller = $this->container->get('theme_installer');
  }
    // Add a directory to extension discovery to find the theme with a missing
    // base class.
    // @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
    $settings = Settings::getAll();
    $settings['test_parent_site'] = 'core/tests/fixtures/test_missing_base_theme';
    new Settings($settings);

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {
    parent::register($container);

    $container->getDefinition('extension.list.theme')
      ->setClass(VfsThemeExtensionList::class);
  }

  /**
   * {@inheritdoc}
   */
  protected function setUpFilesystem() {
    parent::setUpFilesystem();

    $vfs_root = vfsStream::setup('core');
    vfsStream::create([
      'themes' => [
        'test_missing_base_theme' => [
          'test_missing_base_theme.info.yml' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_missing_base_theme/test_missing_base_theme.info.yml'),
          'test_missing_base_theme.theme' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_missing_base_theme/test_missing_base_theme.theme'),
        ],
      ],
    ], $vfs_root);
    $this->themeInstaller = $this->container->get('theme_installer');
  }

  /**
   * Tests exception is thrown.
   */
  public function testMissingBaseThemeException() {
    $this->container->get('extension.list.theme')
      ->setExtensionDiscovery(new ExtensionDiscovery('vfs://core'));

    $this->expectException(InfoParserException::class);
    $this->expectExceptionMessage('Missing required key ("base theme") in themes/test_missing_base_theme/test_missing_base_theme.info.yml, see https://www.drupal.org/node/3066038');
    $this->expectExceptionMessage('Missing required key ("base theme") in core/tests/fixtures/test_missing_base_theme/test_missing_base_theme.info.yml, see https://www.drupal.org/node/3066038');
    $this->themeInstaller->install(['test_missing_base_theme']);
  }

}

/**
 * Test theme extension list class.
 */
class VfsThemeExtensionList extends ThemeExtensionList {

  /**
   * The extension discovery for this extension list.
   *
   * @var \Drupal\Core\Extension\ExtensionDiscovery
   */
  protected $extensionDiscovery;

  /**
   * Sets the extension discovery.
   *
   * @param \Drupal\Core\Extension\ExtensionDiscovery $discovery
   *   The extension discovery.
   *
   * @return self
   */
  public function setExtensionDiscovery(ExtensionDiscovery $discovery) {
    $this->extensionDiscovery = $discovery;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getExtensionDiscovery() {
    return $this->extensionDiscovery;
  }

}
+0 −3
Original line number Diff line number Diff line
@@ -241,9 +241,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
  public static function setUpBeforeClass(): void {
    parent::setUpBeforeClass();
    VarDumper::setHandler(TestVarDumper::class . '::cliHandler');

    // Change the current dir to DRUPAL_ROOT.
    chdir(static::getDrupalRoot());
  }

  /**
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ protected function configure() {
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    $root = dirname(__DIR__, 5);
    chdir($root);
    TestDatabase::releaseAllTestLocks();
    $output->writeln('<info>Successfully released all the test database locks</info>');
    return 0;
Loading