Verified Commit 9e6f0a2c authored by Dave Long's avatar Dave Long
Browse files

task: #2648272 Deprecate retrieving password from $account

By: pwolanin
By: mgifford
By: dpi
By: kingandy
By: smustgrave
By: dcam
By: prudloff
By: mr.baileys
parent 51c8bbe6
Loading
Loading
Loading
Loading
Loading
+10 −0
Changes for core/modules/user/src/Entity/User.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -614,4 +614,14 @@ public static function getAllowedConfigurableLanguageCodes() {
    return array_keys(\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_CONFIGURABLE));
  }

  /**
   * {@inheritdoc}
   */
  public function &__get($name): mixed {
    if ($name == 'password') {
      @trigger_error("Getting the password property is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. See https://www.drupal.org/node/3569185", E_USER_DEPRECATED);
    }
    return parent::__get($name);
  }

}
+17 −0
Changes for core/modules/user/tests/src/Kernel/UserEntityTest.php: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
@@ -108,4 +109,20 @@ public function testChainExistingPasswordMethod(): void {
    $this->assertInstanceOf(User::class, $user);
  }

  /**
   * Tests that accessing the password property is correctly deprecated.
   */
  #[IgnoreDeprecations]
  public function testPasswordProperty(): void {
    /** @var \Drupal\user\Entity\User $user */
    $user = User::create([
      'name' => $this->randomMachineName(),
    ]);

    $user->password = 'password';

    $this->expectDeprecation('Getting the password property is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. See https://www.drupal.org/node/3569185');
    $this->assertEquals('password', $user->password);
  }

}