diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..29f47394d47522534dda7fd4f42aa5854aa7f77d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +################ +# 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: +# SKIP_ESLINT: '1' + OPT_IN_TEST_NEXT_MAJOR: '1' +# _CURL_TEMPLATES_REF: 'main' + diff --git a/composer.json b/composer.json index 3f0a0fe10b405dfd12efebfaf06a65f73194eef7..5eb718ac54905adbd8a17df7bfa2cd6cec40fd5a 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,6 @@ } ], "require": { - "drupal/core": "^8.8 || ^9 || ^10" + "drupal/redirect": "^1.0" } } diff --git a/redirect_message.info.yml b/redirect_message.info.yml index 614665477f35b30bfa149443b8fa9521b6d69204..6b1839fd4d0ac26adeb50af8edc8162d085467d7 100644 --- a/redirect_message.info.yml +++ b/redirect_message.info.yml @@ -4,4 +4,6 @@ description: Allows to add a message for redirects. core_version_requirement: ^8.8 || ^9 || ^10 dependencies: - - drupal:redirect + - redirect:redirect + - drupal:options + - drupal:text diff --git a/src/tests/src/Functional/RedirectMessageFunctionalTest.php b/src/tests/src/Functional/RedirectMessageFunctionalTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0e66fa266f23b194443808b7a36e6bb6cf7a0b46 --- /dev/null +++ b/src/tests/src/Functional/RedirectMessageFunctionalTest.php @@ -0,0 +1,106 @@ +<?php + +namespace Drupal\Tests\redirect_message\Functional; + +use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Tests\BrowserTestBase; + +/** + * Tests the redirect message functionality. + * + * @group redirect_message + */ +class RedirectMessageFunctionalTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'text', + 'options', + 'redirect', + 'redirect_message', + ]; + + /** + * A user with permissions to work with Redirects. + * + * @var \Drupal\user\UserInterface + */ + protected $redirectUser; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + // Log in as a content author who can create articles and use the revive + // field. + $this->redirectUser = $this->drupalCreateUser([ + 'administer redirects', + ]); + $this->drupalLogin($this->redirectUser); + } + + /** + * Test that saving a redirect with a message will show. + * + * @dataProvider providerStatusMessageTypes + */ + public function testRedirectMessageIsShown($type) { + // Add the redirect. + $this->drupalGet('admin/config/search/redirect/add'); + $sourceUrl = 'redirect-with-' . $type . '-message'; + $message = 'Check out my ' . $type . ' redirect message!'; + $edit = [ + 'redirect_source[0][path]' => $sourceUrl, + 'redirect_redirect[0][uri]' => '<front>', + 'message[0][value]' => $message, + 'message_type' => $type, + ]; + $this->submitForm($edit, 'Save'); + + // Open the redirect and verify the message appears. + $this->drupalGet($sourceUrl); + $this->assertSession()->statusMessageContains($message, $type); + } + + /** + * Test that not setting a redirect message does not trigger a message. + */ + public function testNoRedirectMessage() { + // Add the redirect. + $this->drupalGet('admin/config/search/redirect/add'); + $sourceUrl = 'redirect-no-message'; + $edit = [ + 'redirect_source[0][path]' => $sourceUrl, + 'redirect_redirect[0][uri]' => '<front>', + ]; + $this->submitForm($edit, 'Save'); + + // Open the redirect and verify the message appears. + $this->drupalGet($sourceUrl); + $this->assertSession()->statusMessageNotExists(); + } + + /** + * Provides the different status message types. + * + * @return array + * Status message types. + */ + public static function providerStatusMessageTypes(): array { + return [ + [MessengerInterface::TYPE_STATUS], + [MessengerInterface::TYPE_WARNING], + [MessengerInterface::TYPE_ERROR], + ]; + } + +}