Same filename in this branch
- 10 core/modules/views/tests/src/Functional/DefaultViewsTest.php
- 10 core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
Same filename and directory in other branches
- 8.9.x core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
- 9 core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
Namespace
Drupal\Tests\views_ui\Functional
File
core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\views_ui\Functional;
use Drupal\Core\Url;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
class DefaultViewsTest extends UITestBase {
public static $testViews = [
'test_view_status',
'test_page_display_menu',
'test_page_display_arguments',
];
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$this
->placeBlock('page_title_block');
}
public function testDefaultViews() {
$edit_href = 'admin/structure/views/view/glossary';
$this
->drupalGet('admin/structure/views');
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Enable', '/glossary/');
$this
->assertSession()
->addressEquals('admin/structure/views');
$this
->assertSession()
->linkByHrefExists($edit_href);
$new_title = $this
->randomMachineName(16);
$edit = [
'title' => $new_title,
];
$this
->drupalGet('admin/structure/views/nojs/display/glossary/page_1/title');
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/glossary/edit/page_1');
$this
->submitForm([], 'Save');
$this
->drupalGet('glossary');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($new_title);
$this
->drupalGet('admin/structure/views/nojs/display/archive/page_1/title');
$this
->submitForm([], 'Apply');
$this
->drupalGet('admin/structure/views/view/archive/edit/page_1');
$this
->submitForm([], 'Save');
$this
->drupalGet('admin/structure/views');
$this
->assertSession()
->linkByHrefExists('admin/structure/views/view/archive/enable');
$this
->clickViewsOperationLink('Enable', '/archive/');
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Duplicate', '/glossary');
$edit = [
'id' => 'duplicate_of_glossary',
];
$this
->assertSession()
->titleEquals('Duplicate of Glossary | Drupal');
$this
->submitForm($edit, 'Duplicate');
$this
->assertSession()
->addressEquals('admin/structure/views/view/duplicate_of_glossary');
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Duplicate', '/glossary');
$random_name = $this
->randomMachineName();
$this
->submitForm([
'id' => $random_name,
], 'Duplicate');
$this
->assertSession()
->addressEquals("admin/structure/views/view/{$random_name}");
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Disable', '/glossary/');
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Enable', '/glossary/');
$this
->assertSession()
->addressEquals('admin/structure/views');
$this
->assertSession()
->linkByHrefExists($edit_href);
Role::load(RoleInterface::ANONYMOUS_ID)
->revokePermission('access content')
->save();
$this
->drupalLogout();
$this
->drupalGet('glossary');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet('archive');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogin($this->fullAdminUser);
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Delete', '/glossary/');
$this
->submitForm([], 'Delete');
$this
->assertSession()
->addressEquals('admin/structure/views');
$this
->assertSession()
->linkByHrefNotExists($edit_href);
$this
->drupalGet($edit_href);
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('Page not found');
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Delete', 'duplicate_of_glossary');
$this
->submitForm([], 'Delete');
$this
->drupalGet('glossary');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('admin/structure/views');
$this
->clickViewsOperationLink('Delete', $random_name);
$this
->submitForm([], 'Delete');
$this
->drupalGet('glossary');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('Page not found');
}
public function testSplitListing() {
$this
->drupalGet('admin/structure/views');
$this
->assertSession()
->elementNotExists('xpath', '//div[@id="views-entity-list"]/div[@class = "views-list-section enabled"]/table//td/text()[contains(., "test_view_status")]');
$this
->assertSession()
->elementsCount('xpath', '//div[@id="views-entity-list"]/div[@class = "views-list-section disabled"]/table//td/text()[contains(., "test_view_status")]', 1);
$this
->clickViewsOperationLink('Enable', '/test_view_status/');
$this
->assertSession()
->elementNotExists('xpath', '//div[@id="views-entity-list"]/div[@class = "views-list-section disabled"]/table//td/text()[contains(., "test_view_status")]');
$this
->assertSession()
->elementsCount('xpath', '//div[@id="views-entity-list"]/div[@class = "views-list-section enabled"]/table//td/text()[contains(., "test_view_status")]', 1);
$this
->drupalGet('admin/structure/views/view/test_view_status/disable');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testPathDestination() {
$this
->drupalGet('admin/structure/views');
$this
->assertSession()
->linkByHrefExists('test_page_display_menu');
$this
->assertSession()
->linkByHrefNotExists('test_page_display_menu/default');
$this
->assertSession()
->linkByHrefExists('test_page_display_menu/local');
$this
->assertSession()
->responseContains('test_route_with_suffix/%/suffix');
$this
->assertSession()
->linkByHrefNotExists(Url::fromUri('base:test_route_with_suffix/%/suffix')
->toString());
}
public function clickViewsOperationLink($label, $unique_href_part) {
$this
->assertSession()
->elementExists('xpath', "//a[normalize-space(text())='{$label}' and contains(@href, '{$unique_href_part}')]")
->click();
}
}
Classes
Name |
Description |
DefaultViewsTest |
Tests enabling, disabling, and reverting default views via the listing page. |