Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Nov 13, 2024
1 parent d8666b5 commit 06e7eb6
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions tests/Content/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kirby\Content;

use Kirby\Cms\App;
use Kirby\Cms\Language;
use Kirby\Cms\User;

/**
Expand All @@ -13,30 +14,32 @@ class LockTest extends TestCase
{
public const TMP = KIRBY_TMP_DIR . '/Content.LockTest';

protected function createChangesVersion(): Version
{
protected function createChangesVersion(
Language|string $language = 'default'
): Version {
$version = new Version(
model: $this->app->page('test'),
id: VersionId::changes()
);

$version->create([
'title' => 'Test'
]);
], $language);

return $version;
}

protected function createLatestVersion(): Version
{
protected function createLatestVersion(
Language|string $language = 'default'
): Version {
$latest = new Version(
model: $this->app->page('test'),
id: VersionId::latest()
);

$latest->create([
'title' => 'Test'
]);
], $language);

return $latest;
}
Expand Down Expand Up @@ -118,6 +121,40 @@ public function testForWithoutUser()
$this->assertNull($lock->user());
}

/**
* @covers ::for
*/
public function testForWithLanguageWildcard()
{
$this->app = $this->app->clone([
'languages' => [
[
'code' => 'en',
'default' => true
],
[
'code' => 'de'
]
]
]);

// create the version with the admin user
$this->app->impersonate('admin');

$this->createLatestVersion('en');
$this->createLatestVersion('de');

$this->createChangesVersion('de');

// switch to a different user to simulate locked content
$this->app->impersonate('editor');

$changes = $this->app->page('test')->version('changes');
$lock = Lock::for($changes, '*');

$this->assertSame('admin', $lock->user()->id());
}

/**
* @covers ::isActive
*/
Expand Down

0 comments on commit 06e7eb6

Please sign in to comment.