-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
9 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use Kirby\Data\Data; | ||
use Kirby\Exception\InvalidArgumentException; | ||
use Kirby\Exception\PermissionException; | ||
use Kirby\Filesystem\Dir; | ||
use Kirby\Filesystem\F; | ||
use PHPUnit\Framework\TestCase; | ||
|
@@ -472,6 +473,8 @@ public function testBaseUrl($kirbyUrl, $url, $expected) | |
|
||
public function testCreate() | ||
{ | ||
$this->app->impersonate('kirby'); | ||
|
||
$language = Language::create([ | ||
'code' => 'en' | ||
]); | ||
|
@@ -485,6 +488,8 @@ public function testCreate() | |
|
||
public function testDelete() | ||
{ | ||
$this->app->impersonate('kirby'); | ||
|
||
$language = Language::create([ | ||
'code' => 'en' | ||
]); | ||
|
@@ -496,6 +501,8 @@ public function testUpdate() | |
{ | ||
Dir::make($contentDir = $this->fixtures . '/content'); | ||
|
||
$this->app->impersonate('kirby'); | ||
|
||
$language = Language::create([ | ||
'code' => 'en' | ||
]); | ||
|
@@ -505,12 +512,55 @@ public function testUpdate() | |
$this->assertSame('English', $language->name()); | ||
} | ||
|
||
/** | ||
* @covers ::create | ||
*/ | ||
public function testCreateNoPermissions() | ||
{ | ||
$app = $this->app->clone([ | ||
'blueprints' => [ | ||
'users/editor' => [ | ||
'name' => 'editor', | ||
'permissions' => [ | ||
'languages' => [ | ||
'create' => false | ||
] | ||
] | ||
], | ||
], | ||
'users' => [ | ||
['email' => '[email protected]', 'role' => 'editor'] | ||
] | ||
]); | ||
|
||
$this->expectException(PermissionException::class); | ||
$this->expectExceptionMessage('You are not allowed to create a language'); | ||
|
||
$app->impersonate('[email protected]'); | ||
Language::create([ | ||
'code' => 'en' | ||
]); | ||
} | ||
|
||
/** | ||
* @covers ::create | ||
*/ | ||
public function testCreateWithoutLoggedUser() | ||
{ | ||
$this->expectException(PermissionException::class); | ||
$this->expectExceptionMessage('You are not allowed to create a language'); | ||
|
||
Language::create([ | ||
'code' => 'en' | ||
]); | ||
} | ||
|
||
public function testCreateHooks() | ||
{ | ||
$calls = 0; | ||
$phpunit = $this; | ||
|
||
new App([ | ||
$app = $this->app->clone([ | ||
'roots' => [ | ||
'index' => $this->fixtures = __DIR__ . '/fixtures/CreateHooksTest', | ||
], | ||
|
@@ -530,6 +580,8 @@ public function testCreateHooks() | |
] | ||
]); | ||
|
||
$app->impersonate('kirby'); | ||
|
||
Language::create([ | ||
'code' => 'de' | ||
]); | ||
|
@@ -545,7 +597,7 @@ public function testUpdateHooks() | |
$this->fixtures = __DIR__ . '/fixtures/UpdateHooksTest'; | ||
Dir::make($this->fixtures . '/content'); | ||
|
||
new App([ | ||
$app = $this->app->clone([ | ||
'roots' => [ | ||
'index' => $this->fixtures, | ||
], | ||
|
@@ -573,18 +625,113 @@ public function testUpdateHooks() | |
] | ||
]); | ||
|
||
$app->impersonate('kirby'); | ||
|
||
$language = Language::create(['code' => 'en']); | ||
$language->update(['name' => 'English']); | ||
|
||
$this->assertSame(2, $calls); | ||
} | ||
|
||
/** | ||
* @covers ::update | ||
*/ | ||
public function testUpdateNoPermissions() | ||
{ | ||
$app = $this->app->clone([ | ||
'blueprints' => [ | ||
'users/editor' => [ | ||
'name' => 'editor', | ||
'permissions' => [ | ||
'languages' => [ | ||
'create' => true, | ||
'update' => false | ||
] | ||
] | ||
], | ||
], | ||
'users' => [ | ||
['email' => '[email protected]', 'role' => 'editor'] | ||
] | ||
]); | ||
|
||
$this->expectException(PermissionException::class); | ||
$this->expectExceptionMessage('You are not allowed to update the language'); | ||
|
||
$app->impersonate('[email protected]'); | ||
|
||
$language = Language::create(['code' => 'en']); | ||
$language->update(['name' => 'English']); | ||
} | ||
|
||
/** | ||
* @covers ::update | ||
*/ | ||
public function testUpdateWithoutLoggedUser() | ||
{ | ||
$this->app->impersonate('kirby'); | ||
$language = Language::create(['code' => 'en']); | ||
|
||
$this->expectException(PermissionException::class); | ||
$this->expectExceptionMessage('You are not allowed to update the language'); | ||
|
||
// unimpersonate and test the method | ||
$this->app->impersonate(); | ||
$language->update(['name' => 'English']); | ||
} | ||
|
||
/** | ||
* @covers ::delete | ||
*/ | ||
public function testDeleteNoPermissions() | ||
{ | ||
$app = $this->app->clone([ | ||
'blueprints' => [ | ||
'users/editor' => [ | ||
'name' => 'editor', | ||
'permissions' => [ | ||
'languages' => [ | ||
'create' => true, | ||
'delete' => false | ||
] | ||
] | ||
], | ||
], | ||
'users' => [ | ||
['email' => '[email protected]', 'role' => 'editor'] | ||
] | ||
]); | ||
|
||
$this->expectException(PermissionException::class); | ||
$this->expectExceptionMessage('You are not allowed to delete the language'); | ||
|
||
$app->impersonate('[email protected]'); | ||
$language = Language::create(['code' => 'en']); | ||
$language->delete(); | ||
} | ||
|
||
/** | ||
* @covers ::delete | ||
*/ | ||
public function testDeleteWithoutLoggedUser() | ||
{ | ||
$this->app->impersonate('kirby'); | ||
$language = Language::create(['code' => 'en']); | ||
|
||
$this->expectException(PermissionException::class); | ||
$this->expectExceptionMessage('You are not allowed to delete the language'); | ||
|
||
// unimpersonate and test the method | ||
$this->app->impersonate(); | ||
$language->delete(); | ||
} | ||
|
||
public function testDeleteHooks() | ||
{ | ||
$calls = 0; | ||
$phpunit = $this; | ||
|
||
new App([ | ||
$app =new App([ | ||
'roots' => [ | ||
'index' => $this->fixtures = __DIR__ . '/fixtures/DeleteHooksTest', | ||
], | ||
|
@@ -604,6 +751,8 @@ public function testDeleteHooks() | |
] | ||
]); | ||
|
||
$app->impersonate('kirby'); | ||
|
||
$language = Language::create([ | ||
'code' => 'en', | ||
'name' => 'English' | ||
|
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