OverrideDisplaysTest.php in Drupal 10
File
core/modules/views_ui/tests/src/Functional/OverrideDisplaysTest.php
View source
<?php
namespace Drupal\Tests\views_ui\Functional;
class OverrideDisplaysTest extends UITestBase {
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$this
->drupalPlaceBlock('page_title_block');
}
public 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
->drupalGet('admin/structure/views/add');
$this
->submitForm($view, 'Save and edit');
$edit = [];
$edit['title'] = $original_title = $this
->randomMachineName(16);
$edit['override[dropdown]'] = 'default';
$this
->drupalGet("admin/structure/views/nojs/display/{$view['id']}/page_1/title");
$this
->submitForm($edit, 'Apply');
$this
->drupalGet("admin/structure/views/view/{$view['id']}/edit/page_1");
$this
->submitForm([], 'Save');
$this
->drupalCreateContentType([
'type' => 'page',
]);
$this
->drupalCreateNode();
$this
->drupalGet($view_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($original_title);
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLink('Place block');
$this
->assertSession()
->pageTextContains($view['label']);
$this
->drupalPlaceBlock("views_block:{$view['id']}-block_1");
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($original_title);
$edit = [];
$edit['title'] = $new_title = $this
->randomMachineName(16);
$edit['override[dropdown]'] = 'page_1';
$this
->drupalGet("admin/structure/views/nojs/display/{$view['id']}/page_1/title");
$this
->submitForm($edit, 'Apply');
$this
->drupalGet("admin/structure/views/view/{$view['id']}/edit/page_1");
$this
->submitForm([], 'Save');
$this
->drupalGet($view_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($new_title);
$this
->assertSession()
->pageTextContains($original_title);
}
public 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
->drupalGet('admin/structure/views/add');
$this
->submitForm($view, 'Save and edit');
$this
->drupalCreateContentType([
'type' => 'page',
]);
$this
->drupalCreateNode();
$this
->drupalGet($view['page[path]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($view['page[title]']);
$this
->assertSession()
->pageTextNotContains($view['block[title]']);
$this
->drupalGet($view['page[feed_properties][path]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($view['page[title]']);
$this
->assertSession()
->responseNotContains($view['block[title]']);
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLink('Place block');
$this
->assertSession()
->pageTextContains($view['label']);
$this
->drupalPlaceBlock("views_block:{$view['id']}-block_1", [
'visibility' => [
'request_path' => [
'pages' => '/' . $view['page[path]'],
'negate' => TRUE,
],
],
]);
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($view['block[title]']);
$this
->assertSession()
->pageTextNotContains($view['page[title]']);
$edit = [];
$edit['title'] = $new_default_title = $this
->randomMachineName(16);
$this
->drupalGet("admin/structure/views/nojs/display/{$view['id']}/page_1/title");
$this
->submitForm($edit, 'Apply');
$this
->drupalGet("admin/structure/views/view/{$view['id']}/edit/page_1");
$this
->submitForm([], 'Save');
$this
->drupalGet($view['page[path]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($new_default_title);
$this
->assertSession()
->pageTextNotContains($view['page[title]']);
$this
->assertSession()
->pageTextNotContains($view['block[title]']);
$this
->drupalGet($view['page[feed_properties][path]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($new_default_title);
$this
->assertSession()
->responseNotContains($view['page[title]']);
$this
->assertSession()
->responseNotContains($view['block[title]']);
$this
->drupalGet('');
$this
->assertSession()
->pageTextNotContains($new_default_title);
$this
->assertSession()
->pageTextNotContains($view['page[title]']);
$this
->assertSession()
->pageTextContains($view['block[title]']);
$edit = [];
$edit['title'] = $new_block_title = $this
->randomMachineName(16);
$this
->drupalGet("admin/structure/views/nojs/display/{$view['id']}/block_1/title");
$this
->submitForm($edit, 'Apply');
$this
->drupalGet("admin/structure/views/view/{$view['id']}/edit/block_1");
$this
->submitForm([], 'Save');
$this
->drupalGet($view['page[path]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($new_default_title);
$this
->drupalGet($view['page[feed_properties][path]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($new_default_title);
$this
->assertSession()
->responseNotContains($new_block_title);
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($new_block_title);
$this
->assertSession()
->pageTextNotContains($view['block[title]']);
}
public 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
->drupalGet('admin/structure/views/add');
$this
->submitForm($view, 'Save and edit');
$edit = [];
$edit['title'] = $this
->randomMachineName();
$edit['override[dropdown]'] = 'default_revert';
$this
->drupalGet("admin/structure/views/nojs/display/{$view['id']}/block_1/title");
$this
->submitForm($edit, 'Apply');
$this
->drupalGet("admin/structure/views/view/{$view['id']}/edit/block_1");
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains($view['page[title]']);
}
}