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