You are here

public function DisplayCRUDTest::testRemoveDisplay in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views_ui/tests/src/Functional/DisplayCRUDTest.php \Drupal\Tests\views_ui\Functional\DisplayCRUDTest::testRemoveDisplay()

Tests removing a display.

File

core/modules/views_ui/tests/src/Functional/DisplayCRUDTest.php, line 61

Class

DisplayCRUDTest
Tests creation, retrieval, updating, and deletion of displays in the Web UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testRemoveDisplay() {
  $view = $this
    ->randomView();
  $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';

  // Make sure there is no delete button on the default display.
  $this
    ->drupalGet($path_prefix . '/default');
  $this
    ->assertSession()
    ->buttonNotExists('edit-displays-settings-settings-content-tab-content-details-top-actions-delete');
  $this
    ->drupalGet($path_prefix . '/page_1');
  $this
    ->assertSession()
    ->buttonExists('edit-displays-settings-settings-content-tab-content-details-top-actions-delete');

  // Delete the page, so we can test the undo process.
  $this
    ->drupalGet($path_prefix . '/page_1');
  $this
    ->submitForm([], 'Delete Page');
  $this
    ->assertSession()
    ->buttonExists('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete');

  // Test that the display link is marked as to be deleted.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[contains(@href, '{$path_prefix}/page_1') and contains(@class, 'views-display-deleted-link')]");

  // Undo the deleting of the display.
  $this
    ->drupalGet($path_prefix . '/page_1');
  $this
    ->submitForm([], 'Undo delete of Page');
  $this
    ->assertSession()
    ->buttonNotExists('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete');
  $this
    ->assertSession()
    ->buttonExists('edit-displays-settings-settings-content-tab-content-details-top-actions-delete');

  // Now delete again and save the view.
  $this
    ->drupalGet($path_prefix . '/page_1');
  $this
    ->submitForm([], 'Delete Page');
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->linkByHrefNotExists($path_prefix . '/page_1', 'Make sure there is no display tab for the deleted display.');

  // Test deleting a display that has a modified machine name.
  $view = $this
    ->randomView();
  $machine_name = 'new_machine_name';
  $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';
  $this
    ->drupalGet("admin/structure/views/nojs/display/{$view['id']}/page_1/display_id");
  $this
    ->submitForm([
    'display_id' => $machine_name,
  ], 'Apply');
  $this
    ->submitForm([], 'Delete Page');
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->linkByHrefNotExists($path_prefix . '/new_machine_name', 'Make sure there is no display tab for the deleted display.');
}