// Create a Tools menu link for 'node', move the last parent node menu
// link below it, and verify a full breadcrumb for the last child node.
$menu = 'tools'; $edit = [ 'title[0][value]' => 'Root', 'link[0][uri]' => '/node', ]; $this->drupalGet("admin/structure/menu/manage/{$menu}/add"); $this->submitForm($edit, 'Save'); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => 'Root']); $link = reset($menu_links);
// Create a node with two revisions, the initial one belonging to the
// cancelling user.
$revision_node = $this->drupalCreateNode(['uid' => $account->id()]); $revision = $revision_node->getRevisionId(); $settings = get_object_vars($revision_node); $settings['revision'] = 1; // Set new/current revision to someone else.
$settings['uid'] = 1;
// Attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall'); // Assert forum is still required.
$this->assertSession()->fieldDisabled('uninstall[forum]'); $this->assertSession()->pageTextContains('To uninstall Forum, first delete all Forums terms');
// Delete any forum terms.
$vid = $this->config('forum.settings')->get('vocabulary'); $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); $terms = $storage->loadByProperties(['vid' => $vid]); $storage->delete($terms);
// Ensure that the forum node type can not be deleted.
$this->drupalGet('admin/structure/types/manage/forum'); $this->assertSession()->linkNotExists('Delete');
// Now attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall'); // Assert forum is no longer required.
$this->assertSession()->fieldExists('uninstall[forum]'); $this->drupalGet('admin/modules/uninstall');
// Now edit that same workspace; We shouldn't be able to do so, since
// we don't have edit permissions.
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $etm */ $etm = \Drupal::service('entity_type.manager'); /** @var \Drupal\workspaces\WorkspaceInterface $bears */ $entity_list = $etm->getStorage('workspace')->loadByProperties(['label' => 'Bears']); $bears = current($entity_list);
/**
* Verifies that a user can create and edit only their own workspace.
*/ publicfunctiontestEditOwnWorkspace(){ $permissions = [
$flood_config = $this->configFactory->get('user.flood'); $username = $request->headers->get('PHP_AUTH_USER'); $password = $request->headers->get('PHP_AUTH_PW'); // Flood protection: this is very similar to the user login form code.
// @see \Drupal\user\Form\UserLoginForm::validateAuthentication()
// Do not allow any login from the current user's IP if the limit has been
// reached. Default is 50 failed attempts allowed in one hour. This is
// independent of the per-user limit to catch attempts from one IP to log
// in to many different user accounts. We have a reasonably high limit
// since there may be only one apparent IP for all users at an institution.
if($this->flood->isAllowed('basic_auth.failed_login_ip', $flood_config->get('ip_limit'), $flood_config->get('ip_window'))){ $accounts = $this->entityTypeManager->getStorage('user')->loadByProperties(['name' => $username, 'status' => 1]); $account = reset($accounts); if($account){ if($flood_config->get('uid_only')){ // Register flood events based on the uid only, so they apply for any
// IP address. This is the most secure option.
$identifier = $account->id(); } else{ // The default identifier is a combination of uid and IP address. This
// is less secure but more resistant to denial-of-service attacks that
// could lock out all users with public user names.
/**
* Checks if the given entity exists.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity for which to test existence.
*
* @return bool
* Whether the entity already has been created.
*/ protectedfunctionentityExists(EntityInterface $entity){ $entity_storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId()); return !empty($entity_storage->loadByProperties([ 'uuid' => $entity->uuid(), ])); }
/**
* Extracts JSON:API query parameters from the request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type
* The JSON:API resource type.
*
* @return array
* An array of JSON:API parameters like `sort` and `filter`.
*/
publicfunctiontestLoadMissingFid(){ $this->assertNull(File::load(-1), 'Try to load an invalid fid fails.'); $this->assertFileHooksCalled([]); }
/**
* Try to load a non-existent file by URI.
*/ publicfunctiontestLoadMissingFilepath(){ $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => 'foobar://misc/druplicon.png']); $this->assertFalse(reset($files), "Try to load a file that doesn't exist in the database fails."); $this->assertFileHooksCalled([]); }
/**
* Try to load a non-existent file by status.
*/ publicfunctiontestLoadInvalidStatus(){ $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['status' => -99]); $this->assertFalse(reset($files), 'Trying to load a file with an invalid status fails.'); $this->assertFileHooksCalled([]); }
// Delete the field.
$field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name); $field->delete();
// The field still exists, deleted.
$fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $this->assertCount(1, $fields, 'There is one deleted field'); $field = $fields[$field->uuid()]; $this->assertEquals($bundle, $field->getTargetBundle(), 'The deleted field is for the correct bundle');
// Check that the actual stored content did not change during delete.
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */ $table_mapping = $storage->getTableMapping(); $table = $table_mapping->getDedicatedDataTableName($field_storage); $column = $table_mapping->getFieldColumnName($field_storage, 'value'); $result = Database::getConnection()->select($table, 't') ->fields('t')
// Check that the stored menu link meeting the expectations.
$this->assertNotNull($menu_link); $this->assertMenuLink([ 'menu_name' => $menu_id, 'children' => [], 'parent' => $parent, ], $menu_link->getPluginId());
// Delete custom menu.
$this->drupalGet("admin/structure/menu/manage/{$menu_name}/delete"); $this->submitForm([], 'Delete'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->addressEquals("admin/structure/menu"); $this->assertSession()->pageTextContains("The menu $label has been deleted."); $this->assertNull(Menu::load($menu_name), 'Custom menu was deleted'); // Test if all menu links associated with the menu were removed from
// database.
$result = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['menu_name' => $menu_name]); $this->assertEmpty($result, 'All menu links associated with the custom menu were deleted.');
// Make sure there's no delete button on system menus.
$this->drupalGet('admin/structure/menu/manage/main'); $this->assertSession()->responseNotContains('edit-delete');
// Try to delete the main menu.
$this->drupalGet('admin/structure/menu/manage/main/delete'); $this->assertSession()->pageTextContains('You are not authorized to access this page.'); }
/**
* Returns an array of permissions.
*
* @return string[][]
* An array whose keys are permission names and whose corresponding values
* are defined in \Drupal\user\PermissionHandlerInterface::getPermissions().
*/ publicfunctionpermissions(){ $permissions = [];
// Verify that the creation message contains a link to a term.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "term/")]');
/** @var \Drupal\taxonomy\TermStorageInterface $taxonomy_term_storage */ $taxonomy_term_storage = $this->container->get('entity_type.manager')->getStorage('taxonomy_term'); // Verify forum.
$term = $taxonomy_term_storage->loadByProperties([ 'vid' => $this->config('forum.settings')->get('vocabulary'), 'name' => $name, 'description__value' => $description, ]); $term = array_shift($term); $this->assertNotEmpty($term, "The forum type '$type' should exist in the database.");
// Check that the 'Create new revision' checkbox is checked and disabled.
$this->drupalGet('/admin/structure/types/manage/not_moderated'); $this->assertSession()->checkboxChecked('options[revision]'); $this->assertSession()->fieldDisabled('options[revision]');