drupalLogin example



  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests that all Core help topics can be rendered and have good syntax. */
  public function testHelpTopics() {
    $this->drupalLogin($this->rootUser);

    // Enable all modules and themes, so that all routes mentioned in topics     // will be defined.     $module_directories = $this->listDirectories('module');
    $modules_to_install = array_keys($module_directories);
    \Drupal::service('module_installer')->install($modules_to_install);
    $theme_directories = $this->listDirectories('theme');
    \Drupal::service('theme_installer')->install(array_keys($theme_directories));

    $directories = $module_directories + $theme_directories +
      $this->listDirectories('profile');
    
$this->drupalCreateContentType([
      'name' => 'Article',
      'type' => 'article',
    ]);
    $admin_user = $this->drupalCreateUser([
      'access content',
      'access content overview',
      'administer content types',
      'edit any article content',
      'delete any article content',
    ]);
    $this->drupalLogin($admin_user);
  }

  /** * Tests that the node delete operation opens in a modal. */
  public function testNodeDelete() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // Test the delete operation on an item in admin/content .     $node = $this->createNode([
      
/** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['comment_test_views']): void {
    parent::setUp($import_test_views$modules);

    // Add two users, create a node with the user1 as author and another node     // with user2 as author. For the second node add a comment from user1.     $this->account = $this->drupalCreateUser(['skip comment approval']);
    $this->account2 = $this->drupalCreateUser();
    $this->drupalLogin($this->account);

    $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
    $this->addDefaultCommentField('node', 'page');

    $this->nodeUserPosted = $this->drupalCreateNode();
    $this->nodeUserCommented = $this->drupalCreateNode(['uid' => $this->account2->id()]);

    $comment = [
      'uid' => $this->loggedInUser->id(),
      'entity_id' => $this->nodeUserCommented->id(),
      'entity_type' => 'node',
      
$this->createNode([
        'type' => 'bundle_with_section_field',
        'title' => "Node $i title",
      ]);
    }
  }

  /** * Tests blocks containing forms can be successfully saved editing defaults. */
  public function testAddingFormBlocksToDefaults() {
    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));

    // From the manage display page, enable Layout Builder.     $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
    $this->drupalGet("$field_ui_prefix/display/default");
    $this->submitForm(['layout[enabled]' => TRUE], 'Save');
    $this->submitForm(['layout[allow_custom]' => TRUE], 'Save');

    // Save the entity view display so that it can be reverted to later.
ConfigurableLanguage::createFromLangcode($langcode)->save();
    }
    $this->localeStorage = $this->container->get('locale.storage');
    $this->drupalPlaceBlock('local_tasks_block');
    $this->drupalPlaceBlock('page_title_block');
  }

  /** * Tests the site information translation interface. */
  public function testSiteInformationTranslationUi() {
    $this->drupalLogin($this->adminUser);

    $site_name = 'Name of the site for testing configuration translation';
    $site_slogan = 'Site slogan for testing configuration translation';
    $site_name_label = 'Site name';
    $fr_site_name = 'Nom du site pour tester la configuration traduction';
    $fr_site_slogan = 'Slogan du site pour tester la traduction de configuration';
    $fr_site_name_label = 'LibellĂ© du champ "Nom du site"';
    $translation_base_url = 'admin/config/system/site-information/translate';

    // Set site name and slogan for default language.     $this->setSiteInformation($site_name$site_slogan);

    
$url_options = [
      'absolute' => TRUE,
      'language' => $language_interface,
    ];

    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    \Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);

    // Create two users and log them in one after another.     $user1 = $this->drupalCreateUser([]);
    $user2 = $this->drupalCreateUser([]);
    $this->drupalLogin($user1);
    $this->drupalLogout();
    $this->drupalLogin($user2);

    $account = User::load($user1->id());
    $global_account = User::load(\Drupal::currentUser()->id());

    /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
    $date_formatter = $this->container->get('date.formatter');

    // Generate and test tokens.     $tests = [];
    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests race condition for CSRF tokens for simultaneous requests. */
  public function testCsrfRace() {
    $user = $this->createUser(['access content']);
    $this->drupalLogin($user);
    $this->drupalGet('/csrf_race/test');
    $script = '';
    // Delay the request processing of the first request by one second through     // the request parameter, which will simulate the concurrent processing     // of both requests.     foreach ([1, 0] as $i) {
      $script .= <<<EOT jQuery.ajax({ url: "$this->baseUrl/csrf_race/get_csrf_token/$i", method: "GET", headers: { "Content-Type": "application/json" }, success: function(response) { jQuery('body').append("<p class='csrf


    $this->drupalPlaceBlock('local_tasks_block');
    $this->drupalPlaceBlock('local_actions_block');

    $user = $this->drupalCreateUser([
      'access media overview',
      'create media',
      'delete any media',
      'update any media',
    ]);
    $this->drupalLogin($user);
  }

  /** * Tests that the Media Library's administration page works as expected. */
  public function testAdministrationPage() {
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    // Visit the administration page.
    $admin_user = $this->drupalCreateUser([
      'access content',
      'administer taxonomy',
      'access administration pages',
      'administer site configuration',
      'administer content types',
      'administer nodes',
      'bypass node access',
      'administer node fields',
      'administer node display',
    ]);
    $this->drupalLogin($admin_user);

    // Create content type, with underscores.     $this->typeName = 'test_' . strtolower($this->randomMachineName());
    $type = $this->drupalCreateContentType(['name' => $this->typeName, 'type' => $this->typeName]);
    $this->type = $type->id();
  }

  /** * Options (integer) : test 'allowed values' input. */
  public function testOptionsAllowedValuesInteger() {
    
->save();
    }
    // Set up an admin user with appropriate permissions.     $admin_user = $this->drupalCreateUser([
      'view own unpublished content',
      'administer languages',
      'administer content types',
      'access administration pages',
      'create page content',
      'edit own page content',
    ]);
    $this->drupalLogin($admin_user);

    $config = $this->config('language.types');
    $config->set('configurable', [LanguageInterface::TYPE_INTERFACE]);
    $config->set('negotiation.language_content.enabled', [
      LanguageNegotiationUrl::METHOD_ID => 1,
      LanguageNegotiationSelected::METHOD_ID => 1,
    ]);
    $config->save();

    \Drupal::configFactory()->getEditable('language.negotiation')
      ->set('url.prefixes.aa', 'aa')
      
// Created a content type.     $this->drupalCreateContentType([
      'name' => 'moderated',
      'type' => 'moderated',
    ]);

    // Set the content type as moderated.     $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
    $workflow->save();

    $this->drupalLogin($this->rootUser);

    // Enable URL language detection and selection.     $edit = ['language_interface[enabled][language-url]' => 1];
    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');

    // Enable translation for moderated node.     $edit = [
      'entity_types[node]' => 1,
      'settings[node][moderated][translatable]' => 1,
      'settings[node][moderated][fields][path]' => 1,
      
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->adminUser = $this->drupalCreateUser([
      'administer blocks',
      'administer languages',
    ]);
    $this->drupalLogin($this->adminUser);

    // Add predefined language.     $edit = [
      'predefined_langcode' => 'fr',
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');

    // Verify that language was added successfully.     $this->assertSession()->pageTextContains('French');

    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->adminUser = $this->drupalCreateUser([
      'administer site configuration',
      'access administration pages',
      'access site reports',
    ]);
    $this->drupalLogin($this->adminUser);

    $this->webUser = $this->drupalCreateUser();
  }

  /** * Tests rebuilding the node access permissions table with content. */
  public function testNodeAccessRebuildNodeGrants() {
    \Drupal::service('module_installer')->install(['node_access_test']);
    \Drupal::state()->set('node_access_test.private', TRUE);
    node_access_test_add_field(NodeType::load('page'));
    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests the behavior when there are no actions to list in the admin page. */
  public function testEmptyActionList() {
    // Create a user with permission to view the actions administration pages.     $this->drupalLogin($this->drupalCreateUser(['administer actions']));

    // Ensure the empty text appears on the action list page.     /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
    $storage = $this->container->get('entity_type.manager')->getStorage('action');
    $actions = $storage->loadMultiple();
    $storage->delete($actions);
    $this->drupalGet('/admin/config/system/actions');
    $this->assertSession()->pageTextContains('There are no actions yet.');
  }

  /** * Tests that non-configurable actions can be created by the UI. */
for ($i = 0; $i < $revision_count$i++) {
      $media->revision_log = $this->randomMachineName(32);
      $media = $this->createMediaRevision($media);
      $media_revisions[] = clone $media;
    }

    // Get the last revision for simple checks.     /** @var \Drupal\media\MediaInterface $media */
    $media = end($media_revisions);

    // Test permissions.     $this->drupalLogin($this->nonAdminUser);
    /** @var \Drupal\user\RoleInterface $role */
    $role = Role::load(RoleInterface::AUTHENTICATED_ID);

    // Test 'view all media revisions' permission ('view media' permission is     // needed as well).     user_role_revoke_permissions($role->id()['view media', 'view all media revisions']);
    $this->drupalGet('media/' . $media->id() . '/revisions/' . $media->getRevisionId() . '/view');
    $assert->statusCodeEquals(403);
    $this->grantPermissions($role['view media', 'view all media revisions']);
    $this->drupalGet('media/' . $media->id() . '/revisions/' . $media->getRevisionId() . '/view');
    $assert->statusCodeEquals(200);

    
Home | Imprint | This part of the site doesn't use cookies.