forked from getkirby/kirby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request getkirby#4741 from getkirby/fix/4740-better-lock-c…
…heck More efficient lock check
- Loading branch information
Showing
8 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Kirby\Cms; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class LockRoutesTest extends TestCase | ||
{ | ||
protected $app; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->app = new App([ | ||
'options' => [ | ||
'api.allowImpersonation' => true | ||
], | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
] | ||
]); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
$app = $this->app->clone([ | ||
'site' => [ | ||
'children' => [ | ||
[ | ||
'slug' => 'a', | ||
] | ||
] | ||
] | ||
]); | ||
|
||
$app->impersonate('kirby'); | ||
|
||
$response = $app->api()->call('pages/a/lock'); | ||
$expected = [ | ||
'lock' => false | ||
]; | ||
|
||
$this->assertSame($expected, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,4 +283,65 @@ public function testResolveWithRemainingUnlocks() | |
$app->impersonate('[email protected]'); | ||
$this->assertTrue($page->lock()->isUnlocked()); | ||
} | ||
|
||
public function testState() | ||
{ | ||
$app = $this->app; | ||
$page = $app->page('test'); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
$page->lock()->create(); | ||
|
||
$this->assertSame(null, $page->lock()->state()); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
// state is locked | ||
$this->assertSame('lock', $page->lock()->state()); | ||
|
||
// user force unlocks the lock | ||
$page->lock()->unlock(); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
// state is now unlock for the original user | ||
$this->assertSame('unlock', $page->lock()->state()); | ||
} | ||
|
||
public function testToArray() | ||
{ | ||
$app = $this->app; | ||
$page = $app->page('test'); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
$page->lock()->create(); | ||
|
||
$expected = [ | ||
'state' => null, | ||
'data' => false | ||
]; | ||
|
||
$this->assertSame($expected, $page->lock()->toArray()); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
$lockArray = $page->lock()->toArray(); | ||
|
||
// state is locked | ||
$this->assertSame('lock', $lockArray['state']); | ||
$this->assertSame('[email protected]', $lockArray['data']['email']); | ||
|
||
// user force unlocks the lock | ||
$page->lock()->unlock(); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
$lockArray = $page->lock()->toArray(); | ||
|
||
// state is locked | ||
$this->assertSame('unlock', $lockArray['state']); | ||
$this->assertSame(false, $lockArray['data']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,20 @@ | |
namespace Kirby\Panel; | ||
|
||
use Kirby\Cms\App; | ||
use Kirby\Cms\ContentLock; | ||
use Kirby\Cms\Page as ModelPage; | ||
use Kirby\Cms\Site as ModelSite; | ||
use Kirby\Filesystem\Asset; | ||
use Kirby\Filesystem\Dir; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CustomContentLockIsLocked | ||
class CustomContentLockIsLocked extends ContentLock | ||
{ | ||
public function __construct() | ||
{ | ||
$this->model = new ModelPage(['slug' => 'test']); | ||
} | ||
|
||
public function get(): array | ||
{ | ||
return ['email' => '[email protected]']; | ||
|
@@ -26,7 +33,7 @@ public function isUnlocked(): bool | |
} | ||
} | ||
|
||
class CustomContentLockIsUnlocked | ||
class CustomContentLockIsUnlocked extends CustomContentLockIslocked | ||
{ | ||
public function isUnlocked(): bool | ||
{ | ||
|
@@ -416,7 +423,7 @@ public function testLock() | |
|
||
// no lock or unlock | ||
$site = new ModelSite(); | ||
$this->assertSame(['state' => null], $site->panel()->lock()); | ||
$this->assertSame(['state' => null, 'data' => false], $site->panel()->lock()); | ||
|
||
// lock | ||
$site = new ModelSiteTestForceLocked(); | ||
|
@@ -426,7 +433,7 @@ public function testLock() | |
|
||
// unlock | ||
$site = new ModelSiteTestForceUnlocked(); | ||
$this->assertSame(['state' => 'unlock'], $site->panel()->lock()); | ||
$this->assertSame('unlock', $site->panel()->lock()['state']); | ||
} | ||
|
||
/** | ||
|