1 views_ui.test ViewsUIWizardDisplaysTestCase::testOverrideDisplays()

Tests that displays can be overridden via the UI.

File

core/modules/views/tests/views_ui.test, line 746
Tests Views UI Wizard.

Class

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

Code

function testOverrideDisplays() {
  // Create a basic view that shows all content, with a page and a block
  // display.
  $view['human_name'] = $this->randomName(16);
  $view['name'] = strtolower($this->randomName(16));
  $view['page[create]'] = 1;
  $view['page[path]'] = $this->randomName(16);
  $view['block[create]'] = 1;
  $view_path = $view['page[path]'];
  $this->backdropPost('admin/structure/views/add', $view, t('Save & exit'));

  // 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->backdropPost("admin/structure/views/nojs/display/{$view['name']}/page/title", $edit, t('Apply'));
  $this->backdropPost("admin/structure/views/view/{$view['name']}/configure/page", array(), t('Save'));

  // Put the block into the sidebar region, and make sure it will not
  // display on the view's page display (since we will be searching for the
  // presence/absence of the view's title in both the page and the block).
  views_invalidate_cache();
  $layout = layout_load('default');
  $block = $layout->addBlock('views', $view['name'] . '-block', 'sidebar');
  $block->conditions[] = layout_create_access('path', array(
    'settings' => array(
      'visibility_setting' => 0,
      'paths' => $view_path,
    )
  ));
  $layout->save();

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

  // Make sure the title appears in both the page and the block.
  $this->backdropGet($view_path);
  $this->assertText($original_title);
  $this->backdropGet('user');
  $this->assertText($original_title);

  // Change the title for the page display only, and make sure that is the
  // only one that is changed.
  $edit = array();
  $edit['title'] = $new_title = $this->randomName(16);
  $edit['override[dropdown]'] = 'page';
  $this->backdropPost("admin/structure/views/nojs/display/{$view['name']}/page/title", $edit, t('Apply'));
  $this->backdropPost("admin/structure/views/view/{$view['name']}/configure/page", array(), t('Save'));
  $this->backdropGet($view_path);
  $this->assertText($new_title);
  $this->assertNoText($original_title);
  $this->backdropGet('user');
  $this->assertText($original_title);
  $this->assertNoText($new_title);
}