Chris@0: drupalCreateUser(['administer users']); Chris@0: $this->drupalLogin($user); Chris@0: Chris@0: $this->assertEqual($user->getCreatedTime(), REQUEST_TIME, 'Creating a user sets default "created" timestamp.'); Chris@0: $this->assertEqual($user->getChangedTime(), REQUEST_TIME, 'Creating a user sets default "changed" timestamp.'); Chris@0: Chris@0: // Create a field. Chris@0: $field_name = 'test_field'; Chris@0: FieldStorageConfig::create([ Chris@0: 'field_name' => $field_name, Chris@0: 'entity_type' => 'user', Chris@0: 'module' => 'image', Chris@0: 'type' => 'image', Chris@0: 'cardinality' => 1, Chris@0: 'locked' => FALSE, Chris@0: 'indexes' => ['target_id' => ['target_id']], Chris@0: 'settings' => [ Chris@0: 'uri_scheme' => 'public', Chris@0: ], Chris@0: ])->save(); Chris@0: Chris@0: FieldConfig::create([ Chris@0: 'field_name' => $field_name, Chris@0: 'entity_type' => 'user', Chris@0: 'label' => 'Picture', Chris@0: 'bundle' => 'user', Chris@0: 'description' => t('Your virtual face or picture.'), Chris@0: 'required' => FALSE, Chris@0: 'settings' => [ Chris@0: 'file_extensions' => 'png gif jpg jpeg', Chris@0: 'file_directory' => 'pictures', Chris@0: 'max_filesize' => '30 KB', Chris@0: 'alt_field' => 0, Chris@0: 'title_field' => 0, Chris@0: 'max_resolution' => '85x85', Chris@0: 'min_resolution' => '', Chris@0: ], Chris@0: ])->save(); Chris@0: Chris@0: // Test user creation page for valid fields. Chris@0: $this->drupalGet('admin/people/create'); Chris@0: $this->assertFieldbyId('edit-status-0', 0, 'The user status option Blocked exists.', 'User login'); Chris@0: $this->assertFieldbyId('edit-status-1', 1, 'The user status option Active exists.', 'User login'); Chris@0: $this->assertFieldByXPath('//input[@type="radio" and @id="edit-status-1" and @checked="checked"]', NULL, 'Default setting for user status is active.'); Chris@0: Chris@0: // Test that browser autocomplete behavior does not occur. Chris@0: $this->assertNoRaw('data-user-info-from-browser', 'Ensure form attribute, data-user-info-from-browser, does not exist.'); Chris@0: Chris@0: // Test that the password strength indicator displays. Chris@0: $config = $this->config('user.settings'); Chris@0: Chris@0: $config->set('password_strength', TRUE)->save(); Chris@0: $this->drupalGet('admin/people/create'); Chris@0: $this->assertRaw(t('Password strength:'), 'The password strength indicator is displayed.'); Chris@0: Chris@0: $config->set('password_strength', FALSE)->save(); Chris@0: $this->drupalGet('admin/people/create'); Chris@0: $this->assertNoRaw(t('Password strength:'), 'The password strength indicator is not displayed.'); Chris@0: Chris@0: // We create two users, notifying one and not notifying the other, to Chris@0: // ensure that the tests work in both cases. Chris@0: foreach ([FALSE, TRUE] as $notify) { Chris@0: $name = $this->randomMachineName(); Chris@0: $edit = [ Chris@0: 'name' => $name, Chris@0: 'mail' => $this->randomMachineName() . '@example.com', Chris@0: 'pass[pass1]' => $pass = $this->randomString(), Chris@0: 'pass[pass2]' => $pass, Chris@0: 'notify' => $notify, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/people/create', $edit, t('Create new account')); Chris@0: Chris@0: if ($notify) { Chris@0: $this->assertText(t('A welcome message with further instructions has been emailed to the new user @name.', ['@name' => $edit['name']]), 'User created'); Chris@0: $this->assertEqual(count($this->drupalGetMails()), 1, 'Notification email sent'); Chris@0: } Chris@0: else { Chris@0: $this->assertText(t('Created a new user account for @name. No email has been sent.', ['@name' => $edit['name']]), 'User created'); Chris@0: $this->assertEqual(count($this->drupalGetMails()), 0, 'Notification email not sent'); Chris@0: } Chris@0: Chris@0: $this->drupalGet('admin/people'); Chris@0: $this->assertText($edit['name'], 'User found in list of users'); Chris@0: $user = user_load_by_name($name); Chris@0: $this->assertEqual($user->isActive(), 'User is not blocked'); Chris@0: } Chris@0: Chris@0: // Test that the password '0' is considered a password. Chris@0: // @see https://www.drupal.org/node/2563751. Chris@0: $name = $this->randomMachineName(); Chris@0: $edit = [ Chris@0: 'name' => $name, Chris@0: 'mail' => $this->randomMachineName() . '@example.com', Chris@0: 'pass[pass1]' => 0, Chris@0: 'pass[pass2]' => 0, Chris@0: 'notify' => FALSE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/people/create', $edit, t('Create new account')); Chris@0: $this->assertText("Created a new user account for $name. No email has been sent"); Chris@0: $this->assertNoText('Password field is required'); Chris@0: } Chris@0: Chris@0: }