function OverrideDisplaysTest::testWizardMixedDefaultOverriddenDisplays

Tests that the wizard correctly sets up default and overridden displays.

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/Tests/OverrideDisplaysTest.php, line 83
Contains \Drupal\views_ui\Tests\OverrideDisplaysTest.

Class

OverrideDisplaysTest
Tests that displays can be correctly overridden via the user interface.

Namespace

Drupal\views_ui\Tests

Code

function testWizardMixedDefaultOverriddenDisplays() {

  // Create a basic view with a page, block, and feed. Give the page and feed
  // identical titles, but give the block a different one, so we expect the
  // page and feed to inherit their titles from the default display, but the
  // block to override it.
  $view['label'] = $this
    ->randomName(16);
  $view['id'] = strtolower($this
    ->randomName(16));
  $view['page[create]'] = 1;
  $view['page[title]'] = $this
    ->randomName(16);
  $view['page[path]'] = $this
    ->randomName(16);
  $view['page[feed]'] = 1;
  $view['page[feed_properties][path]'] = $this
    ->randomName(16);
  $view['block[create]'] = 1;
  $view['block[title]'] = $this
    ->randomName(16);
  $this
    ->drupalPost('admin/structure/views/add', $view, t('Save and edit'));

  // Add a node that will appear in the view, so that the block will actually
  // be displayed.
  $this
    ->drupalCreateNode();

  // Make sure that the feed, page and block all start off with the correct
  // titles.
  $this
    ->drupalGet($view['page[path]']);
  $this
    ->assertResponse(200);
  $this
    ->assertText($view['page[title]']);
  $this
    ->assertNoText($view['block[title]']);
  $this
    ->drupalGet($view['page[feed_properties][path]']);
  $this
    ->assertResponse(200);
  $this
    ->assertText($view['page[title]']);
  $this
    ->assertNoText($view['block[title]']);

  // Confirm that the block is available in the block administration UI.
  $this
    ->drupalGet('admin/structure/block/list/block_plugin_ui:' . config('system.theme')
    ->get('default') . '/add');
  $this
    ->assertText('View: ' . $view['label']);

  // Place the block.
  $this
    ->drupalPlaceBlock("views_block:{$view['id']}-block_1");
  $this
    ->drupalGet('');
  $this
    ->assertText($view['block[title]']);
  $this
    ->assertNoText($view['page[title]']);

  // Edit the page and change the title. This should automatically change
  // the feed's title also, but not the block.
  $edit = array();
  $edit['title'] = $new_default_title = $this
    ->randomName(16);
  $this
    ->drupalPost("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
  $this
    ->drupalPost("admin/structure/views/view/{$view['id']}/edit/page_1", array(), t('Save'));
  $this
    ->drupalGet($view['page[path]']);
  $this
    ->assertResponse(200);
  $this
    ->assertText($new_default_title);
  $this
    ->assertNoText($view['page[title]']);
  $this
    ->drupalGet($view['page[feed_properties][path]']);
  $this
    ->assertResponse(200);
  $this
    ->assertText($new_default_title);
  $this
    ->assertNoText($view['page[title]']);
  $this
    ->assertNoText($view['block[title]']);
  $this
    ->drupalGet('');
  $this
    ->assertText($view['block[title]']);
  $this
    ->assertNoText($new_default_title);
  $this
    ->assertNoText($view['page[title]']);

  // Edit the block and change the title. This should automatically change
  // the block title only, and leave the defaults alone.
  $edit = array();
  $edit['title'] = $new_block_title = $this
    ->randomName(16);
  $this
    ->drupalPost("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
  $this
    ->drupalPost("admin/structure/views/view/{$view['id']}/edit/block_1", array(), t('Save'));
  $this
    ->drupalGet($view['page[path]']);
  $this
    ->assertResponse(200);
  $this
    ->assertText($new_default_title);
  $this
    ->drupalGet($view['page[feed_properties][path]']);
  $this
    ->assertResponse(200);
  $this
    ->assertText($new_default_title);
  $this
    ->assertNoText($new_block_title);
  $this
    ->drupalGet('');
  $this
    ->assertText($new_block_title);
  $this
    ->assertNoText($view['block[title]']);
}