Verified Commit dd785268 authored by godotislate's avatar godotislate
Browse files

fix: #2954725 AccountInterface::getLastAccessedTime() implementors return incorrect data type

By: dpi
By: acbramley
By: manuel.adan
By: dcam
By: smustgrave
By: godotislate
(cherry picked from commit c62d3799)
parent 12b80f3d
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class UserSession implements AccountInterface {
  /**
   * The Unix timestamp when the user last accessed the site.
   *
   * @var string
   * @var int
   */
  protected $access;

@@ -194,7 +194,7 @@ public function getTimeZone() {
   * {@inheritdoc}
   */
  public function getLastAccessedTime() {
    return $this->access;
    return (int) $this->access;
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -289,7 +289,7 @@ public function getCreatedTime() {
   * {@inheritdoc}
   */
  public function getLastAccessedTime() {
    return $this->getFieldValue('access', 'value');
    return (int) $this->getFieldValue('access', 'value');
  }

  /**
+18 −0
Original line number Diff line number Diff line
@@ -125,4 +125,22 @@ public function testPasswordProperty(): void {
    $this->assertEquals('password', $user->password);
  }

  /**
   * Tests that ::getLastAccessedTime() returns an integer for a loaded user.
   *
   * @legacy-covers ::getLastAccessedTime
   */
  public function testGetLastAccessedTime(): void {
    $access = 100;
    /** @var \Drupal\user\Entity\User $user */
    $user = User::create([
      'name' => $this->randomMachineName(),
      'access' => $access,
    ]);
    $id = $user->save();

    $loaded_user = User::load($id);
    $this->assertSame($access, $loaded_user->getLastAccessedTime());
  }

}
+13 −0
Original line number Diff line number Diff line
@@ -114,4 +114,17 @@ public function testNamePropertyDeprecation(): void {
    $this->assertEquals('bar', $user->foo);
  }

  /**
   * Tests that ::getLastAccessedTime() returns an integer.
   *
   * @legacy-covers ::getLastAccessedTime
   */
  public function testGetLastAccessedTime(): void {
    $user = new UserSession([
      'access' => '1234567890',
    ]);

    $this->assertSame(1234567890, $user->getLastAccessedTime());
  }

}