function NodeDeleteConfirmTest::testNodeDelete

Same name and namespace in other branches
  1. 11.x 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 48

Class

NodeDeleteConfirmTest
Tests JavaScript functionality specific to delete operations.

Namespace

Drupal\Tests\node\FunctionalJavascript

Code

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->waitForText('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->waitForText('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');
  $this->assertSession()
    ->pageTextContains('The Article Delete article from entity form has been deleted.');
  // Assert that the node is deleted in above operation.
  $this->drupalGet('/admin/content');
  $assert_session->waitForText('There are no content items yet.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.