Skip to content

Commit

Permalink
Return null as modification date if the version does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed May 21, 2024
1 parent 00105f6 commit bc29672
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Content/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ public function model(): ModelWithContent
public function modified(
string $language = 'default'
): int|null {
$this->ensure($language);
return $this->model->storage()->modified($this->id, $this->language($language));
if ($this->exists($language) === true) {
return $this->model->storage()->modified($this->id, $this->language($language));
}

return null;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/Content/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,22 @@ public function testModifiedMultiLanguage(): void
$this->assertSame($modified, $version->modified('de'));
}

/**
* @covers ::modified
*/
public function testModifiedMultiLanguageIfNotExists(): void
{
$this->setUpMultiLanguage();

$version = new Version(
model: $this->model,
id: VersionId::published()
);

$this->assertNull($version->modified('en'));
$this->assertNull($version->modified('de'));
}

/**
* @covers ::modified
*/
Expand All @@ -386,6 +402,21 @@ public function testModifiedSingleLanguage(): void
$this->assertSame($modified, $version->modified());
}

/**
* @covers ::modified
*/
public function testModifiedSingleLanguageIfNotExists(): void
{
$this->setUpSingleLanguage();

$version = new Version(
model: $this->model,
id: VersionId::published()
);

$this->assertNull($version->modified());
}

/**
* @covers ::read
*/
Expand Down

0 comments on commit bc29672

Please sign in to comment.