Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to gin RC11 #808

Merged
merged 12 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"drupal/field_group": "^3.4",
"drupal/focal_point": "2.0.2",
"drupal/facets": "^2.0.6",
"drupal/gin": "3.0-rc9",
"drupal/gin_toolbar": "^1.0-rc5",
"drupal/gin": "3.0-rc11",
"drupal/gin_toolbar": "^1.0-rc6",
"drupal/graphql": "^4.7",
"drupal/inline_entity_form": "^1.0-rc14",
"drupal/ivw_integration": "^2.0",
Expand Down
1 change: 1 addition & 0 deletions config/install/gin.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ focus_color: ''
layout_density: small
show_description_toggle: true
show_user_theme_settings: true
sticky_action_buttons: true
5 changes: 5 additions & 0 deletions modules/thunder_workflow/src/ThunderWorkflowFormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public function moveStateToActions(NodeInterface $entity, array $form): array {
$form['actions']['moderation_state'] = $form['moderation_state'];
unset($form['moderation_state']);

// Promote moderation_state in gin theme to not end up in
// dropdown button.
$form['actions']['moderation_state']['#gin_action_item'] = TRUE;
$form['actions']['moderation_state']['widget'][0]['#attributes']['form'] = $form['#id'];

return $form;
}

Expand Down
52 changes: 21 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit bootstrap="../../../core/tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
failOnWarning="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
cacheResult="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="../../../core/tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" failOnWarning="true" printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" cacheResult="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./includes</directory>
<directory>./lib</directory>
<directory>./modules</directory>
<directory>../modules</directory>
<directory>../sites</directory>
</include>
<exclude>
<directory>./modules/*/src/Tests</directory>
<directory>./modules/*/tests</directory>
<directory>../modules/*/src/Tests</directory>
<directory>../modules/*/tests</directory>
<directory>../modules/*/*/src/Tests</directory>
<directory>../modules/*/*/tests</directory>
</exclude>
</coverage>
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
Expand All @@ -31,11 +41,11 @@
<!-- To disable deprecation testing completely uncomment the next line. -->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
<env name="MINK_DRIVER_CLASS" value=''/>
<env name="MINK_DRIVER_CLASS" value=""/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=''/>
<env name="MINK_DRIVER_ARGS" value=""/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]'/>
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value="[&quot;chrome&quot;, { &quot;chromeOptions&quot;: { &quot;w3c&quot;: false } }, &quot;http://localhost:4444/wd/hub&quot;]"/>
</php>
<testsuites>
<testsuite name="unit">
Expand All @@ -59,24 +69,4 @@
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<filter>
<whitelist>
<directory>./includes</directory>
<directory>./lib</directory>
<!-- Extensions can have their own test directories, so exclude those. -->
<directory>./modules</directory>
<exclude>
<directory>./modules/*/src/Tests</directory>
<directory>./modules/*/tests</directory>
</exclude>
<directory>../modules</directory>
<exclude>
<directory>../modules/*/src/Tests</directory>
<directory>../modules/*/tests</directory>
<directory>../modules/*/*/src/Tests</directory>
<directory>../modules/*/*/tests</directory>
</exclude>
<directory>../sites</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 2 additions & 0 deletions tests/src/Functional/ThunderTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\thunder\Traits\ThunderGinTestTrait;
use Drupal\Tests\thunder\Traits\ThunderTestTrait;
use Prophecy\PhpUnit\ProphecyTrait;

Expand All @@ -15,6 +16,7 @@ abstract class ThunderTestBase extends BrowserTestBase {
use ThunderTestTrait;
use StringTranslationTrait;
use ProphecyTrait;
use ThunderGinTestTrait;

/**
* {@inheritdoc}
Expand Down
6 changes: 4 additions & 2 deletions tests/src/FunctionalJavascript/MediaImageModifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ public function testRemoveAdd(): void {
/** @var \Drupal\file\FileInterface $file */
$file = $media->get($media->getSource()->getConfiguration()['source_field'])->entity;
$this->assertFileExists($file->getFileUri());
$this->getSession()->getPage()->find('css', 'div.gin-sidebar')->clickLink('Delete');
$this->getSession()->getPage()->find('css', '[data-drupal-selector="edit-actions"] .gin-more-actions__trigger')->click();
$this->getSession()->getPage()->find('css', '[data-drupal-selector="edit-actions"]')->clickLink('Delete');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '#drupal-modal'));
$this->assertSession()->fieldNotExists('also_delete_file');
$this->assertSession()->pageTextContains('This action cannot be undone.The file attached to this media is owned by admin so will be retained.');
Role::load(static::$defaultUserRole)->grantPermission('delete any file')->save();
$this->getSession()->reload();
$this->getSession()->getPage()->find('css', 'div.gin-sidebar')->clickLink('Delete');
$this->getSession()->getPage()->find('css', '[data-drupal-selector="edit-actions"] .gin-more-actions__trigger')->click();
$this->getSession()->getPage()->find('css', '[data-drupal-selector="edit-actions"]')->clickLink('Delete');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '#drupal-modal'));
$this->assertSession()->fieldExists('also_delete_file')->check();
Expand Down
110 changes: 110 additions & 0 deletions tests/src/Traits/ThunderGinTestTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Drupal\Tests\thunder\Traits;

use Behat\Mink\Exception\ElementNotFoundException;

/**
* This trait provides overriden functions for the gin theme.
*
* The form_submit function was added to fix
* https://www.drupal.org/project/gin/issues/3455524
* remove after
* https://www.drupal.org/project/drupal/issues/3456202
* has landed.
*/
trait ThunderGinTestTrait {

/**
* Fills and submits a form.
*
* @param array $edit
* Field data in an associative array. Changes the current input fields
* (where possible) to the values indicated.
*
* A checkbox can be set to TRUE to be checked and should be set to FALSE to
* be unchecked.
* @param string $submit
* Value of the submit button whose click is to be emulated. For example,
* 'Save'. The processing of the request depends on this value. For example,
* a form may have one button with the value 'Save' and another button with
* the value 'Delete', and execute different code depending on which one is
* clicked.
* @param string $form_html_id
* (optional) HTML ID of the form to be submitted. On some pages
* there are many identical forms, so just using the value of the submit
* button is not enough. For example: 'trigger-node-presave-assign-form'.
* Note that this is not the Drupal $form_id, but rather the HTML ID of the
* form, which is typically the same thing but with hyphens replacing the
* underscores.
*/
public function submitForm(array $edit, $submit, $form_html_id = NULL): void {
$assert_session = $this->assertSession();
$submit_button = $assert_session->buttonExists($submit);

// Check if button has a form attribute set.
if ($form_id = $submit_button->getAttribute('form')) {
$form = $assert_session->elementExists('xpath', "//form[@id='$form_id']");
$action = $form->getAttribute('action');
}
// Get the form.
elseif (isset($form_html_id)) {
$form = $assert_session->elementExists('xpath', "//form[@id='$form_html_id']");
$submit_button = $assert_session->buttonExists($submit, $form);
$action = $form->getAttribute('action');
}
else {
// Gin Form Test: Change check to include //form
// so we keep the search in scope of a form.
$submit_button = $assert_session->elementExists('xpath', "//input[@value='$submit']");
$form = $assert_session->elementExists('xpath', './ancestor::form', $submit_button);
$action = $form->getAttribute('action');
}

// Edit the form values.
foreach ($edit as $name => $value) {
try {
$field = $assert_session->fieldExists($name, $form);
}
catch (ElementNotFoundException $e) {
$field = $assert_session->fieldExists($name);
}

// Provide support for the values '1' and '0' for checkboxes instead of
// TRUE and FALSE.
// @todo Get rid of supporting 1/0 by converting all tests cases using
// this to boolean values.
$field_type = $field->getAttribute('type');
if ($field_type === 'checkbox') {
$value = (bool) $value;
}
$field->setValue($value);
}

// Submit form.
$this->prepareRequest();
$submit_button->press();

// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();

// Check if there are any meta refresh redirects (like Batch API pages).
if ($this->checkForMetaRefresh()) {
// We are finished with all meta refresh redirects, so reset the counter.
$this->metaRefreshCount = 0;
}

// Log only for WebDriverTestBase tests because for tests using
// DrupalTestBrowser we log with ::getResponseLogHandler.
if ($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()) {
$out = $this->getSession()->getPage()->getContent();
$html_output = 'POST request to: ' . $action .
'<hr />Ending URL: ' . $this->getSession()->getCurrentUrl();
$html_output .= '<hr />' . $out;
$html_output .= $this->getHtmlOutputHeaders();
$this->htmlOutput($html_output);
}

}

}
11 changes: 11 additions & 0 deletions thunder.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,14 @@ function thunder_post_update_0002_enable_paragraphs_split(array &$sandbox): stri
// Output logged messages to related channel of update execution.
return $updater->logger()->output();
}

/**
* Enable sticky action buttons for the Gin theme.
*/
function thunder_post_update_0003_enable_sticky_action_buttons(array &$sandbox): string {
\Drupal::configFactory()->getEditable('gin.settings')
->set('sticky_action_buttons', TRUE)
->save();

return t('Sticky action buttons enabled.');
}
Loading