You are here

public function DisplayCRUDTest::testRemoveDisplay in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views_ui/tests/src/Functional/DisplayCRUDTest.php \Drupal\Tests\views_ui\Functional\DisplayCRUDTest::testRemoveDisplay()
  2. 10 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 60

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';
  $this
    ->drupalGet($path_prefix . '/default');
  $this
    ->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is no delete button on the default display.');
  $this
    ->drupalGet($path_prefix . '/page_1');
  $this
    ->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is a delete button on the page display.');

  // Delete the page, so we can test the undo process.
  $this
    ->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
  $this
    ->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'Undo delete of Page', 'Make sure there a undo button on the page display after deleting.');
  $element = $this
    ->xpath('//a[contains(@href, :href) and contains(@class, :class)]', [
    ':href' => $path_prefix . '/page_1',
    ':class' => 'views-display-deleted-link',
  ]);
  $this
    ->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.');
  $element = $this
    ->xpath('//a[contains(@href, :href) and contains(@class, :class)]', [
    ':href' => $path_prefix . '/page_1',
    ':class' => 'views-display-deleted-link',
  ]);
  $this
    ->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.');

  // Undo the deleting of the display.
  $this
    ->drupalPostForm($path_prefix . '/page_1', [], 'Undo delete of Page');
  $this
    ->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'Undo delete of Page', 'Make sure there is no undo button on the page display after reverting.');
  $this
    ->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-delete', 'Delete Page', 'Make sure there is a delete button on the page display after the reverting.');

  // Now delete again and save the view.
  $this
    ->drupalPostForm($path_prefix . '/page_1', [], 'Delete Page');
  $this
    ->drupalPostForm(NULL, [], t('Save'));
  $this
    ->assertNoLinkByHref($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
    ->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/display_id", [
    'display_id' => $machine_name,
  ], 'Apply');
  $this
    ->drupalPostForm(NULL, [], 'Delete Page');
  $this
    ->drupalPostForm(NULL, [], t('Save'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertNoLinkByHref($path_prefix . '/new_machine_name', 'Make sure there is no display tab for the deleted display.');
}