Verified Commit 9e84cb4e authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3293469 by bnjmnm, dmundra, finnsky, Anchal_gupta, andypost, lauriii,...

Issue #3293469 by bnjmnm, dmundra, finnsky, Anchal_gupta, andypost, lauriii, xjm, nod_, rikki_iki: Automated A11y tests in Nightwatch
parent 70cfa8b4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
name: 'Nightwatch theme install utility'
type: module
description: 'Helper module facilitate theme installation in Nightwatch tests'
package: Testing
version: VERSION
+13 −0
Original line number Diff line number Diff line
nightwatch_utility.theme_install_default:
  path: '/admin/theme/install_default/{theme}'
  defaults:
    _controller: '\Drupal\nightwatch_theme_install_utility\Controller\ThemeInstallController::installDefault'
  requirements:
    _permission: 'administer themes'

nightwatch_utility.theme_install_admin:
  path: '/admin/theme/install_admin/{theme}'
  defaults:
    _controller: '\Drupal\nightwatch_theme_install_utility\Controller\ThemeInstallController::installAdmin'
  requirements:
    _permission: 'administer themes'
+93 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\nightwatch_theme_install_utility\Controller;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ThemeInstallerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides an easier way for Nightwatch tests to install themes.
 */
class ThemeInstallController extends ControllerBase {

  /**
   * The theme installer service.
   *
   * @var \Drupal\Core\Extension\ThemeInstallerInterface
   */
  protected $themeInstaller;

  /**
   * Constructs a new ThemeInstallController.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer
   *   The theme installer.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ThemeInstallerInterface $theme_installer) {
    $this->configFactory = $config_factory;
    $this->themeInstaller = $theme_installer;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('config.factory'),
      $container->get('theme_installer')
    );
  }

  /**
   * Install a theme as default.
   *
   * @param string $theme
   *   The theme to install as the default theme.
   *
   * @return array
   *   A render array confirming installation.
   */
  public function installDefault(string $theme) {
    return $this->installTheme($theme, 'default');
  }

  /**
   * Install a theme as the admin theme.
   * @param string $theme
   *   The theme to install as the admin theme.
   *
   * @return array
   *   A render array confirming installation.
   */
  public function installAdmin($theme) {
    return $this->installTheme($theme, 'admin');
  }

  /**
   * Installs a theme.
   *
   * @param string $theme
   *   The theme to install.
   * @param string $default_or_admin
   *   Which type of theme to install, can be `default` or `admin`.
   *
   * @return array
   *   A render array confirming installation.
   */
  private function installTheme($theme, $default_or_admin): array {
    assert(in_array($default_or_admin, ['default', 'admin']), 'The $default_or_admin parameter must be `default` or `admin`');
    $config = $this->configFactory->getEditable('system.theme');
    $this->themeInstaller->install([$theme]);
    $config->set($default_or_admin, $theme)->save();
    return [
      '#type' => 'container',
      '#attributes' => ['id' => 'theme-installed'],
      '#markup' => "Installed $theme as $default_or_admin theme",
    ];
  }

}
+106 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  config:
    - field.field.node.article.body
    - field.field.node.article.comment
    - field.field.node.article.field_image
    - field.field.node.article.field_tags
    - image.style.thumbnail
    - node.type.article
  module:
    - comment
    - image
    - path
    - text
id: node.article.default
targetEntityType: node
bundle: article
mode: default
content:
  body:
    type: text_textarea_with_summary
    weight: 1
    region: content
    settings:
      rows: 9
      summary_rows: 3
      placeholder: ''
      show_summary: false
    third_party_settings: {  }
  comment:
    type: comment_default
    weight: 20
    region: content
    settings: {  }
    third_party_settings: {  }
  created:
    type: datetime_timestamp
    weight: 10
    region: content
    settings: {  }
    third_party_settings: {  }
  field_image:
    type: image_image
    weight: 4
    region: content
    settings:
      progress_indicator: throbber
      preview_image_style: thumbnail
    third_party_settings: {  }
  field_tags:
    type: entity_reference_autocomplete_tags
    weight: 3
    region: content
    settings:
      match_operator: CONTAINS
      match_limit: 10
      size: 60
      placeholder: ''
    third_party_settings: {  }
  path:
    type: path
    weight: 30
    region: content
    settings: {  }
    third_party_settings: {  }
  promote:
    type: boolean_checkbox
    weight: 15
    region: content
    settings:
      display_label: true
    third_party_settings: {  }
  status:
    type: boolean_checkbox
    weight: 120
    region: content
    settings:
      display_label: true
    third_party_settings: {  }
  sticky:
    type: boolean_checkbox
    weight: 16
    region: content
    settings:
      display_label: true
    third_party_settings: {  }
  title:
    type: string_textfield
    weight: 0
    region: content
    settings:
      size: 60
      placeholder: ''
    third_party_settings: {  }
  uid:
    type: entity_reference_autocomplete
    weight: 5
    region: content
    settings:
      match_operator: CONTAINS
      match_limit: 10
      size: 60
      placeholder: ''
    third_party_settings: {  }
hidden: {  }
+76 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  config:
    - field.field.node.page.body
    - node.type.page
  module:
    - path
    - text
id: node.page.default
targetEntityType: node
bundle: page
mode: default
content:
  body:
    type: text_textarea_with_summary
    weight: 31
    region: content
    settings:
      rows: 9
      summary_rows: 3
      placeholder: ''
      show_summary: false
    third_party_settings: {  }
  created:
    type: datetime_timestamp
    weight: 10
    region: content
    settings: {  }
    third_party_settings: {  }
  path:
    type: path
    weight: 30
    region: content
    settings: {  }
    third_party_settings: {  }
  promote:
    type: boolean_checkbox
    weight: 15
    region: content
    settings:
      display_label: true
    third_party_settings: {  }
  status:
    type: boolean_checkbox
    weight: 120
    region: content
    settings:
      display_label: true
    third_party_settings: {  }
  sticky:
    type: boolean_checkbox
    weight: 16
    region: content
    settings:
      display_label: true
    third_party_settings: {  }
  title:
    type: string_textfield
    weight: -5
    region: content
    settings:
      size: 60
      placeholder: ''
    third_party_settings: {  }
  uid:
    type: entity_reference_autocomplete
    weight: 5
    region: content
    settings:
      match_operator: CONTAINS
      match_limit: 10
      size: 60
      placeholder: ''
    third_party_settings: {  }
hidden: {  }
Loading