function NodeDeleteConfirmTest::testNodeDelete
Same name in other branches
- 10 core/modules/node/tests/src/FunctionalJavascript/NodeDeleteConfirmTest.php \Drupal\Tests\node\FunctionalJavascript\NodeDeleteConfirmTest::testNodeDelete()
Tests that the node delete operation opens in a modal.
File
-
core/
modules/ node/ tests/ src/ FunctionalJavascript/ NodeDeleteConfirmTest.php, line 49
Class
- NodeDeleteConfirmTest
- Tests JavaScript functionality specific to delete operations.
Namespace
Drupal\Tests\node\FunctionalJavascriptCode
public function testNodeDelete() : void {
$page = $this->getSession()
->getPage();
$assert_session = $this->assertSession();
// Test the delete operation on an item in admin/content .
$node = $this->createNode([
'type' => 'article',
'title' => 'Delete article from content list',
]);
$node->save();
$this->drupalGet('admin/content');
$page->find('css', '.dropbutton-toggle button')
->click();
$page->clickLink('Delete');
// Asserts a dialog opens with the expected text.
$this->assertEquals('Are you sure you want to delete the content item Delete article from content list?', $assert_session->waitForElement('css', '.ui-dialog-title')
->getText());
$page->find('css', '.ui-dialog-buttonset')
->pressButton('Delete');
$assert_session->pageTextContains('The Article Delete article from content list has been deleted.');
// Assert that the node is deleted in above operation.
$this->drupalGet('admin/content');
$assert_session->pageTextContains('There are no content items yet.');
$node = $this->createNode([
'type' => 'article',
'title' => 'Delete article from entity form',
]);
$node->save();
// Tests the delete modal on its entity form.
$this->drupalGet('node/2/edit');
$this->clickLink('Delete');
$this->assertEquals('Are you sure you want to delete the content item Delete article from entity form?', $assert_session->waitForElement('css', '.ui-dialog-title')
->getText());
$page->find('css', '.ui-dialog-buttonset')
->pressButton('Delete');
$assert_session->pageTextContains('The Article Delete article from entity form has been deleted.');
$node = $this->createNode([
'type' => 'article',
'title' => 'Delete article from views entity operations',
]);
$node->save();
\Drupal::service('module_installer')->install([
'views',
]);
$view = Views::getView('content');
$view->storage
->enable()
->save();
\Drupal::service('router.builder')->rebuildIfNeeded();
$this->drupalGet('admin/content');
$page->find('css', '.dropbutton-toggle button')
->click();
$page->clickLink('Delete');
// Asserts a dialog opens with the expected text.
$this->assertEquals('Are you sure you want to delete the content item Delete article from views entity operations?', $assert_session->waitForElement('css', '.ui-dialog-title')
->getText());
$page->find('css', '.ui-dialog-buttonset')
->pressButton('Delete');
$assert_session->pageTextContains('The Article Delete article from views entity operations has been deleted.');
$assert_session->pageTextContains('No content available.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.