This commit is contained in:
2020-07-13 17:09:59 +02:00
parent 03559a7b76
commit 3a082e23cc
492 changed files with 4129 additions and 982 deletions
@@ -0,0 +1,36 @@
<?php
namespace Drupal\entity_test\Entity;
use Drupal\Core\Url;
/**
* Test entity class.
*
* @ContentEntityType(
* id = "entity_test_external",
* label = @Translation("Entity test external"),
* base_table = "entity_test_external",
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
* },
* links = {
* "canonical" = "/entity_test_external/{entity_test_external}"
* },
* )
*/
class EntityTestExternal extends EntityTest {
/**
* {@inheritdoc}
*/
public function toUrl($rel = 'canonical', array $options = []) {
if ($rel === 'canonical') {
return Url::fromUri('http://example.com', $options);
}
return parent::toUrl($rel, $options);
}
}
@@ -121,6 +121,7 @@ class FormTestMachineNameValidationForm extends FormBase {
* Loading stub for machine name
*
* @param $machine_name
*
* @return bool
*/
public function load($machine_name) {
@@ -0,0 +1,10 @@
<?php
/**
* @file
* Test module.
*/
use Drupal\module_autoload_test\SomeClass;
define('MODULE_AUTOLOAD_TEST_CONSTANT', SomeClass::TEST);
@@ -4,6 +4,8 @@ namespace Drupal\module_autoload_test;
class SomeClass {
const TEST = '\Drupal\module_autoload_test\SomeClass::TEST';
public function testMethod() {
return 'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.';
}
@@ -78,11 +78,11 @@ class ThemeTestSubscriber implements EventSubscriberInterface {
*/
public function onView(GetResponseEvent $event) {
$current_route = $this->currentRouteMatch->getRouteName();
$entity_autcomplete_route = [
$entity_autocomplete_route = [
'system.entity_autocomplete',
];
if (in_array($current_route, $entity_autcomplete_route)) {
if (in_array($current_route, $entity_autocomplete_route)) {
if ($this->container->initialized('theme.registry')) {
throw new \Exception('registry initialized');
}
@@ -5,7 +5,7 @@ token_test.test:
requirements:
_access: 'TRUE'
token_test.test_without_bubbleable_metadata:
path: token-test-without-bubleable-metadata/{node}
path: token-test-without-bubbleable-metadata/{node}
defaults:
_controller: Drupal\token_test\Controller\TestController::tokenReplaceWithoutPassedBubbleableMetadata
requirements:
@@ -54,14 +54,17 @@ class ProcessingTest extends BrowserTestBase {
// Batch 0: no operation.
$edit = ['batch' => 'batch_0'];
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertNoEscaped('<', 'No escaped markup is present.');
// If there is any escaped markup it will include at least an escaped '<'
// character, so assert on each page that there is no escaped '<' as a way
// of verifying that no markup is incorrectly escaped.
$this->assertNoEscaped('<');
$this->assertBatchMessages($this->_resultMessages('batch_0'), 'Batch with no operation performed successfully.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
// Batch 1: several simple operations.
$edit = ['batch' => 'batch_1'];
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch with simple operations performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
@@ -69,7 +72,7 @@ class ProcessingTest extends BrowserTestBase {
// Batch 2: one multistep operation.
$edit = ['batch' => 'batch_2'];
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
$this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch with multistep operation performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
@@ -77,7 +80,7 @@ class ProcessingTest extends BrowserTestBase {
// Batch 3: simple + multistep combined.
$edit = ['batch' => 'batch_3'];
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
$this->assertBatchMessages($this->_resultMessages('batch_3'), 'Batch with simple and multistep operations performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_3'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
@@ -85,7 +88,7 @@ class ProcessingTest extends BrowserTestBase {
// Batch 4: nested batch.
$edit = ['batch' => 'batch_4'];
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
$this->assertBatchMessages($this->_resultMessages('batch_4'), 'Nested batch performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_4'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
@@ -121,7 +124,7 @@ class ProcessingTest extends BrowserTestBase {
*/
public function testBatchFormMultistep() {
$this->drupalGet('batch-test/multistep');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
$this->assertText('step 1', 'Form is displayed in step 1.');
// First step triggers batch 1.
@@ -129,14 +132,14 @@ class ProcessingTest extends BrowserTestBase {
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 1 performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.');
$this->assertText('step 2', 'Form is displayed in step 2.');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
// Second step triggers batch 2.
$this->drupalPostForm(NULL, [], 'Submit');
$this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch for step 2 performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
$this->assertNoEscaped('<', 'No escaped markup is present.');
$this->assertNoEscaped('<');
// Extra query arguments will trigger logic that will add them to the
// redirect URL. Make sure they are persisted.
@@ -22,6 +22,7 @@ abstract class CacheTestBase extends BrowserTestBase {
* The variable the cache should contain.
* @param $bin
* The bin the cache item was stored in.
*
* @return
* TRUE on pass, FALSE on fail.
*/
@@ -21,7 +21,9 @@ class FormatDateTest extends BrowserTestBase {
*/
public function testAdminDefinedFormatDate() {
// Create and log in an admin user.
$this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
// Add new date format.
$edit = [
@@ -313,6 +313,11 @@ class UrlTest extends BrowserTestBase {
$result = Url::fromUri($url)->toString();
$this->assertEqual($url, $result);
// Verify external URL can contain a query string with an integer key.
$url = $test_url . '?120=1';
$result = Url::fromUri($url)->toString();
$this->assertEqual($url, $result);
// Verify external URL can be extended with a query string.
$url = $test_url;
$query = ['awesome' => 'drupal'];
@@ -48,7 +48,7 @@ class EntityAddUITest extends BrowserTestBase {
// has the necessary permissions.
$this->drupalGet('/entity_test_with_bundle/add');
$this->assertText('There is no test entity bundle yet.');
$this->assertLink('Add a new test entity bundle.');
$this->assertSession()->linkExists('Add a new test entity bundle.');
// One bundle exists, confirm redirection to the add-form.
EntityTestBundle::create([
@@ -67,8 +67,8 @@ class EntityAddUITest extends BrowserTestBase {
])->save();
$this->drupalGet('/entity_test_with_bundle/add');
$this->assertLink('Test label');
$this->assertLink('Test2 label');
$this->assertSession()->linkExists('Test label');
$this->assertSession()->linkExists('Test2 label');
$this->assertText('My test description');
$this->assertText('My test2 description');
@@ -93,9 +93,9 @@ class EntityAddUITest extends BrowserTestBase {
'description' => 'My test3 description',
])->save();
$this->drupalGet('/entity_test_with_bundle/add');
$this->assertLink('Test label');
$this->assertLink('Test2 label');
$this->assertNoLink('Test3 label');
$this->assertSession()->linkExists('Test label');
$this->assertSession()->linkExists('Test2 label');
$this->assertSession()->linkNotExists('Test3 label');
$this->clickLink(t('Test label'));
$this->assertSession()->statusCodeEquals(200);
@@ -114,10 +114,10 @@ class EntityAddUITest extends BrowserTestBase {
// does not have bundle specific permissions. The add bundle message is
// present as the user has bundle create permissions.
$this->drupalGet('/entity_test_with_bundle/add');
$this->assertNoLink('Test label');
$this->assertNoLink('Test2 label');
$this->assertNoLink('Test3 label');
$this->assertLink('Add a new test entity bundle.');
$this->assertSession()->linkNotExists('Test label');
$this->assertSession()->linkNotExists('Test2 label');
$this->assertSession()->linkNotExists('Test3 label');
$this->assertSession()->linkExists('Add a new test entity bundle.');
}
/**
@@ -141,8 +141,8 @@ class EntityAddUITest extends BrowserTestBase {
entity_test_create_bundle('test2', 'Test2 label', 'entity_test_mul');
$this->drupalGet('/entity_test_mul/add');
$this->assertLink('Test label');
$this->assertLink('Test2 label');
$this->assertSession()->linkExists('Test label');
$this->assertSession()->linkExists('Test2 label');
$this->clickLink('Test2 label');
$this->drupalGet('/entity_test_mul/add/test2');
@@ -164,6 +164,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be tested, as created by createEntity().
*
* @return array
* An array of the additional cache tags.
*
@@ -27,7 +27,10 @@ class EntityFormTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(['administer entity_test content', 'view test entity']);
$web_user = $this->drupalCreateUser([
'administer entity_test content',
'view test entity',
]);
$this->drupalLogin($web_user);
// Add a language.
@@ -42,7 +42,7 @@ class EntityOperationsTest extends BrowserTestBase {
$roles = user_roles();
foreach ($roles as $role) {
$this->assertLinkByHref($role->toUrl()->toString() . '/test_operation');
$this->assertLink(new FormattableMarkup('Test Operation: @label', ['@label' => $role->label()]));
$this->assertSession()->linkExists(new FormattableMarkup('Test Operation: @label', ['@label' => $role->label()]));
}
}
@@ -52,7 +52,11 @@ class EntityTranslationFormTest extends BrowserTestBase {
public function testEntityFormLanguage() {
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer content types']);
$web_user = $this->drupalCreateUser([
'create page content',
'edit own page content',
'administer content types',
]);
$this->drupalLogin($web_user);
// Create a node with language LanguageInterface::LANGCODE_NOT_SPECIFIED.
@@ -18,7 +18,9 @@ class ConfigTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
}
/**
@@ -42,7 +42,9 @@ class ElementsVerticalTabsTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access vertical_tab_test tabs']);
$this->adminUser = $this->drupalCreateUser([
'access vertical_tab_test tabs',
]);
$this->webUser = $this->drupalCreateUser();
$this->drupalLogin($this->adminUser);
}
@@ -251,21 +251,27 @@ class FormTest extends BrowserTestBase {
$this->assertSession()
->elementExists('css', 'input[name="form_token"]')
->setValue('invalid token');
$random_string = $this->randomString();
$edit = [
'textfield' => $this->randomString(),
'textfield' => $random_string,
'checkboxes[bar]' => TRUE,
'select' => 'bar',
'radios' => 'foo',
];
$this->drupalPostForm(NULL, $edit, 'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
// Verify that input elements retained the posted values.
$this->assertFieldByName('textfield', $edit['textfield']);
$assert = $this->assertSession();
$element = $assert->fieldExists('textfield');
$this->assertEmpty($element->getValue());
$assert->responseNotContains($random_string);
$this->assertText('The form has become outdated.');
// Ensure that we don't use the posted values.
$this->assertFieldByName('textfield', '');
$this->assertNoFieldChecked('edit-checkboxes-foo');
$this->assertFieldChecked('edit-checkboxes-bar');
$this->assertOptionSelected('edit-select', 'bar');
$this->assertFieldChecked('edit-radios-foo');
$this->assertNoFieldChecked('edit-checkboxes-bar');
$this->assertOptionSelected('edit-select', '');
$this->assertNoFieldChecked('edit-radios-foo');
// Check another form that has a textarea input.
$this->drupalGet(Url::fromRoute('form_test.required'));
@@ -278,9 +284,9 @@ class FormTest extends BrowserTestBase {
];
$this->drupalPostForm(NULL, $edit, 'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
$this->assertFieldByName('textfield', $edit['textfield']);
$this->assertFieldByName('textarea', $edit['textarea']);
$this->assertText('The form has become outdated.');
$this->assertFieldByName('textfield', '');
$this->assertFieldByName('textarea', '');
// Check another form that has a number input.
$this->drupalGet(Url::fromRoute('form_test.number'));
@@ -288,12 +294,14 @@ class FormTest extends BrowserTestBase {
->elementExists('css', 'input[name="form_token"]')
->setValue('invalid token');
$edit = [
'integer_step' => mt_rand(1, 100),
// We choose a random value which is higher than the default value,
// so we don't accidentally generate the default value.
'integer_step' => mt_rand(6, 100),
];
$this->drupalPostForm(NULL, $edit, 'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
$this->assertFieldByName('integer_step', $edit['integer_step']);
$this->assertText('The form has become outdated.');
$this->assertFieldByName('integer_step', 5);
// Check a form with a Url field
$this->drupalGet(Url::fromRoute('form_test.url'));
@@ -305,8 +313,8 @@ class FormTest extends BrowserTestBase {
];
$this->drupalPostForm(NULL, $edit, 'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
$this->assertFieldByName('url', $edit['url']);
$this->assertText('The form has become outdated.');
$this->assertFieldByName('url', '');
}
/**
@@ -27,7 +27,10 @@ class ModulesListFormWebTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();
\Drupal::state()->set('system_test.module_hidden', FALSE);
$this->drupalLogin($this->drupalCreateUser(['administer modules', 'administer permissions']));
$this->drupalLogin($this->drupalCreateUser([
'administer modules',
'administer permissions',
]));
}
/**
@@ -74,7 +74,7 @@ class ValidationTest extends BrowserTestBase {
$this->drupalPostForm(NULL, ['name' => 'validate'], 'Save');
$this->assertNoFieldByName('name', '#value changed by #validate', 'Form element #value was not altered.');
$this->assertNoText('Name value: value changed by setValueForElement() in #validate', 'Form element value in $form_state was not altered.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
$this->assertText('The form has become outdated.');
}
/**
@@ -154,9 +154,9 @@ class BreadcrumbTest extends BrowserTestBase {
$trail = $home;
$this->assertBreadcrumb("node/$nid1", $trail);
// Also verify that the node does not appear elsewhere (e.g., menu trees).
$this->assertNoLink($node1->getTitle());
$this->assertSession()->linkNotExists($node1->getTitle());
// Also verify that the node does not appear elsewhere (e.g., menu trees).
$this->assertNoLink($node1->getTitle());
$this->assertSession()->linkNotExists($node1->getTitle());
$trail += [
"node/$nid1" => $node1->getTitle(),
@@ -286,7 +286,8 @@ class BreadcrumbTest extends BrowserTestBase {
$link_path => $link->getTitle(),
];
$this->assertBreadcrumb($link_path, $trail, $term->getName(), $tree);
$this->assertEscaped($parent->getTitle(), 'Tagged node found.');
// Ensure that the tagged node is found.
$this->assertEscaped($parent->getTitle());
// Additionally make sure that this link appears only once; i.e., the
// untranslated menu links automatically generated from menu router items
@@ -79,7 +79,7 @@ class LocalTasksTest extends BrowserTestBase {
* @return bool
* TRUE if the local task exists on the page.
*/
protected function assertLocalTaskAppers($title) {
protected function assertLocalTaskAppears($title) {
// SimpleXML gives us the unescaped text, not the actual escaped markup,
// so use a pattern instead to check the raw content.
// This behavior is a bug in libxml, see
@@ -116,9 +116,9 @@ class LocalTasksTest extends BrowserTestBase {
// Verify that script tags are escaped on output.
$title = Html::escape("Task 1 <script>alert('Welcome to the jungle!')</script>");
$this->assertLocalTaskAppers($title);
$this->assertLocalTaskAppears($title);
$title = Html::escape("<script>alert('Welcome to the derived jungle!')</script>");
$this->assertLocalTaskAppers($title);
$this->assertLocalTaskAppears($title);
// Verify that local tasks appear as defined in the router.
$this->drupalGet(Url::fromRoute('menu_test.local_task_test_tasks_view'));
@@ -130,7 +130,7 @@ class LocalTasksTest extends BrowserTestBase {
]);
$title = Html::escape("<script>alert('Welcome to the jungle!')</script>");
$this->assertLocalTaskAppers($title);
$this->assertLocalTaskAppears($title);
// Ensure the view tab is active.
$result = $this->xpath('//ul[contains(@class, "tabs")]//li[contains(@class, "active")]/a');
@@ -42,11 +42,11 @@ class MenuAccessTest extends BrowserTestBase {
$this->drupalPlaceBlock('system_menu_block:account');
// Test that there's link rendered on the route.
$this->drupalGet('menu_test_access_check_session');
$this->assertLink('Test custom route access check');
$this->assertSession()->linkExists('Test custom route access check');
// Page is still accessible but there should be no menu link.
$this->drupalGet('menu_test_access_check_session');
$this->assertSession()->statusCodeEquals(200);
$this->assertNoLink('Test custom route access check');
$this->assertSession()->linkNotExists('Test custom route access check');
// Test that page is no more accessible.
$this->drupalGet('menu_test_access_check_session');
$this->assertSession()->statusCodeEquals(403);
@@ -65,10 +65,10 @@ class MenuRouterTest extends BrowserTestBase {
// Confirm correct controller activated.
$this->assertText('test1');
// Confirm local task links are displayed.
$this->assertLink('Local task A');
$this->assertLink('Local task B');
$this->assertNoLink('Local task C');
$this->assertEscaped("<script>alert('Welcome to the jungle!')</script>", ENT_QUOTES, 'UTF-8');
$this->assertSession()->linkExists('Local task A');
$this->assertSession()->linkExists('Local task B');
$this->assertSession()->linkNotExists('Local task C');
$this->assertEscaped("<script>alert('Welcome to the jungle!')</script>");
// Confirm correct local task href.
$this->assertLinkByHref(Url::fromRoute('menu_test.router_test1', ['bar' => $machine_name])->toString());
$this->assertLinkByHref(Url::fromRoute('menu_test.router_test2', ['bar' => $machine_name])->toString());
@@ -2,6 +2,7 @@
namespace Drupal\Tests\system\Functional\Module;
use Drupal\module_autoload_test\SomeClass;
use Drupal\Tests\BrowserTestBase;
/**
@@ -96,4 +97,19 @@ class ClassLoaderTest extends BrowserTestBase {
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('module_install_class_loader_test2'), 'The module_install_class_loader_test2 module has been installed.');
}
/**
* Tests that .module files can use class constants in main section.
*/
public function testAutoloadFromModuleFile() {
$this->assertFalse(defined('MODULE_AUTOLOAD_TEST_CONSTANT'));
$this->drupalLogin($this->rootUser);
$edit = [
"modules[module_autoload_test][enable]" => TRUE,
];
$this->drupalPostForm('admin/modules', $edit, t('Install'));
$this->assertSession()->statusCodeEquals(200);
$this->resetAll();
$this->assertSame(SomeClass::TEST, MODULE_AUTOLOAD_TEST_CONSTANT);
}
}
@@ -29,7 +29,10 @@ class ExperimentalModuleTest extends BrowserTestBase {
*/
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer modules']);
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer modules',
]);
$this->drupalLogin($this->adminUser);
}
@@ -358,7 +358,7 @@ class InstallUninstallTest extends ModuleTestBase {
$this->drupalGet('admin/help/' . $module);
$this->assertSession()->statusCodeEquals(200);
$this->assertText($name . ' module', "'$name module' is on the help page for $module");
$this->assertLink('online documentation for the ' . $name . ' module', 0, "Correct online documentation link is in the help page for $module");
$this->assertSession()->linkExists('online documentation for the ' . $name . ' module', 0, "Correct online documentation link is in the help page for $module");
}
/**
@@ -26,7 +26,10 @@ abstract class ModuleTestBase extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer modules']);
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer modules',
]);
$this->drupalLogin($this->adminUser);
}
@@ -36,7 +36,12 @@ class AccessDeniedTest extends BrowserTestBase {
$this->drupalPlaceBlock('page_title_block');
// Create an administrative user.
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer site configuration', 'link to any page', 'administer blocks']);
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer site configuration',
'link to any page',
'administer blocks',
]);
$this->adminUser->roles[] = 'administrator';
$this->adminUser->save();
@@ -63,7 +63,7 @@ class AdminTest extends BrowserTestBase {
// Verify that all visible, top-level administration links are listed on
// the main administration page.
foreach ($this->getTopLevelMenuLinks() as $item) {
$this->assertLink($item->getTitle());
$this->assertSession()->linkExists($item->getTitle());
$this->assertLinkByHref($item->getUrlObject()->toString());
// The description should appear below the link.
$this->assertText($item->getDescription());
@@ -159,7 +159,8 @@ class DateTimeTest extends BrowserTestBase {
$date_format->save();
$this->drupalGet(Url::fromRoute('entity.date_format.collection'));
$this->assertEscaped("<script>alert('XSS');</script>", 'The date format was properly escaped');
// Ensure that the date format is properly escaped.
$this->assertEscaped("<script>alert('XSS');</script>");
// Add a new date format with HTML in it.
$date_format_id = strtolower($this->randomMachineName(8));
@@ -216,7 +217,9 @@ class DateTimeTest extends BrowserTestBase {
$this->drupalLogout();
// Now log in as a regular editor.
$this->drupalLogin($this->drupalCreateUser(['create page_with_date content']));
$this->drupalLogin($this->drupalCreateUser([
'create page_with_date content',
]));
$this->drupalGet('node/add/page_with_date');
$edit = [
@@ -34,7 +34,10 @@ class PageNotFoundTest extends BrowserTestBase {
parent::setUp();
// Create an administrative user.
$this->adminUser = $this->drupalCreateUser(['administer site configuration', 'link to any page']);
$this->adminUser = $this->drupalCreateUser([
'administer site configuration',
'link to any page',
]);
$this->adminUser->roles[] = 'administrator';
$this->adminUser->save();
@@ -39,7 +39,13 @@ class PageTitleTest extends BrowserTestBase {
$this->drupalPlaceBlock('page_title_block');
$this->contentUser = $this->drupalCreateUser(['create page content', 'access content', 'administer themes', 'administer site configuration', 'link to any page']);
$this->contentUser = $this->drupalCreateUser([
'create page content',
'access content',
'administer themes',
'administer site configuration',
'link to any page',
]);
$this->drupalLogin($this->contentUser);
}
@@ -41,7 +41,10 @@ class SiteMaintenanceTest extends BrowserTestBase {
// Create a user allowed to access site in maintenance mode.
$this->user = $this->drupalCreateUser(['access site in maintenance mode']);
// Create an administrative user.
$this->adminUser = $this->drupalCreateUser(['administer site configuration', 'access site in maintenance mode']);
$this->adminUser = $this->drupalCreateUser([
'administer site configuration',
'access site in maintenance mode',
]);
$this->drupalLogin($this->adminUser);
}
@@ -27,7 +27,9 @@ class SystemAuthorizeTest extends BrowserTestBase {
parent::setUp();
// Create an administrator user.
$this->drupalLogin($this->drupalCreateUser(['administer software updates']));
$this->drupalLogin($this->drupalCreateUser([
'administer software updates',
]));
}
/**
@@ -43,7 +43,13 @@ class ThemeTest extends BrowserTestBase {
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'view the administration theme', 'administer themes', 'bypass node access', 'administer blocks']);
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'view the administration theme',
'administer themes',
'bypass node access',
'administer blocks',
]);
$this->drupalLogin($this->adminUser);
$this->node = $this->drupalCreateNode();
$this->drupalPlaceBlock('local_tasks_block');
@@ -202,16 +208,16 @@ class ThemeTest extends BrowserTestBase {
$this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']);
$this->drupalGet('admin/appearance/settings');
$theme_handler = \Drupal::service('theme_handler');
$this->assertLink($theme_handler->getName('classy'));
$this->assertLink($theme_handler->getName('bartik'));
$this->assertNoLink($theme_handler->getName('stable'));
$this->assertSession()->linkExists($theme_handler->getName('classy'));
$this->assertSession()->linkExists($theme_handler->getName('bartik'));
$this->assertSession()->linkNotExists($theme_handler->getName('stable'));
// If a hidden theme is an admin theme it should be viewable.
\Drupal::configFactory()->getEditable('system.theme')->set('admin', 'stable')->save();
\Drupal::service('router.builder')->rebuildIfNeeded();
$this->drupalPlaceBlock('local_tasks_block', ['region' => 'header', 'theme' => 'stable']);
$this->drupalGet('admin/appearance/settings');
$this->assertLink($theme_handler->getName('stable'));
$this->assertSession()->linkExists($theme_handler->getName('stable'));
$this->drupalGet('admin/appearance/settings/stable');
$this->assertSession()->statusCodeEquals(200);
@@ -38,7 +38,7 @@ class TokenReplaceWebTest extends BrowserTestBase {
$this->assertCacheTags(['node:1', 'rendered', 'user:2']);
$this->assertCacheContexts(['languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user']);
$this->drupalGet('token-test-without-bubleable-metadata/' . $node->id());
$this->drupalGet('token-test-without-bubbleable-metadata/' . $node->id());
$this->assertText("Tokens: {$node->id()} {$account->id()}");
$this->assertCacheTags(['node:1', 'rendered', 'user:2']);
$this->assertCacheContexts(['languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user']);
@@ -108,7 +108,7 @@ class TrustedHostsTest extends BrowserTestBase {
$this->drupalPlaceBlock('shortcuts');
$this->drupalGet('');
$this->assertLink($shortcut->label());
$this->assertSession()->linkExists($shortcut->label());
}
}
@@ -90,7 +90,10 @@ class EntityFilteringThemeTest extends BrowserTestBase {
\Drupal::service('theme_installer')->install(array_keys($this->themes));
// Create a test user.
$this->user = $this->drupalCreateUser(['access content', 'access user profiles']);
$this->user = $this->drupalCreateUser([
'access content',
'access user profiles',
]);
$this->user->name = $this->xssLabel;
$this->user->save();
$this->drupalLogin($this->user);
@@ -28,7 +28,10 @@ class ExperimentalThemeTest extends BrowserTestBase {
*/
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer themes']);
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer themes',
]);
$this->drupalLogin($this->adminUser);
}
@@ -28,7 +28,10 @@ class ThemeTokenTest extends BrowserTestBase {
*/
protected function setUp() {
parent::setUp();
$account = $this->drupalCreateUser(['administer blocks', 'view the administration theme']);
$account = $this->drupalCreateUser([
'administer blocks',
'view the administration theme',
]);
$this->drupalLogin($account);
}
@@ -50,7 +50,9 @@ class InvalidUpdateHookTest extends BrowserTestBase {
require_once $this->root . '/core/includes/update.inc';
$this->updateUrl = $GLOBALS['base_url'] . '/update.php';
$this->updateUser = $this->drupalCreateUser(['administer software updates']);
$this->updateUser = $this->drupalCreateUser([
'administer software updates',
]);
}
public function testInvalidUpdateHook() {
@@ -46,7 +46,9 @@ class UpdatePathLastRemovedTest extends BrowserTestBase {
require_once $this->root . '/core/includes/update.inc';
$this->updateUrl = Url::fromRoute('system.db_update');
$this->updateUser = $this->drupalCreateUser(['administer software updates']);
$this->updateUser = $this->drupalCreateUser([
'administer software updates',
]);
}
/**
@@ -103,7 +103,7 @@ class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest {
// now that we're logged in.
$this->drupalGet('node/8', ['language' => $spanish]);
$this->assertText('Test 12');
$this->assertLink('drupal');
$this->assertSession()->linkExists('drupal');
// Make sure the content for node 8 is still in the edit form.
$this->drupalGet('node/8/edit');
@@ -135,7 +135,7 @@ class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest {
$this->assertText('usuario_test');
$this->assertRaw('druplicon.small');
$this->assertText('Test file field');
$this->assertLink('test.txt');
$this->assertSession()->linkExists('test.txt');
// Make sure the user is translated.
$this->drupalGet('user/3/translations');
@@ -235,24 +235,24 @@ class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest {
$this->drupalGet('admin/structure/types/manage/test_content_type/fields');
// Make sure fields are the right type.
$this->assertLink('Text (formatted, long, with summary)');
$this->assertLink('Boolean');
$this->assertLink('Comments');
$this->assertLink('Date');
$this->assertLink('Email');
$this->assertLink('Link');
$this->assertLink('List (float)');
$this->assertLink('Telephone number');
$this->assertLink('Entity reference');
$this->assertLink('File');
$this->assertLink('Image');
$this->assertLink('Text (plain, long)');
$this->assertLink('List (text)');
$this->assertLink('Text (formatted, long)');
$this->assertLink('Text (plain)');
$this->assertLink('List (integer)');
$this->assertLink('Number (integer)');
$this->assertLink('Number (float)');
$this->assertSession()->linkExists('Text (formatted, long, with summary)');
$this->assertSession()->linkExists('Boolean');
$this->assertSession()->linkExists('Comments');
$this->assertSession()->linkExists('Date');
$this->assertSession()->linkExists('Email');
$this->assertSession()->linkExists('Link');
$this->assertSession()->linkExists('List (float)');
$this->assertSession()->linkExists('Telephone number');
$this->assertSession()->linkExists('Entity reference');
$this->assertSession()->linkExists('File');
$this->assertSession()->linkExists('Image');
$this->assertSession()->linkExists('Text (plain, long)');
$this->assertSession()->linkExists('List (text)');
$this->assertSession()->linkExists('Text (formatted, long)');
$this->assertSession()->linkExists('Text (plain)');
$this->assertSession()->linkExists('List (integer)');
$this->assertSession()->linkExists('Number (integer)');
$this->assertSession()->linkExists('Number (float)');
// Make sure our form mode exists.
$this->drupalGet('admin/structure/display-modes/form');
@@ -327,7 +327,7 @@ class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest {
// Make sure the terms are still translated.
$this->drupalGet('taxonomy/term/2/translations');
$this->assertLink('Test root term - Spanish');
$this->assertSession()->linkExists('Test root term - Spanish');
// Make sure our contact form exists.
$this->drupalGet('admin/structure/contact');
@@ -56,7 +56,9 @@ class UpdateRemovedPostUpdateTest extends BrowserTestBase {
->execute();
$this->updateUrl = Url::fromRoute('system.db_update');
$this->updateUser = $this->drupalCreateUser(['administer software updates']);
$this->updateUser = $this->drupalCreateUser([
'administer software updates',
]);
}
/**
@@ -45,7 +45,10 @@ class UpdateSchemaTest extends BrowserTestBase {
parent::setUp();
require_once $this->root . '/core/includes/update.inc';
$this->user = $this->drupalCreateUser(['administer software updates', 'access site in maintenance mode']);
$this->user = $this->drupalCreateUser([
'administer software updates',
'access site in maintenance mode',
]);
$this->updateUrl = Url::fromRoute('system.db_update');
}
@@ -86,7 +86,7 @@ class UpdateScriptTest extends BrowserTestBase {
// Check that a link to the update page is not accessible to regular users.
$this->drupalGet('/update-script-test/database-updates-menu-item');
$this->assertNoLink('Run database updates');
$this->assertSession()->linkNotExists('Run database updates');
// Try accessing update.php as an anonymous user.
$this->drupalLogout();
@@ -96,7 +96,7 @@ class UpdateScriptTest extends BrowserTestBase {
// Check that a link to the update page is not accessible to anonymous
// users.
$this->drupalGet('/update-script-test/database-updates-menu-item');
$this->assertNoLink('Run database updates');
$this->assertSession()->linkNotExists('Run database updates');
// Access the update page with the proper permission.
$this->drupalLogin($this->updateUser);
@@ -106,7 +106,7 @@ class UpdateScriptTest extends BrowserTestBase {
// Check that a link to the update page is accessible to users with proper
// permissions.
$this->drupalGet('/update-script-test/database-updates-menu-item');
$this->assertLink('Run database updates');
$this->assertSession()->linkExists('Run database updates');
// Access the update page as user 1.
$this->drupalLogin($this->rootUser);
@@ -115,7 +115,7 @@ class UpdateScriptTest extends BrowserTestBase {
// Check that a link to the update page is accessible to user 1.
$this->drupalGet('/update-script-test/database-updates-menu-item');
$this->assertLink('Run database updates');
$this->assertSession()->linkExists('Run database updates');
}
/**
@@ -519,19 +519,22 @@ class UpdateScriptTest extends BrowserTestBase {
$this->updateRequirementsProblem();
$this->clickLink(t('Continue'));
$this->assertText(t('No pending updates.'));
$this->assertNoLink('Administration pages');
$this->assertSession()->linkNotExists('Administration pages');
$this->assertEmpty($this->xpath('//main//a[contains(@href, :href)]', [':href' => 'update.php']));
$this->clickLink('Front page');
$this->assertSession()->statusCodeEquals(200);
// Click through update.php with 'access administration pages' permission.
$admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages']);
$admin_user = $this->drupalCreateUser([
'administer software updates',
'access administration pages',
]);
$this->drupalLogin($admin_user);
$this->drupalGet($this->updateUrl, ['external' => TRUE]);
$this->updateRequirementsProblem();
$this->clickLink(t('Continue'));
$this->assertText(t('No pending updates.'));
$this->assertLink('Administration pages');
$this->assertSession()->linkExists('Administration pages');
$this->assertEmpty($this->xpath('//main//a[contains(@href, :href)]', [':href' => 'update.php']));
$this->clickLink('Administration pages');
$this->assertSession()->statusCodeEquals(200);
@@ -558,7 +561,12 @@ class UpdateScriptTest extends BrowserTestBase {
// Click through update.php with 'access administration pages' and
// 'access site reports' permissions.
$admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages', 'access site reports', 'access site in maintenance mode']);
$admin_user = $this->drupalCreateUser([
'administer software updates',
'access administration pages',
'access site reports',
'access site in maintenance mode',
]);
$this->drupalLogin($admin_user);
$this->drupalGet($this->updateUrl, ['external' => TRUE]);
$this->updateRequirementsProblem();
@@ -566,8 +574,8 @@ class UpdateScriptTest extends BrowserTestBase {
$this->clickLink(t('Apply pending updates'));
$this->checkForMetaRefresh();
$this->assertText('Updates were attempted.');
$this->assertLink('logged');
$this->assertLink('Administration pages');
$this->assertSession()->linkExists('logged');
$this->assertSession()->linkExists('Administration pages');
$this->assertEmpty($this->xpath('//main//a[contains(@href, :href)]', [':href' => 'update.php']));
$this->clickLink('Administration pages');
$this->assertSession()->statusCodeEquals(200);
@@ -617,7 +625,13 @@ class UpdateScriptTest extends BrowserTestBase {
$this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
// Create admin user.
$admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages', 'access site reports', 'access site in maintenance mode', 'administer site configuration']);
$admin_user = $this->drupalCreateUser([
'administer software updates',
'access administration pages',
'access site reports',
'access site in maintenance mode',
'administer site configuration',
]);
$this->drupalLogin($admin_user);
// Visit status report page and ensure, that link to update.php has no path prefix set.
@@ -634,8 +648,8 @@ class UpdateScriptTest extends BrowserTestBase {
$this->clickLink(t('Apply pending updates'));
$this->checkForMetaRefresh();
$this->assertText('Updates were attempted.');
$this->assertLink('logged');
$this->assertLink('Administration pages');
$this->assertSession()->linkExists('logged');
$this->assertSession()->linkExists('Administration pages');
$this->assertEmpty($this->xpath('//main//a[contains(@href, :href)]', [':href' => 'update.php']));
$this->clickLink('Administration pages');
$this->assertSession()->statusCodeEquals(200);
@@ -686,7 +700,7 @@ class UpdateScriptTest extends BrowserTestBase {
// Verify that updates were completed successfully.
$this->assertText('Updates were attempted.');
$this->assertLink('site');
$this->assertSession()->linkExists('site');
$this->assertText('The update_script_test_update_8001() update was executed successfully.');
// Verify that no 7.x updates were run.
@@ -694,9 +708,9 @@ class UpdateScriptTest extends BrowserTestBase {
$this->assertNoText('The update_script_test_update_7201() update was executed successfully.');
// Verify that there are no links to different parts of the workflow.
$this->assertNoLink('Administration pages');
$this->assertSession()->linkNotExists('Administration pages');
$this->assertEmpty($this->xpath('//main//a[contains(@href, :href)]', [':href' => 'update.php']));
$this->assertNoLink('logged');
$this->assertSession()->linkNotExists('logged');
// Verify the front page can be visited following the upgrade.
$this->clickLink('Front page');
@@ -43,7 +43,9 @@ class UpdatesWith7xTest extends BrowserTestBase {
parent::setUp();
require_once $this->root . '/core/includes/update.inc';
$this->updateUrl = $GLOBALS['base_url'] . '/update.php';
$this->updateUser = $this->drupalCreateUser(['administer software updates']);
$this->updateUser = $this->drupalCreateUser([
'administer software updates',
]);
}
public function testWith7x() {
@@ -29,7 +29,9 @@ class DateFormatTest extends WebDriverTestBase {
parent::setUp();
// Create admin user and log in admin user.
$this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
$this->drupalPlaceBlock('local_actions_block');
}