Skip to content
Snippets Groups Projects
Commit 2ee51299 authored by Ide Braakman's avatar Ide Braakman
Browse files

Issue #3419586: Customizations for comment delete form interfere with Core's...

Issue #3419586: Customizations for comment delete form interfere with Core's delete modal in the admin UI
parent fe950447
Branches 8.x-1.x
1 merge request!25Issue #3419586: Customizations for comment delete form interfere with Core's...
Pipeline #303117 passed with warnings
......@@ -76,6 +76,11 @@ class AjaxCommentsDeleteForm extends DeleteForm {
$this->tempStore->getSelectors($request, $overwrite = TRUE);
$wrapper_html_id = $this->tempStore->getSelectorValue($request, 'wrapper_html_id');
// Return the original form if the required attribute is missing.
if (empty($wrapper_html_id)) {
return $form;
}
// Add the wrapping fields's HTML id as a hidden input
// so we can access it in the controller.
$form['wrapper_html_id'] = [
......
......@@ -64,7 +64,7 @@ class TempStore {
public function getSelectorValue(Request $request, $selector) {
$selectors = $this->getSelectors($request);
$value = $selectors[$selector];
return substr($value, strpos($value, '#') + 1);
return $value ? substr($value, strpos($value, '#') + 1) : $value;
}
/**
......
......@@ -9,7 +9,11 @@ use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\NodeInterface;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;
use Drupal\views\Views;
/**
* Javascript functional tests for ajax comments.
......@@ -27,6 +31,20 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* A test node to which comments will be posted.
*
* @var \Drupal\node\NodeInterface
*/
protected NodeInterface $node;
/**
* An administrative user with permission to configure comment settings.
*
* @var \Drupal\user\UserInterface
*/
protected UserInterface $adminUser;
/**
* {@inheritdoc}
*/
......@@ -63,12 +81,7 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
$renderer = $entity_view_display->getRenderer('comment');
$renderer->setThirdPartySetting('ajax_comments', 'enable_ajax_comments', '1');
$entity_view_display->save();
}
/**
* Tests that comments can be posted and edited over ajax without errors.
*/
public function testCommentPosting() {
$format = FilterFormat::create([
'format' => $this->randomMachineName(),
'name' => $this->randomString(),
......@@ -77,7 +90,7 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
]);
$format->save();
$admin_user = $this->drupalCreateUser([
$this->adminUser = $this->drupalCreateUser([
'access content',
'access comments',
// Usernames aren't shown in comment edit form autocomplete unless this
......@@ -89,13 +102,19 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
'skip comment approval',
$format->getPermissionName(),
]);
$this->drupalLogin($admin_user);
$node = $this->drupalCreateNode([
$this->node = $this->drupalCreateNode([
'type' => 'article',
'comment' => CommentItemInterface::OPEN,
]);
$this->drupalGet($node->toUrl());
}
/**
* Tests that comments can be posted and edited over ajax without errors.
*/
public function testCommentPosting() {
$this->drupalLogin($this->adminUser);
$this->drupalGet($this->node->toUrl());
$page = $this->getSession()->getPage();
......@@ -175,7 +194,7 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
// Test removing the role's permission to post comments.
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = Role::loadMultiple($admin_user->getRoles());
$roles = Role::loadMultiple($this->adminUser->getRoles());
foreach ($roles as $role) {
$role->revokePermission('post comments')->save();
}
......@@ -195,20 +214,20 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
// Restore the user's permission to post comments, and reload the page
// so that the reply links are visible.
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = Role::loadMultiple($admin_user->getRoles());
$roles = Role::loadMultiple($this->adminUser->getRoles());
foreach ($roles as $role) {
$role->grantPermission('post comments')->save();
}
$this->refreshVariables();
// Reload the page.
$this->drupalGet($node->toUrl());
$this->drupalGet($this->node->toUrl());
$reply_link = $page->findLink('Reply');
$this->assertNotNull($reply_link);
// Revoke the user's permission to post comments, again.
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = Role::loadMultiple($admin_user->getRoles());
$roles = Role::loadMultiple($this->adminUser->getRoles());
foreach ($roles as $role) {
$role->revokePermission('post comments')->save();
}
......@@ -225,14 +244,14 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
// Again, restore the user's permission to post comments, and
// reload the page so that the reply links are visible.
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = Role::loadMultiple($admin_user->getRoles());
$roles = Role::loadMultiple($this->adminUser->getRoles());
foreach ($roles as $role) {
$role->grantPermission('post comments')->save();
}
$this->refreshVariables();
// Reload the page.
$this->drupalGet($node->toUrl());
$this->drupalGet($this->node->toUrl());
// Click the link to reply to a comment.
$this->clickLink('Reply');
......@@ -243,7 +262,7 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
// Revoke the user's permission to post comments without reloading the page.
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = Role::loadMultiple($admin_user->getRoles());
$roles = Role::loadMultiple($this->adminUser->getRoles());
foreach ($roles as $role) {
$role->revokePermission('post comments')->save();
}
......@@ -258,4 +277,41 @@ class AjaxCommentsFunctionalTest extends WebDriverTestBase {
$this->assertSession()->waitForText('You do not have permission to post a comment.');
}
/**
* Tests the administrative interface with Ajax Comments.
*/
public function testAdminInterface(): void {
// @todo remove toolbar dependency once #3464431 is resolved.
\Drupal::service('module_installer')->install([
'toolbar',
'views',
]);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
'access toolbar',
]);
$view = Views::getView('comment');
$view->storage->enable()->save();
\Drupal::service('router.builder')->rebuildIfNeeded();
$this->drupalLogin($this->adminUser);
$this->drupalGet($this->node->toUrl());
$comment_form = $this->assertSession()->waitForElement('css', 'form.comment-form');
$comment_form->findField('comment_body[0][value]')->setValue('Test comment');
$comment_form->pressButton('Save');
$this->assertSession()->waitForElement('css', "#comment-1");
$this->drupalGet('admin/content/comment');
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$page->find('css', '.dropbutton-toggle button')->click();
$page->clickLink('Delete');
$this->assertEquals('Are you sure you want to delete the comment Test comment?', $assert_session->waitForElement('css', '.ui-dialog-title')->getText());
$page->find('css', '.ui-dialog-buttonset')->pressButton('Delete');
$this->assertSession()->pageTextContains('The comment and all its replies have been deleted.');
$this->assertSession()->pageTextContains('No comments available.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment