getAccountName example

'administer node display',
    ]);
    $this->drupalLogin($account);

    $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this->submitForm(['layout[enabled]' => TRUE], 'Save');
    $page->clickLink('Manage layout');
    $page->clickLink('Add section');
    $page->clickLink('Layout Builder Test: Context Aware');
    $page->pressButton('Add section');
    // See \Drupal\layout_builder_test\Plugin\Layout\TestContextAwareLayout::build().     $assert_session->elementExists('css', '.user--' . $account->getAccountName());
    $page->clickLink('Configure Section 1');
    $page->fillField('layout_settings[label]', 'My section');
    $page->pressButton('Update');
    $assert_session->linkExists('Configure My section');
    $page->clickLink('Add block');
    $page->clickLink('Powered by Drupal');
    $page->pressButton('Add block');
    $page->pressButton('Save layout');
    $this->drupalGet('node/1');
    // See \Drupal\layout_builder_test\Plugin\Layout\TestContextAwareLayout::build().     $assert_session->elementExists('css', '.user--' . $account->getAccountName());
  }
// Test block output.     \Drupal::currentUser()->setAccount($user1);

    // Test the rendering of a block.     $entity = Block::load('views_block__who_s_online_who_s_online_block');
    $output = \Drupal::entityTypeManager()
      ->getViewBuilder($entity->getEntityTypeId())
      ->view($entity, 'block');
    $this->setRawContent($this->renderer->renderRoot($output));
    $this->assertRaw('2 users', 'Correct number of online users (2 users).');
    $this->assertText($user1->getAccountName(), 'Active user 1 found in online list.');
    $this->assertText($user2->getAccountName(), 'Active user 2 found in online list.');
    $this->assertNoText($user3->getAccountName(), 'Inactive user not found in online list.');
    // Verify that online users are ordered correctly.     $this->assertGreaterThan(strpos($this->getRawContent()$user2->getAccountName())strpos($this->getRawContent()$user1->getAccountName()));
  }

}

        );
      }
      // A different user is already logged in on the computer.       else {
        /** @var \Drupal\user\UserInterface $reset_link_user */
        $reset_link_user = $this->userStorage->load($uid);
        if ($reset_link_user && $this->validatePathParameters($reset_link_user$timestamp$hash)) {
          $this->messenger()
            ->addWarning($this->t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please <a href=":logout">log out</a> and try using the link again.',
              [
                '%other_user' => $account->getAccountName(),
                '%resetting_user' => $reset_link_user->getAccountName(),
                ':logout' => Url::fromRoute('user.logout')->toString(),
              ]));
        }
        else {
          // Invalid one-time link specifies an unknown user.           $this->messenger()->addError($this->t('The one-time login link you clicked is invalid.'));
        }
        return $this->redirect('<front>');
      }
    }

    
$this->assertSession()->pageTextContains('Status');
  }

  /** * Test user name link. * * Tests that the user name formatter shows a link to the user when there is * access but not otherwise. */
  public function testUserNameLink() {
    $test_user = $this->drupalCreateUser();
    $xpath = "//td/a[.='" . $test_user->getAccountName() . "']/@href[.='" . $test_user->toUrl()->toString() . "']";

    $attributes = [
      'title' => 'View user profile.',
    ];
    $link = $test_user->toLink(NULL, 'canonical', ['attributes' => $attributes])->toString();

    // No access, so no link.     $this->drupalGet('test_user_fields_access');
    $this->assertSession()->pageTextContains($test_user->getAccountName());
    $this->assertSession()->elementNotExists('xpath', $xpath);

    

  protected function setUp(): void {
    parent::setUp();
    $this->account = $this->drupalCreateUser(['access user profiles']);
  }

  /** * Tests access to user autocompletion and verify the correct results. */
  public function testUserAutocomplete() {
    $this->drupalLogin($this->account);
    $this->drupalGet('user/autocomplete', ['query' => ['q' => $this->account->getAccountName()]]);
    $this->assertSession()->responseContains($this->account->getAccountName());
    $this->assertSession()->pageTextNotContains('registry initialized');
  }

}
$accounts = $this->userStorage->loadByProperties(['name' => $names]);

    // If there are no accounts, return FALSE now. As we will not enter the     // loop below otherwise.     if (empty($accounts)) {
      return FALSE;
    }

    // Validate each account. If any fails break out and return false.     foreach ($accounts as $account) {
      if (!in_array($account->getAccountName()$names) || !$this->validateEntity($account)) {
        return FALSE;
      }
    }

    return TRUE;
  }

  /** * {@inheritdoc} */
  public function processSummaryArguments(&$args) {
    

  public function testSearchModuleDisabling() {
    // Array of search plugins to test: 'keys' are the keywords to search for,     // and 'text' is the text to assert is on the results page.     $plugin_info = [
      'node_search' => [
        'keys' => 'pizza',
        'text' => $this->searchNode->label(),
      ],
      'user_search' => [
        'keys' => $this->searchUser->getAccountName(),
        'text' => $this->searchUser->getEmail(),
      ],
      'dummy_search_type' => [
        'keys' => 'foo',
        'text' => 'Dummy search snippet to display',
      ],
    ];
    $plugins = array_keys($plugin_info);
    /** @var \Drupal\search\SearchPageInterface[] $entities */
    $entities = SearchPage::loadMultiple();
    // Disable all of the search pages.
// Confirm the correct revision text appears on "view revisions" page.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/view");
    $this->assertSession()->pageTextContains($node->body->value);

    // Confirm the correct log message appears on "revisions overview" page.     $this->drupalGet("node/" . $node->id() . "/revisions");
    foreach ($logs as $revision_log) {
      $this->assertSession()->pageTextContains($revision_log);
    }
    // Original author, and editor names should appear on revisions overview.     $web_user = $nodes[0]->revision_uid->entity;
    $this->assertSession()->pageTextContains('by ' . $web_user->getAccountName());
    $editor = $nodes[2]->revision_uid->entity;
    $this->assertSession()->pageTextContains('by ' . $editor->getAccountName());

    // Confirm that this is the default revision.     $this->assertTrue($node->isDefaultRevision(), 'Third node revision is the default one.');

    // Confirm that revisions revert properly.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert");
    $this->submitForm([], 'Revert');
    $this->assertSession()->pageTextContains("Basic page {$nodes[1]->label()} has been reverted to the revision from {$this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime())}.");
    $node_storage->resetCache([$node->id()]);
    
$this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains("The path '{$edit['site_404']}' has to start with a slash.");

    // Use a custom 404 page.     $edit = [
      'site_404' => '/user/' . $this->adminUser->id(),
    ];
    $this->drupalGet('admin/config/system/site-information');
    $this->submitForm($edit, 'Save configuration');

    $this->drupalGet($this->randomMachineName(10));
    $this->assertSession()->pageTextContains($this->adminUser->getAccountName());
  }

  /** * Tests that an inaccessible custom 404 page falls back to the default. */
  public function testPageNotFoundCustomPageWithAccessDenied() {
    // Sets up a 404 page not accessible by the anonymous user.     $this->config('system.site')->set('page.404', '/system-test/custom-4xx')->save();

    $this->drupalGet('/this-path-does-not-exist');
    $this->assertSession()->pageTextNotContains('Admin-only 4xx response');
    
// This step should not appear, since settings.php is fully configured     // already.   }

  /** * Confirms that the installation succeeded. */
  public function testInstalled() {
    $this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);
    // Confirm that we are logged-in after installation.     $this->assertSession()->pageTextContains($this->rootUser->getAccountName());

    // Confirm that Drupal recognizes this distribution as the current profile.     $this->assertEquals('my_distro', \Drupal::installProfile());
    $this->assertEquals('my_distro', $this->config('core.extension')->get('profile'), 'The install profile has been written to core.extension configuration.');

    $this->rebuildContainer();
    $this->assertEquals('my_distro', \Drupal::installProfile());
  }

}
'#wrapper_attributes' => ['class' => ['entity-meta__title']],
    ];
    $form['meta']['changed'] = [
      '#type' => 'item',
      '#title' => $this->t('Last saved'),
      '#markup' => !$node->isNew() ? $this->dateFormatter->format($node->getChangedTime(), 'short') : $this->t('Not saved yet'),
      '#wrapper_attributes' => ['class' => ['entity-meta__last-saved']],
    ];
    $form['meta']['author'] = [
      '#type' => 'item',
      '#title' => $this->t('Author'),
      '#markup' => $node->getOwner()->getAccountName(),
      '#wrapper_attributes' => ['class' => ['entity-meta__author']],
    ];

    $form['status']['#group'] = 'footer';

    // Node author information for administrators.     $form['author'] = [
      '#type' => 'details',
      '#title' => $this->t('Authoring information'),
      '#group' => 'advanced',
      '#attributes' => [
        
public function testDescriptionRevLog(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions');
    $user = $this->drupalCreateUser([]$this->randomMachineName());
    $entity->setRevisionUser($user);
    $entity->setRevisionCreationTime((new \DateTime('2 February 2013 4:00:00pm'))->getTimestamp());
    $entity->save();

    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', '02/02/2013 - 16:00');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', $user->getAccountName());
  }

  /** * Test description with entity implementing revision log, with empty values. * * @covers ::getRevisionDescription */
  public function testDescriptionRevLogNullValues(): void {
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions')->save();

    
class TestContextAwareBlock extends BlockBase {

  /** * {@inheritdoc} */
  public function build() {
    /** @var \Drupal\user\UserInterface $user */
    $user = $this->getContextValue('user');
    return [
      '#prefix' => '<div id="' . $this->getPluginId() . '--username">',
      '#suffix' => '</div>',
      '#markup' => $user ? $user->getAccountName() : 'No context mapping selected.',
    ];
  }

  /** * {@inheritdoc} */
  protected function blockAccess(AccountInterface $account) {
    if ($this->getContextValue('user') instanceof UserInterface) {
      $this->messenger()->addStatus('User context found.');
    }

    
$this->assertEmpty($user->getPassword());
    $this->assertTrue($user->isBlocked());

    $this->assertMailString('body', 'Your application for an account is', 2);
    $this->assertMailString('body', 'Bob.Arctor has applied for an account', 2);

    // Verify that an authenticated user cannot register a new user, despite     // being granted permission to do so because only anonymous users can     // register themselves, authenticated users with the necessary permissions     // can POST a new user to the "user" REST resource.     $this->initAuthentication();
    $response = $this->registerRequest($this->account->getAccountName());
    $this->assertResourceErrorResponse(403, "Only anonymous users can register a user.", $response);
  }

  /** * Create the request body. * * @param string $name * Name. * @param bool $include_password * Include Password. * @param bool $include_email * Include Email. * * @return array * Return the request body. */

    $this->drupalLogin($this->adminUser);
    $this->setCommentPreview(DRUPAL_OPTIONAL);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');

    $edit = [];
    $date = new DrupalDateTime('2008-03-02 17:23');
    $edit['subject[0][value]'] = $this->randomMachineName(8);
    $edit['comment_body[0][value]'] = $this->randomMachineName(16);
    $edit['uid'] = $web_user->getAccountName() . ' (' . $web_user->id() . ')';
    $edit['date[date]'] = $date->format('Y-m-d');
    $edit['date[time]'] = $date->format('H:i:s');
    $raw_date = $date->getTimestamp();
    $expected_text_date = $this->container->get('date.formatter')->formatInterval(\Drupal::time()->getRequestTime() - $raw_date);
    $expected_form_date = $date->format('Y-m-d');
    $expected_form_time = $date->format('H:i:s');
    $comment = $this->postComment($this->node, $edit['subject[0][value]']$edit['comment_body[0][value]'], TRUE);
    $this->drupalGet('comment/' . $comment->id() . '/edit');
    $this->submitForm($edit, 'Preview');

    // Check that the preview is displaying the subject, comment, author and date correctly.
Home | Imprint | This part of the site doesn't use cookies.