Skip to content
Snippets Groups Projects
Commit be199674 authored by Project Update Bot's avatar Project Update Bot Committed by Damien McKenna
Browse files

Issue #3298040 by Project Update Bot, DamienMcKenna: Automated Drupal 10 compatibility fixes.

parent a7c059e8
No related branches found
No related tags found
2 merge requests!3Resolve #3464729 "Pathvalidator is deprecated",!1Resolve #3344154 "Readme.txt to readme.md"
Set_Front_Page 8.x-1.x-dev, 2023-xx-xx
--------------------------------------
#3150993 by DamienMcKenna: D9 test.
#3150993 by DamienMcKenna: D9 test fix.
#3298040 by Project Update Bot, DamienMcKenna: Automated Drupal 10
compatibility fixes.
Set_Front_Page 8.x-1.0-rc1, 2020-06-11
......
site_frontpage_default: ""
types: { }
......@@ -2,4 +2,4 @@ name: Set Front Page
description: "Simple module for assigning the current page as the site's front page"
type: module
configure: set_front_page.settings
core_version_requirement: ^8 || ^9
core_version_requirement: ^9.1 || ^10
......@@ -102,8 +102,14 @@ class SetFrontPageConfigForm extends ConfigFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->setFrontPageManager->getConfig();
$frontpage = $this->setFrontPageManager->getFrontPage();
$frontpage_alias = $frontpage ? $this->aliasManager->getAliasByPath($config['frontpage']) : $frontpage;
$frontpage_alias = $frontpage = $this->setFrontPageManager->getFrontPage() ?? '';
if (!empty($frontpage)) {
$frontpage_alias = $this->aliasManager->getAliasByPath($frontpage);
// If there's no alias, just use the raw URL.
if (empty($frontpage_alias)) {
$frontpage_alias = $frontpage;
}
}
$form['site_frontpage'] = [
'#type' => 'textfield',
......
......@@ -22,7 +22,7 @@ class SetFrontPageTests extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['views', 'node', 'set_front_page'];
protected static $modules = ['views', 'node', 'set_front_page'];
/**
* The node object that is created for testing.
......@@ -48,7 +48,7 @@ class SetFrontPageTests extends BrowserTestBase {
/**
* {@inheritDoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
// Create admin user, log in admin user, and create one node.
......@@ -72,98 +72,148 @@ class SetFrontPageTests extends BrowserTestBase {
public function testSetFrontPageConfig() {
// Test default homepage.
$this->drupalGet('');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->titleEquals('Home | Drupal');
// Change the front page to an invalid path.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit = ['site_frontpage' => '/kittens'];
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage']]));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains((string) new FormattableMarkup("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage']]));
// Change the front page to a valid path without a starting slash.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit = ['site_frontpage' => $this->nodePath];
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains((string) new FormattableMarkup("The path '@path' has to start with a slash.", ['@path' => $edit['site_frontpage']]));
// Change the front page to a valid path.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit['site_frontpage'] = '/' . $this->nodePath;
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t('The configuration options have been saved.'), 'The configuration have been saved.');
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The configuration options have been saved.');
// The homepage is $this->node and its title changed.
$this->drupalGet('');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->titleEquals($this->node->getTitle() . ' | Drupal');
// Configure a default frontpage path with an invalid path.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit = ['site_frontpage_default' => '/kittens'];
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage_default']]));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains((string) new FormattableMarkup("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage_default']]));
// Configure a default frontpage path with a valid path without starting
// slash.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit = ['site_frontpage_default' => $this->nodePath];
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains((string) new FormattableMarkup("The path '@path' has to start with a slash.", ['@path' => $edit['site_frontpage_default']]));
// Change the default front page to a valid path.
$edit['site_frontpage_default'] = '/node'; // . $this->nodePath;
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t('The configuration options have been saved.'));
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit['site_frontpage_default'] = '/node';
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The configuration options have been saved.');
// The set frontpage tab is not accessible by this user, because the
// content type is not enabled in the set front page configuration.
$this->drupalGet($this->nodePath . '/set_front_page');
$this->assertSession()->statusCodeEquals(403, 'The set front page is not available to the user');
$this->assertSession()->statusCodeEquals(403);
// Enabled valid content type to be an homepage.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit['set_front_page_node_type__page'] = TRUE;
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t('The configuration options have been saved.'));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The configuration options have been saved.');
// The set frontpage tab is accessible by this user
$this->drupalGet($this->nodePath . '/set_front_page');
$this->assertSession()->statusCodeEquals(200, 'The set front page is available to the user');
$this->assertSession()->statusCodeEquals(200);
// The corrent node is the frontpage so the save button is disabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-save" and @type="submit" and @disabled="disabled"]')), 'The "Use this page as the front page" button is present and disabled.');
return;
// The default buttons is enabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-change-to-default" and @type="submit" and not(@disabled)]')), 'The "Revert to the default page" button is present and enabled.');
// In the content type blog the set frontpage is not enabled.
$blog_node = $this->drupalCreateNode(['type' => 'blog', 'promote' => 1]);
// The set frontpage tab is not accessible by this user
$this->drupalGet('node/' . $blog_node->id() . '/set_front_page');
$this->assertSession()->statusCodeEquals(403, 'The set front page is not available to the user');
$this->assertSession()->statusCodeEquals(403);
// Create a new node.
$node = $this->drupalCreateNode(['type' => 'page', 'promote' => 1]);
// The set frontpage tab is accessible by this user
$this->drupalGet('node/' . $node->id() . '/set_front_page');
$this->assertSession()->statusCodeEquals(200, 'The set front page is available to the user');
$this->assertSession()->statusCodeEquals(200);
// The frontapge is not the current node, so is enabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-save" and @type="submit" and not(@disabled)]')), 'The "Use this page as the front page" button is present and enabled.');
// The default buttons is enabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-change-to-default" and @type="submit" and not(@disabled)]')), 'The "Revert to the default page" button is present and enabled.');
// Change the front page to $node.
$this->drupalPostForm('node/' . $node->id() . '/set_front_page', [], t('Use this page as the front page'));
$this->drupalGet('node/' . $node->id() . '/set_front_page');
$this->assertSession()->statusCodeEquals(200);
$this->submitForm([], t('Use this page as the front page'));
$this->assertSession()->statusCodeEquals(200);
// The frontapge is the current node, so is disabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-save" and @type="submit" and @disabled="disabled"]')), 'The "Use this page as the front page" button is present and disabled.');
// The default buttons is enabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-change-to-default" and @type="submit" and not(@disabled)]')), 'The "Revert to the default page" button is present and enabled.');
// Confirm that the front page is set to the new node.
$this->drupalGet('');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->titleEquals($node->getTitle() . ' | Drupal');
// Change the default frontpage path.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit = ['site_frontpage_default' => '/' . $this->nodePath];
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t('The configuration options have been saved.'));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$this->drupalGet($this->nodePath . '/set_front_page');
$this->assertSession()->statusCodeEquals(200, 'The set front page is available to the user');
$this->assertSession()->statusCodeEquals(200);
// The current node is the frontpage so disable the save button.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-save" and @type="submit" and not(@disabled)]')), 'The "Use this page as the front page" button is present and enabled.');
// The current node is the default frontpage so the button is disabled.
$this->assertTrue(!empty($this->xpath('//input[@id="edit-change-to-default" and @type="submit" and @disabled = "disabled"]')), 'The "Revert to the default page" button is present and disabled.');
// If the default frontpage path is not defined, the related button should
// disappear.
$this->drupalGet('admin/config/set_front_page/settings');
$this->assertSession()->statusCodeEquals(200);
$edit = ['site_frontpage_default' => ''];
$this->drupalPostForm('admin/config/set_front_page/settings', $edit, t('Save configuration'));
$this->assertSession()->pageTextContains(t('The configuration options have been saved.'));
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$this->drupalGet($this->nodePath . '/set_front_page');
$this->assertSession()->statusCodeEquals(200);
$this->assertTrue(empty($this->xpath('//input[@id="edit-change-to-default" and @type="submit"]')), 'The "Revert to the default page" button is not present.');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment