View source
<?php
namespace Drupal\Tests\user\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class PasswordConfirmWidgetTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected $assert;
protected $testUser;
protected function setUp() : void {
parent::setUp();
$this->assert = $this
->assertSession();
$this->testUser = $this
->createUser();
$this
->drupalLogin($this->testUser);
}
public function testPasswordConfirmWidgetJsComponents() {
$this
->drupalGet($this->testUser
->toUrl('edit-form'));
$password_confirm_widget_selector = '.js-form-type-password-confirm.js-form-item-pass';
$password_parent_selector = '.js-form-item-pass-pass1';
$password_confirm_selector = '.js-form-item-pass-pass2';
$password_confirm_widget = $this->assert
->elementExists('css', $password_confirm_widget_selector);
$password_parent_item = $password_confirm_widget
->find('css', $password_parent_selector);
$password_confirm_item = $password_confirm_widget
->find('css', $password_confirm_selector);
$this
->assertNotNull($this->assert
->waitForElement('css', "{$password_parent_selector}.password-parent"));
$this
->assertTrue($password_parent_item
->hasClass('password-parent'));
$this
->assertNotNull($this->assert
->waitForElement('css', "{$password_confirm_selector}.confirm-parent"));
$this
->assertTrue($password_confirm_item
->hasClass('confirm-parent'));
$this
->assertTrue($password_parent_item
->has('css', 'input.js-password-field'));
$this
->assertTrue($password_parent_item
->has('css', 'input.js-password-field + .password-strength > [data-drupal-selector="password-strength-meter"]:first-child [data-drupal-selector="password-strength-indicator"]'));
$this
->assertTrue($password_parent_item
->has('css', '.password-strength > [data-drupal-selector="password-strength-meter"] + .password-strength__title:last-child > [data-drupal-selector="password-strength-text"]'));
$this
->assertEmpty($password_parent_item
->find('css', '.password-strength > [data-drupal-selector="password-strength-meter"] + .password-strength__title:last-child > [data-drupal-selector="password-strength-text"]')
->getText());
$this
->assertTrue($password_confirm_item
->has('css', 'input.js-password-confirm'));
$this
->assertTrue($password_confirm_item
->has('css', "{$password_confirm_selector} + .password-suggestions"));
$this
->assertFalse($password_confirm_item
->has('css', "{$password_confirm_selector} + .password-suggestions > ul > li"));
$this
->assertFalse($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions")
->isVisible());
$this
->assertTrue($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions")
->getHtml() === '');
$this
->drupalGet($this->testUser
->toUrl('edit-form'));
$this->assert
->waitForElement('css', "{$password_parent_selector}.password-parent");
$password_confirm_widget
->fillField('Password', 'o');
$this
->assertNotNull($this->assert
->waitForElement('css', "{$password_confirm_selector} + .password-suggestions > ul > li"));
$this
->assertTrue($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions > ul > li")
->isVisible());
$this
->assertFalse($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_parent_selector}", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');
$password_confirm_widget
->fillField('Password', 'o');
$this
->assertFalse($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
->isVisible());
$this
->assertTrue($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions > ul > li")
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_parent_selector}", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');
$password_confirm_widget
->fillField('Password', 'oooooooooO0∘');
$password_confirm_widget
->fillField('Confirm password', 'oooooooooO0∘');
$this->assert
->elementAttributeContains('css', 'input.js-password-field + .password-strength > [data-drupal-selector="password-strength-meter"] [data-drupal-selector="password-strength-indicator"]', 'style', 'width: 100%;');
$this->assert
->elementTextContains('css', "{$password_confirm_widget_selector} {$password_parent_selector} [data-drupal-selector='password-strength-text']", 'Strong');
$this
->assertTrue($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
->isVisible());
$this
->assertTrue($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-match-status-text"]')
->hasClass('ok'));
$this->assert
->elementTextContains('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-match-status-text"]', 'yes');
$this
->assertFalse($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions")
->isVisible());
}
public function testPasswordConfirmMessage() {
$this
->drupalGet($this->testUser
->toUrl('edit-form'));
$password_confirm_widget_selector = '.js-form-type-password-confirm.js-form-item-pass';
$password_confirm_selector = '.js-form-item-pass-pass2';
$password_confirm_widget = $this->assert
->elementExists('css', $password_confirm_widget_selector);
$password_confirm_item = $password_confirm_widget
->find('css', $password_confirm_selector);
$this
->assertTrue($password_confirm_item
->has('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]'));
$this
->assertTrue($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_confirm_selector}", '<div aria-live="polite" aria-atomic="true" class="password-confirm-message" data-drupal-selector="password-confirm-message">Passwords match: <span data-drupal-selector="password-match-status-text"></span></div>');
}
public function testFillConfirmOnly() {
$this
->drupalGet($this->testUser
->toUrl('edit-form'));
$password_confirm_widget_selector = '.js-form-type-password-confirm.js-form-item-pass';
$password_parent_selector = '.js-form-item-pass-pass1';
$password_confirm_selector = '.js-form-item-pass-pass2';
$password_confirm_widget = $this->assert
->elementExists('css', $password_confirm_widget_selector);
$password_confirm_item = $password_confirm_widget
->find('css', $password_confirm_selector);
$password_parent_item = $password_confirm_widget
->find('css', $password_parent_selector);
$password_confirm_widget
->fillField('Confirm password', 'o');
$this
->assertNotNull($this->assert
->waitForElement('css', "{$password_confirm_selector} + .password-suggestions > ul > li"));
$this
->assertTrue($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions")
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_parent_selector}", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');
$this
->assertTrue($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_confirm_selector} [data-drupal-selector='password-confirm-message']", 'Passwords match: <span data-drupal-selector="password-match-status-text" class="error">no</span>');
$password_confirm_widget
->fillField('Confirm password', '');
$this
->assertFalse($password_confirm_item
->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_confirm_selector} [data-drupal-selector='password-confirm-message']", 'Passwords match: <span data-drupal-selector="password-match-status-text" class="error">no</span>');
$this
->assertTrue($password_confirm_item
->find('css', "{$password_confirm_selector} + .password-suggestions")
->isVisible());
$this
->assertTrue($password_parent_item
->find('css', '.password-strength > .password-strength__meter + .password-strength__title')
->isVisible());
$this->assert
->elementContains('css', "{$password_confirm_widget_selector} {$password_parent_selector}", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');
}
}