createUser example

$this->assertSession()->pageTextContains('System no module version dependency test');
    $this->assertSession()->pageTextContains('System no module version test');

    // Ensure the modules can actually be installed.     $edit['modules[system_no_module_version_test][enable]'] = 'system_no_module_version_test';
    $edit['modules[system_no_module_version_dependency_test][enable]'] = 'system_no_module_version_dependency_test';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()->pageTextContains('2 modules have been enabled: System no module version dependency test, System no module version test.');

    // Ensure status report is working.     $this->drupalLogin($this->createUser(['administer site configuration']));
    $this->drupalGet('admin/reports/status');
    $this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests failing PHP version requirements. */
  public function testIncompatiblePhpVersionDependency() {
    $this->drupalGet('admin/modules');
    $this->assertSession()->pageTextContains('This module requires PHP version 6502.* and is incompatible with PHP version ' . phpversion() . '.');
    $this->assertSession()->fieldDisabled('modules[system_incompatible_php_version_test][enable]');
  }
$this->installEntitySchema($entity_type_id);
      }
    }
  }

  /** * Tests basic CRUD functionality of the Entity API. */
  public function testCRUD() {
    // All entity variations have to have the same results.     foreach (entity_test_entity_types() as $entity_type) {
      $this->assertCRUD($entity_type$this->createUser());
    }
  }

  /** * Executes a test set for a defined entity type and user. * * @param string $entity_type * The entity type to run the tests with. * @param \Drupal\user\UserInterface $user1 * The user to run the tests with. * * @internal */
$this->installConfig(['filter']);

    NodeType::create(['type' => 'page'])->save();

    FieldStorageConfig::create([
      'type' => 'text_long',
      'entity_type' => 'comment',
      'field_name' => 'comment_body',
    ])->save();
    $this->addDefaultCommentField('node', 'page', 'comment');

    $account = $this->createUser();
    $other_account = $this->createUser();

    $node_authored_by_account = $this->createNode([
      'uid' => $account->id(),
      'title' => "authored by {$account->id()}",
    ]);
    $node_commented_by_account = $this->createNode([
      'title' => "commented by {$account->id()}",
    ]);
    $arbitrary_node = $this->createNode();

    

  protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('user');
    $this->installSchema('system', ['sequences']);

    $this->accessControlHandler = $this->container->get('entity_type.manager')->getAccessControlHandler('workflow');

    // Create and discard user 1, which is special and bypasses all access     // checking.     $this->createUser([]);
    $this->user = $this->createUser([]);
    $this->adminUser = $this->createUser(['administer workflows']);
  }

  /** * @covers ::checkCreateAccess */
  public function testCheckCreateAccess() {
    // A user must have the correct permission to create a workflow.     $this->assertEquals(
      AccessResult::neutral()
        
/** * {@inheritdoc} */
  protected static $modules = ['entity_test_constraints'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('entity_test_constraints');
    $this->createUser();
  }

  public function testValidation() {
    $this->state->set('entity_test_constraints.build', [
      'EntityHasField' => 'body',
    ]);

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $this->container->get('entity_type.manager');
    $entity_type_manager->clearCachedDefinitions();

    


  /** * Ensures that user 1 has a unique render cache for the given context. * * @param string[] $contexts * List of cache contexts to use. */
  protected function doTestUser1WithContexts($contexts) {
    // Test that user 1 does not share the cache with other users who have the     // same roles, even when using a role-based cache context.     $user1 = $this->createUser();
    $this->assertEquals(1, $user1->id());
    $first_authenticated_user = $this->createUser();
    $second_authenticated_user = $this->createUser();
    $admin_user = $this->createUser([], NULL, TRUE);

    $this->assertEquals($user1->getRoles()$first_authenticated_user->getRoles(), 'User 1 has the same roles as an authenticated user.');
    // Impersonate user 1 and render content that only user 1 should have     // permission to see.     \Drupal::service('account_switcher')->switchTo($user1);
    $test_element = [
      '#cache' => [
        
/** * {@inheritdoc} */
  protected $defaultTheme = 'views_ui_test_theme';

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

    $this->drupalLogin($this->createUser([
      'administer views',
    ]));
  }

  /** * Confirms that form_alter is triggered after AJAX rebuilds. */
  public function testAjaxRebuild() {
    \Drupal::service('theme_installer')->install(['views_ui_test_theme']);

    $this->config('system.theme')
      
User::create(['uid' => 0, 'name' => ''])->save();
    ViewTestData::createTestViews(static::class['user_test_views']);

    $view = Views::getView('test_user_uid_argument');

    // Tests an invalid user uid.     $view->preview(NULL, [rand(1000, 10000)]);
    $this->assertEmpty($view->getTitle());
    $view->destroy();

    // Tests a valid user.     $account = $this->createUser();
    $view->preview(NULL, [$account->id()]);
    $this->assertEquals($account->label()$view->getTitle());
    $view->destroy();

    // Tests the anonymous user.     $anonymous = $this->config('user.settings')->get('anonymous');
    $view->preview(NULL, [0]);
    $this->assertEquals($anonymous$view->getTitle());
    $view->destroy();

    $view->getDisplay()->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
    
$this->installSchema('system', ['sequences']);
    $this->installEntitySchema('user');
    $this->installEntitySchema('file');
    $this->installSchema('file', ['file_usage']);
    $this->installConfig('user');

    $anonymous = User::create(['uid' => 0, 'name' => '']);
    $anonymous->save();
    user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access content']);

    // Create an authenticated user to check file access.     $account = $this->createUser(['access site reports', 'access content'], NULL, FALSE, ['uid' => 2]);

    // Create a new file entity in the public:// stream wrapper.     $file_public = File::create([
      'uid' => 1,
      'filename' => 'drupal.txt',
      'uri' => 'public://drupal.txt',
      'status' => FileInterface::STATUS_PERMANENT,
    ]);
    $file_public->save();

    $this->assertTrue($file_public->access('view', $account));
    

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);

    $this->drupalCreateContentType(['type' => 'page']);
    $this->adminUser = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']);
  }

  /** * Tests bulk selection. */
  public function testBulkSelection() {

    // Create first node, set updated time to the past.     $node_1 = $this->drupalCreateNode([
      'type' => 'page',
      'title' => 'The first node',
      
$this->installEntitySchema('media');
    $this->installConfig([
      'field',
      'system',
      'file',
      'image',
      'media',
      'media_library',
    ]);

    // Create an account with special UID 1.     $this->createUser([]);

    $this->createMediaType('image', ['id' => 'image']);
    $this->createMediaType('oembed:video', ['id' => 'remote_video']);
  }

  /** * Tests the media library add form. */
  public function testMediaTypeAddForm() {
    $entity_type_manager = \Drupal::entityTypeManager();
    $image = $entity_type_manager->getStorage('media_type')->load('image');
    
$timeZoneConfig = $configFactory->getEditable('system.date');
    $timeZoneConfig->set('timezone.default', 'Australia/Adelaide');
    $timeZoneConfig->save();

    $eventDispatcher = $this->container->get('event_dispatcher');
    $kernel = $this->container->get('kernel');

    $eventDispatcher->dispatch(new RequestEvent($kernel, Request::create('http://www.example.com'), HttpKernelInterface::MAIN_REQUEST));

    $this->assertEquals('Australia/Adelaide', date_default_timezone_get());

    $user = $this->createUser([]);
    $user->set('timezone', 'Australia/Lord_Howe');
    $user->save();

    $this->setCurrentUser($user);

    $this->assertEquals('Australia/Lord_Howe', date_default_timezone_get());

  }

}
$form_builder = $this->container->get('form_builder');
    $form = $form_builder->getForm($this);

    // Check that the current user has proper access to view entity labels.     $expected = $this->referencedEntities[0]->label() . ' (' . $this->referencedEntities[0]->id() . ')';
    $this->assertEquals($expected$form['single_access']['#value']);

    $expected .= ', ' . $this->referencedEntities[1]->label() . ' (' . $this->referencedEntities[1]->id() . ')';
    $this->assertEquals($expected$form['tags_access']['#value']);

    // Set up a non-admin user that is *not* allowed to view test entities.     \Drupal::currentUser()->setAccount($this->createUser());

    // Rebuild the form.     $form = $form_builder->getForm($this);

    $expected = '- Restricted access - (' . $this->referencedEntities[0]->id() . ')';
    $this->assertEquals($expected$form['single_access']['#value']);

    $expected .= ', - Restricted access - (' . $this->referencedEntities[1]->id() . ')';
    $this->assertEquals($expected$form['tags_access']['#value']);
  }

  
$this->installSchema('system', ['sequences']);
    $this->installSchema('workspaces', ['workspace_association']);

    $this->createContentType(['type' => 'article']);

    $permissions = array_intersect([
      'administer nodes',
      'create workspace',
      'edit any workspace',
      'view any workspace',
    ]array_keys($this->container->get('user.permissions')->getPermissions()));
    $this->setCurrentUser($this->createUser($permissions));

    $this->workspaces['stage'] = Workspace::create(['id' => 'stage', 'label' => 'Stage']);
    $this->workspaces['stage']->save();
    $this->workspaces['dev'] = Workspace::create(['id' => 'dev', 'parent' => 'stage', 'label' => 'Dev']);
    $this->workspaces['dev']->save();
  }

  /** * Tests the revisions tracked by a workspace. * * @covers ::getTrackedEntities * @covers ::getAssociatedRevisions */
$page->save();

    // Create the article node type with revisions enabled.     $article = NodeType::create([
      'type' => 'article',
      'new_revision' => TRUE,
    ]);
    $article->save();

    // An administrator user. No user exists yet, ensure that the first user     // does not have UID 1.     $content_admin_user = $this->createUser(['administer nodes'], NULL, FALSE, ['uid' => 2]);

    // Two different editor users.     $page_creator_user = $this->createUser(['create page content', 'edit own page content', 'delete own page content']);
    $page_manager_user = $this->createUser(['create page content', 'edit any page content', 'delete any page content']);

    // An unprivileged user.     $page_unrelated_user = $this->createUser(['access content']);

    // List of all users     $test_users = [
      $content_admin_user,
      
Home | Imprint | This part of the site doesn't use cookies.