function OverrideDisplaysTest::testOverrideDisplays

Tests that displays can be overridden via the UI.

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/Tests/OverrideDisplaysTest.php, line 26
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 testOverrideDisplays() {

  // Create a basic view that shows all content, with a page and a block
  // display.
  $view['label'] = $this
    ->randomName(16);
  $view['id'] = strtolower($this
    ->randomName(16));
  $view['page[create]'] = 1;
  $view['page[path]'] = $this
    ->randomName(16);
  $view['block[create]'] = 1;
  $view_path = $view['page[path]'];
  $this
    ->drupalPost('admin/structure/views/add', $view, t('Save and edit'));

  // Configure its title. Since the page and block both started off with the
  // same (empty) title in the views wizard, we expect the wizard to have set
  // things up so that they both inherit from the default display, and we
  // therefore only need to change that to have it take effect for both.
  $edit = array();
  $edit['title'] = $original_title = $this
    ->randomName(16);
  $edit['override[dropdown]'] = 'default';
  $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'));

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

  // Make sure the title appears in the page.
  $this
    ->drupalGet($view_path);
  $this
    ->assertResponse(200);
  $this
    ->assertText($original_title);

  // Confirm that the view 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");

  // Make sure the title appears in the block.
  $this
    ->drupalGet('');
  $this
    ->assertText($original_title);

  // Change the title for the page display only, and make sure that the
  // original title still appears on the page.
  $edit = array();
  $edit['title'] = $new_title = $this
    ->randomName(16);
  $edit['override[dropdown]'] = 'page_1';
  $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_path);
  $this
    ->assertResponse(200);
  $this
    ->assertText($new_title);
  $this
    ->assertText($original_title);
}