View source
<?php
namespace Drupal\views_ui\Tests;
class OverrideDisplaysTest extends UITestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
function testOverrideDisplays() {
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['page[create]'] = 1;
$view['page[path]'] = $this
->randomMachineName(16);
$view['block[create]'] = 1;
$view_path = $view['page[path]'];
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$edit = array();
$edit['title'] = $original_title = $this
->randomMachineName(16);
$edit['override[dropdown]'] = 'default';
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
$this
->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", array(), t('Save'));
$this
->drupalCreateContentType(array(
'type' => 'page',
));
$this
->drupalCreateNode();
$this
->drupalGet($view_path);
$this
->assertResponse(200);
$this
->assertText($original_title);
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLinkPartialName('Place block');
$this
->assertText($view['label']);
$this
->drupalPlaceBlock("views_block:{$view['id']}-block_1");
$this
->drupalGet('');
$this
->assertText($original_title);
$edit = array();
$edit['title'] = $new_title = $this
->randomMachineName(16);
$edit['override[dropdown]'] = 'page_1';
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
$this
->drupalPostForm("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);
}
function testWizardMixedDefaultOverriddenDisplays() {
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['page[create]'] = 1;
$view['page[title]'] = $this
->randomMachineName(16);
$view['page[path]'] = $this
->randomMachineName(16);
$view['page[feed]'] = 1;
$view['page[feed_properties][path]'] = $this
->randomMachineName(16);
$view['block[create]'] = 1;
$view['block[title]'] = $this
->randomMachineName(16);
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->drupalCreateContentType(array(
'type' => 'page',
));
$this
->drupalCreateNode();
$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]']);
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLinkPartialName('Place block');
$this
->assertText($view['label']);
$this
->drupalPlaceBlock("views_block:{$view['id']}-block_1", array(
'visibility' => array(
'request_path' => array(
'pages' => '/' . $view['page[path]'],
'negate' => TRUE,
),
),
));
$this
->drupalGet('');
$this
->assertText($view['block[title]']);
$this
->assertNoText($view['page[title]']);
$edit = array();
$edit['title'] = $new_default_title = $this
->randomMachineName(16);
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
$this
->drupalPostForm("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
->assertNoText($view['block[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
->assertNoText($new_default_title);
$this
->assertNoText($view['page[title]']);
$this
->assertText($view['block[title]']);
$edit = array();
$edit['title'] = $new_block_title = $this
->randomMachineName(16);
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
$this
->drupalPostForm("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]']);
}
function testRevertAllDisplays() {
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['page[create]'] = 1;
$view['page[title]'] = $this
->randomMachineName(16);
$view['page[path]'] = $this
->randomMachineName(16);
$view['block[create]'] = 1;
$view['block[title]'] = $this
->randomMachineName(16);
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$edit = array();
$edit['title'] = $new_block_title = $this
->randomMachineName();
$edit['override[dropdown]'] = 'default_revert';
$this
->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
$this
->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/block_1", array(), t('Save'));
$this
->assertText($view['page[title]']);
}
}