Skip to content
Snippets Groups Projects
Commit f0340fc7 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3468758: Add a gitlab file + opt into D11

parent 3402043f
No related branches found
No related tags found
1 merge request!14Issue #3468758: Add a gitlab file + opt into D11
Pipeline #257353 canceled
################
# GitLabCI template for Drupal projects.
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification.
# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your
# pipelines automatically. However, you can modify this template if you have additional needs for your project.
# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/
################
# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/
# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml
include:
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- "/includes/include.drupalci.main.yml"
- "/includes/include.drupalci.variables.yml"
- "/includes/include.drupalci.workflows.yml"
################
# Pipeline configuration variables are defined with default values and descriptions in the file
# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
# Uncomment the lines below if you want to override any of the variables. The following is just an example.
################
variables:
_CSPELL_WORDS: 'FORMID, webform'
# SKIP_ESLINT: '1'
OPT_IN_TEST_PREVIOUS_MINOR: '1'
OPT_IN_TEST_NEXT_MINOR: '1'
OPT_IN_TEST_NEXT_MAJOR: '1'
......@@ -14,5 +14,7 @@
"issues": "https://drupal.org/project/issues/formdazzle",
"source": "https://git.drupalcode.org/project/formdazzle"
},
"require": {}
"require": {
"drupal/core": "^10 || ^11"
}
}
name: 'Formdazzle!'
type: module
description: 'Provides a set of utilities that make form theming easier.'
core_version_requirement: ^9 || ^10
php: 8.0
core_version_requirement: ^10 || ^11
......@@ -22,7 +22,7 @@ class Dazzler implements RenderCallbackInterface {
* @param string $form_id
* The form id.
*/
public static function formAlter(array &$form, string $form_id) {
public static function formAlter(array &$form, string $form_id): void {
// Instead of altering the form now, we wait until all hook_form_alter
// functions are completed and make our changes during the #pre_render
// phase of Drupal\Core\Render\Renderer::render().
......@@ -144,7 +144,7 @@ class Dazzler implements RenderCallbackInterface {
* @param string $form_id_suggestion
* A suggestion to use based on the form ID.
*/
public static function traverse(array &$element, string $form_id, string $form_id_suggestion) {
public static function traverse(array &$element, string $form_id, string $form_id_suggestion): void {
// Add the default info for the #type of form element.
self::addDefaultThemeProperties($element);
......@@ -168,7 +168,7 @@ class Dazzler implements RenderCallbackInterface {
* @param array $element
* The form or form element.
*/
public static function addDefaultThemeProperties(array &$element) {
public static function addDefaultThemeProperties(array &$element): void {
if (isset($element['#type'])) {
$default_theme_properties = array_intersect_key(
\Drupal::service('element_info')->getInfo($element['#type']),
......@@ -188,7 +188,7 @@ class Dazzler implements RenderCallbackInterface {
* @param string $form_id_suggestion
* A suggestion to use based on the form ID.
*/
public static function addSuggestions(array &$element, string $form_id, string $form_id_suggestion) {
public static function addSuggestions(array &$element, string $form_id, string $form_id_suggestion): void {
$needs_theme_suggestion = isset($element['#theme']);
$needs_theme_wrapper_suggestion = isset($element['#theme_wrappers']);
......@@ -340,7 +340,7 @@ class Dazzler implements RenderCallbackInterface {
* @param array $variables
* The variables that will be passed to the form_element Twig template.
*/
public static function preprocessFormElement(array &$variables) {
public static function preprocessFormElement(array &$variables): void {
if (isset($variables['element']['#formdazzle'])) {
$suggestion_suffix = $variables['element']['#formdazzle']['suggestion_suffix'];
......@@ -362,7 +362,7 @@ class Dazzler implements RenderCallbackInterface {
* @param string $hook
* The name of the module hook being implemented.
*/
public static function moduleImplementsAlter(array &$implementations, string $hook) {
public static function moduleImplementsAlter(array &$implementations, string $hook): void {
if ($hook === 'form_alter') {
$group = $implementations['formdazzle'];
unset($implementations['formdazzle']);
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\formdazzle\Unit;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Render\Markup;
use Drupal\formdazzle\Dazzler;
......@@ -20,13 +21,6 @@ class DazzlerTest extends UnitTestCase {
*/
protected $elementInfoManager;
/**
* Form element fixtures.
*
* @var array
*/
protected $fixtures;
/**
* {@inheritdoc}
*/
......@@ -48,13 +42,12 @@ class DazzlerTest extends UnitTestCase {
/**
* Initializes the mocked element info manager.
*/
public function initElementInfoManager() {
public function initElementInfoManager(): void {
if (is_null($this->elementInfoManager)) {
$this->elementInfoManager = $this->createMock('\Drupal\Core\Render\ElementInfoManagerInterface');
$this->elementInfoManager
->method('getInfo')
->will(
$this->returnValueMap([
->willReturnMap([
['no_theme_defaults', ['#fixture' => TRUE]],
[
'mixed_defaults',
......@@ -77,8 +70,7 @@ class DazzlerTest extends UnitTestCase {
'#theme_wrappers' => ['form'],
],
],
])
);
]);
}
}
......@@ -91,12 +83,9 @@ class DazzlerTest extends UnitTestCase {
* @return array
* The fixture.
*/
protected function getFixture($name) {
// Setting up fixtures as a class member variable can't be done during
// Setup() because dataProvider functions are run before Setup().
if (is_null($this->fixtures)) {
protected static function getFixture(string $name): array {
// Form element fixtures.
$this->fixtures = [
$fixtures = [
'no_theme_defaults' => [
'#type' => 'no_theme_defaults',
],
......@@ -131,18 +120,17 @@ class DazzlerTest extends UnitTestCase {
],
],
];
$this->fixtures += $form_fixtures;
$fixtures = array_merge($fixtures, $form_fixtures);
foreach (array_keys($form_fixtures) as $form_id) {
// All our form fixtures share this structure.
$this->fixtures[$form_id] += [
$fixtures[$form_id] += [
'#type' => 'form',
'#form_id' => $form_id,
'#theme' => [$form_id],
];
}
}
return $this->fixtures[$name];
return $fixtures[$name];
}
/**
......@@ -151,10 +139,10 @@ class DazzlerTest extends UnitTestCase {
* @return string
* The test message to use.
*/
public function getTestMessage() {
public function getTestMessage(): string {
return preg_replace_callback('/^test(.)([^ ]+)/', function ($matches) {
return Dazzler::class . '::' . strtolower($matches[1]) . $matches[2] . '()';
}, $this->getName());
}, 'DazzlerTest');
}
/**
......@@ -166,7 +154,7 @@ class DazzlerTest extends UnitTestCase {
* @return \Drupal\Component\Render\MarkupInterface|string
* The Twig debug comment.
*/
public function getTwigDebugComment(array $templates) {
public static function getTwigDebugComment(array $templates): MarkupInterface|string {
return Markup::create(PHP_EOL . PHP_EOL
. '<!-- THEME DEBUG -->' . PHP_EOL
. '<!-- THEME HOOK: No templates found. -->' . PHP_EOL
......@@ -191,11 +179,11 @@ class DazzlerTest extends UnitTestCase {
*
* @see testFormAlter()
*/
public function providerFormAlter() {
public static function providerFormAlter(): array {
$data = [];
$class = 'Drupal\formdazzle\Dazzler';
$actual = $this->getFixture('simple_form');
$actual = self::getFixture('simple_form');
$expected = $actual + [
'#pre_render' => [[$class, 'preRenderForm']],
'#formdazzle' => ['form_id' => 'a_form_id'],
......@@ -206,7 +194,8 @@ class DazzlerTest extends UnitTestCase {
$expected,
];
$actual = $this->getFixture('simple_form') + [
$actual = self::getFixture('simple_form') + [
// @phpstan-ignore-next-line
'#pre_render' => ['some_pre_render'],
];
$expected = $actual + [
......@@ -240,14 +229,14 @@ class DazzlerTest extends UnitTestCase {
*
* @see testPreRenderForm()
*/
public function providerPreRenderForm() {
public static function providerPreRenderForm(): array {
$data = [];
// Basic test.
$form = [
'#form_id' => 'a_form_id',
'#theme' => ['a_form_id'],
] + $this->getFixture('with_child');
] + self::getFixture('with_child');
Dazzler::formAlter($form, 'a_form_id');
$expected = $form;
$expected['#theme_wrappers'] = ['form__a_form_id'];
......@@ -256,7 +245,7 @@ class DazzlerTest extends UnitTestCase {
'#theme' => 'with_theme__a_form_id',
'#theme_wrappers' => ['with_theme_wrapper__a_form_id'],
];
$expected['#markup'] = $this->getTwigDebugComment(['a-form-id.html.twig']);
$expected['#markup'] = self::getTwigDebugComment(['a-form-id.html.twig']);
unset($expected['#formdazzle']);
$data['adds suggestions to the entire form'] = [
$form,
......@@ -264,11 +253,11 @@ class DazzlerTest extends UnitTestCase {
];
// Node edit form.
$form = $this->getFixture('node_article_edit_form');
$form = self::getFixture('node_article_edit_form');
Dazzler::formAlter($form, 'node_article_edit_form');
$expected = $form + [
'#theme_wrappers' => ['form__node_article_edit_form'],
'#markup' => $this->getTwigDebugComment([
'#markup' => self::getTwigDebugComment([
'node-article-edit-form.html.twig',
'node-form.html.twig',
]),
......@@ -280,12 +269,12 @@ class DazzlerTest extends UnitTestCase {
];
// Form with #theme as string.
$form = $this->getFixture('node_article_edit_form');
$form = self::getFixture('node_article_edit_form');
$form['#theme'] = 'node_form__article__edit';
Dazzler::formAlter($form, 'node_article_edit_form');
$expected = $form + [
'#theme_wrappers' => ['form__node_article_edit_form'],
'#markup' => $this->getTwigDebugComment([
'#markup' => self::getTwigDebugComment([
'node-form--article--edit.html.twig',
'node-form--article.html.twig',
'node-form.html.twig',
......@@ -298,14 +287,14 @@ class DazzlerTest extends UnitTestCase {
];
// Form that has not had Dazzler::formAlter() run on it.
$form = $this->getFixture('with_child');
$form = self::getFixture('with_child');
$data['does not alter forms lacking #formdazzle data'] = [
$form,
$form,
];
// Form that has incorrect #formdazzle data in it.
$form = $this->getFixture('with_child') + [
$form = self::getFixture('with_child') + [
'#formdazzle' => [
'not_form_id' => TRUE,
],
......@@ -335,15 +324,15 @@ class DazzlerTest extends UnitTestCase {
*
* @see testRepeatedPreRenderFormCalls()
*/
public function providerRepeatedPreRenderFormCalls() {
public static function providerRepeatedPreRenderFormCalls(): array {
$data = [];
// Node edit form.
$form = $this->getFixture('with_child');
$form = self::getFixture('with_child');
Dazzler::formAlter($form, 'with_child');
$expected = $form + [
'#theme_wrappers' => ['form__with_child'],
'#markup' => $this->getTwigDebugComment(['with-child.html.twig']),
'#markup' => self::getTwigDebugComment(['with-child.html.twig']),
];
$expected['child'] = [
'#type' => 'with_theme_and_wrappers',
......@@ -398,7 +387,7 @@ class DazzlerTest extends UnitTestCase {
*
* @see testGetFormIdSuggestion()
*/
public function providerGetFormIdSuggestion() {
public static function providerGetFormIdSuggestion(): array {
return [
'simple form ID' => [['#theme' => ['form_id']], 'form_id', 'form_id'],
'webform submission form' => [
......@@ -445,14 +434,14 @@ class DazzlerTest extends UnitTestCase {
*
* @see testFormAlter()
*/
public function providerTraverse() {
public static function providerTraverse(): array {
// Initial form.
$form_id = 'simple_form';
$form_suggestion = 'a_form_suggestion';
$form = $this->getFixture($form_id) + [
'parent' => $this->getFixture('with_theme_and_wrappers') + [
$form = self::getFixture($form_id) + [
'parent' => self::getFixture('with_theme_and_wrappers') + [
'#parents' => ['parent'],
'child' => $this->getFixture('with_theme') + [
'child' => self::getFixture('with_theme') + [
'#parents' => ['parent', 'child'],
],
],
......@@ -489,30 +478,30 @@ class DazzlerTest extends UnitTestCase {
*
* @see testAddDefaultThemeProperties()
*/
public function providerAddDefaultThemeProperties() {
public static function providerAddDefaultThemeProperties(): array {
return [
'Ignores non-theme defaults (#1)' => [
$this->getFixture('no_theme_defaults'),
$this->getFixture('no_theme_defaults'),
self::getFixture('no_theme_defaults'),
self::getFixture('no_theme_defaults'),
],
'Ignores non-theme defaults (#2)' => [
$this->getFixture('mixed_defaults'),
$this->getFixture('mixed_defaults') + ['#theme' => 'mixed_defaults'],
self::getFixture('mixed_defaults'),
self::getFixture('mixed_defaults') + ['#theme' => 'mixed_defaults'],
],
'Adds #theme #theme_wrappers defaults' => [
$this->getFixture('with_theme_and_wrappers'),
$this->getFixture('with_theme_and_wrappers') + [
self::getFixture('with_theme_and_wrappers'),
self::getFixture('with_theme_and_wrappers') + [
'#theme' => 'with_theme',
'#theme_wrappers' => ['with_theme_wrapper'],
],
],
'Does not override existing properties' => [
$this->getFixture('no_default_overrides'),
$this->getFixture('no_default_overrides'),
self::getFixture('no_default_overrides'),
self::getFixture('no_default_overrides'),
],
'Does not add defaults for non-#type elements' => [
$this->getFixture('no_type'),
$this->getFixture('no_type'),
self::getFixture('no_type'),
self::getFixture('no_type'),
],
];
}
......@@ -532,7 +521,7 @@ class DazzlerTest extends UnitTestCase {
*
* @see testAddSuggestions()
*/
public function providerAddSuggestions() {
public static function providerAddSuggestions(): array {
return [
'no suggestion needed' => [
[
......@@ -643,14 +632,14 @@ class DazzlerTest extends UnitTestCase {
],
'ensure valid name #theme suggestion' => [
[
'#name' => 'Element Key.Val[grey-box][a1/bü]',
'#name' => 'Element Key.Val[gray-box][a1/bü]',
'#theme' => 'theme_hook',
],
'form_id',
'form_suggestion',
[
'#name' => 'Element Key.Val[grey-box][a1/bü]',
'#theme' => 'theme_hook__form_suggestion__element_key_val_grey_box_a1_b',
'#name' => 'Element Key.Val[gray-box][a1/bü]',
'#theme' => 'theme_hook__form_suggestion__element_key_val_gray_box_a1_b',
],
],
'add type-based #theme suggestion (unknown)' => [
......@@ -881,7 +870,7 @@ class DazzlerTest extends UnitTestCase {
*
* @dataProvider providerPreprocessFormElement
*/
public function testPreprocessFormElement(array $variables, array $expected) {
public function testPreprocessFormElement(array $variables, array $expected): void {
Dazzler::preprocessFormElement($variables);
$this->assertEquals($expected, $variables, $this->getTestMessage());
}
......@@ -891,7 +880,7 @@ class DazzlerTest extends UnitTestCase {
*
* @see testPreprocessFormElement()
*/
public function providerPreprocessFormElement() {
public static function providerPreprocessFormElement(): array {
$variables = [
'element' => [
'#formdazzle' => [
......@@ -926,7 +915,7 @@ class DazzlerTest extends UnitTestCase {
*
* @dataProvider providerModuleImplementsAlter
*/
public function testModuleImplementsAlter(array $implementations, string $hook, array $expected) {
public function testModuleImplementsAlter(array $implementations, string $hook, array $expected): void {
Dazzler::moduleImplementsAlter($implementations, $hook);
$this->assertEquals(
array_keys($expected),
......@@ -940,7 +929,7 @@ class DazzlerTest extends UnitTestCase {
*
* @see testModuleImplementsAlter()
*/
public function providerModuleImplementsAlter() {
public static function providerModuleImplementsAlter(): array {
$implementations = [
'media_library' => FALSE,
'menu_ui' => FALSE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment