Skip to content

Commit d767771

Browse files
committed
Complete unit tests for new dialog classes
1 parent a8e6f68 commit d767771

File tree

77 files changed

+3176
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3176
-558
lines changed

src/Cms/LanguageVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function update(string|null $value = null): static
132132
/**
133133
* Returns the value if the variable has been translated.
134134
*/
135-
public function value(): string|null
135+
public function value(): string|array|null
136136
{
137137
return $this->language->translations()[$this->key] ?? null;
138138
}

src/Cms/UserActions.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,16 @@ public function createId(): string
298298
public function delete(): bool
299299
{
300300
return $this->commit('delete', ['user' => $this], function ($user) {
301-
if ($user->exists() === false) {
302-
return true;
303-
}
304-
305-
// delete all public assets for this user
306-
Dir::remove($user->mediaRoot());
307-
308-
// delete the user directory
309-
if (Dir::remove($user->root()) !== true) {
310-
throw new LogicException(
311-
message: 'The user directory for "' . $user->email() . '" could not be deleted'
312-
);
301+
if ($user->exists() === true) {
302+
// delete all public assets for this user
303+
Dir::remove($user->mediaRoot());
304+
305+
// delete the user directory
306+
if (Dir::remove($user->root()) !== true) {
307+
throw new LogicException(
308+
message: 'The user directory for "' . $user->email() . '" could not be deleted'
309+
);
310+
}
313311
}
314312

315313
// remove the user from users collection

src/Panel/Ui/Component.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Kirby\Panel\Ui;
44

5-
use Kirby\Exception\LogicException;
6-
use Kirby\Toolkit\Str;
7-
85
/**
96
* Component that can be passed as component-props array
107
* to the Vue Panel frontend
@@ -17,9 +14,8 @@
1714
* @since 5.0.0
1815
* @internal
1916
*/
20-
abstract class Component
17+
abstract class Component extends Renderable
2118
{
22-
protected string $key;
2319
public array $attrs = [];
2420

2521
public function __construct(
@@ -31,40 +27,6 @@ public function __construct(
3127
$this->attrs = $attrs;
3228
}
3329

34-
/**
35-
* Magic setter and getter for component properties
36-
*
37-
* ```php
38-
* $component->class('my-class')
39-
* ```
40-
*/
41-
public function __call(string $name, array $args = [])
42-
{
43-
if (property_exists($this, $name) === false) {
44-
throw new LogicException(
45-
message: 'The property "' . $name . '" does not exist on the UI component "' . $this->component . '"'
46-
);
47-
}
48-
49-
// getter
50-
if ($args === []) {
51-
return $this->$name;
52-
}
53-
54-
// setter
55-
$this->$name = $args[0];
56-
return $this;
57-
}
58-
59-
/**
60-
* Returns a (unique) key that can be used
61-
* for Vue's `:key` attribute
62-
*/
63-
public function key(): string
64-
{
65-
return $this->key ??= Str::random(10, 'alphaNum');
66-
}
67-
6830
/**
6931
* Returns the props that will be passed to the Vue component
7032
*/

src/Panel/Ui/Dialog.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ class Dialog extends Component
2121

2222
public function __construct(
2323
string $component = 'k-dialog',
24-
public string|array|false|null $cancelButton = null,
24+
public string|array|bool|null $cancelButton = null,
2525
string|null $class = null,
2626
public string|null $size = null,
2727
string|null $style = null,
28-
public string|array|false|null $submitButton = null,
28+
public string|array|bool|null $submitButton = null,
29+
...$attrs
2930
) {
30-
parent::__construct(
31-
component: $component,
32-
class: $class,
33-
style: $style
34-
);
31+
parent::__construct(...[
32+
...$attrs,
33+
'component' => $component,
34+
'class' => $class,
35+
'style' => $style
36+
]);
3537

3638
$this->kirby = App::instance();
3739
$this->request = $this->kirby->request();

src/Panel/Ui/Dialogs/FieldDialog.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Kirby\Cms\Find;
66
use Kirby\Form\Field;
7+
use Kirby\Form\FieldClass;
78
use Kirby\Form\Form;
89
use Kirby\Http\Router;
910
use Kirby\Panel\Dialog;
@@ -20,7 +21,7 @@
2021
class FieldDialog
2122
{
2223
public function __construct(
23-
public Field $field,
24+
public Field|FieldClass $field,
2425
public string|null $path = null
2526
) {
2627
}

src/Panel/Ui/Dialogs/FileChangeNameDialog.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public function __construct(
4343

4444
public function submit(): array
4545
{
46-
$name = $this->request->get('name');
47-
$renamed = $this->file->changeName($name);
48-
$oldUrl = $this->file->panel()->url(true);
49-
$newUrl = $renamed->panel()->url(true);
46+
$name = $this->request->get('name');
47+
$oldUrl = $this->file->panel()->url(true);
48+
$this->file = $this->file->changeName($name);
49+
$newUrl = $this->file->panel()->url(true);
5050

5151
$response = [
5252
'event' => 'file.changeName'

src/Panel/Ui/Dialogs/FileChangeTemplateDialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function __construct(
4747

4848
public function submit(): array
4949
{
50-
$template = $this->request->get('template');
51-
$this->file->changeTemplate($template);
50+
$template = $this->request->get('template');
51+
$this->file = $this->file->changeTemplate($template);
5252

5353
return [
5454
'event' => 'file.changeTemplate',

src/Panel/Ui/Dialogs/FormDialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class FormDialog extends Dialog
1717
{
1818
public function __construct(
1919
string|null $component = 'k-form-dialog',
20-
string|array|false|null $cancelButton = null,
20+
string|array|bool|null $cancelButton = null,
2121
public array $fields = [],
2222
string|null $size = 'medium',
23-
string|array|false|null $submitButton = null,
23+
string|array|bool|null $submitButton = null,
2424
public string|null $text = null,
2525
public array $value = []
2626
) {

src/Panel/Ui/Dialogs/IsForLanguageVariable.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Kirby\Panel\Ui\Dialogs;
44

55
use Kirby\Cms\Find;
6-
use Kirby\Cms\Language;
7-
use Kirby\Cms\LanguageVariable;
86

97
/**
108
* @package Kirby Panel
@@ -17,19 +15,11 @@
1715
*/
1816
trait IsForLanguageVariable
1917
{
20-
/**
21-
* @psalm-return ($key is null ? \Kirby\Cms\Language : \Kirby\Cms\LanguageVariable)
22-
*/
2318
public static function for(
2419
string $code,
2520
string|null $key = null
26-
): Language|LanguageVariable {
21+
): static {
2722
$language = Find::language($code);
28-
29-
if ($key === null) {
30-
return new static($language);
31-
}
32-
3323
$variable = $language->variable($key, true);
3424
return new static($variable);
3525
}

src/Panel/Ui/Dialogs/LanguageTranslationCreateDialog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*/
1818
class LanguageTranslationCreateDialog extends FormDialog
1919
{
20-
use IsForLanguageVariable;
20+
use IsForLanguage;
2121

2222
public function __construct(
2323
public Language $language,
24-
string|array|false|null $cancelButton = null,
25-
string|array|false|null $submitButton = null,
24+
string|array|bool|null $cancelButton = null,
25+
string|array|bool|null $submitButton = null,
2626
public string|null $text = null,
2727
) {
2828
parent::__construct(

src/Panel/Ui/Dialogs/LanguageTranslationUpdateDialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function isVariableArray(): bool
6161

6262
public function submit(): true
6363
{
64-
$value = $this->request->get('value', '');
65-
$this->variable->update($value);
64+
$value = $this->request->get('value', '');
65+
$this->variable = $this->variable->update($value);
6666

6767
return true;
6868
}

src/Panel/Ui/Dialogs/LanguageUpdateDialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function locale(): string|array
6363

6464
public function submit(): array
6565
{
66-
$data = $this->request->get(['direction', 'locale', 'name']);
67-
$this->language->update($data);
66+
$data = $this->request->get(['direction', 'locale', 'name']);
67+
$this->language = $this->language->update($data);
6868

6969
return [
7070
'event' => 'language.update'

src/Panel/Ui/Dialogs/PageChangeSortDialog.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public function __construct(
4343

4444
public function submit(): array
4545
{
46-
$this->page->changeStatus(
46+
$position = $this->request->get('position');
47+
$this->page = $this->page->changeStatus(
4748
'listed',
48-
$this->request->get('position')
49+
$position
4950
);
5051

5152
return [

src/Panel/Ui/Dialogs/PageChangeStatusDialog.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Kirby\Cms\Page;
77
use Kirby\Cms\PageBlueprint;
88
use Kirby\Panel\Field;
9+
use Kirby\Panel\Ui\Renderable;
910
use Kirby\Toolkit\I18n;
1011

1112
/**
@@ -17,7 +18,7 @@
1718
* @since 5.0.0
1819
* @internal
1920
*/
20-
class PageChangeStatusDialog
21+
class PageChangeStatusDialog extends Renderable
2122
{
2223
use IsForPage;
2324

@@ -98,9 +99,8 @@ public function states(): array
9899

99100
public function submit(): array
100101
{
101-
$request = App::instance()->request();
102-
103-
$this->page->changeStatus(
102+
$request = App::instance()->request();
103+
$this->page = $this->page->changeStatus(
104104
$request->get('status'),
105105
$request->get('position')
106106
);

src/Panel/Ui/Dialogs/PageChangeTemplateDialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function __construct(
5555

5656
public function submit(): array
5757
{
58-
$template = $this->request->get('template');
59-
$this->page->changeTemplate($template);
58+
$template = $this->request->get('template');
59+
$this->page = $this->page->changeTemplate($template);
6060

6161
return [
6262
'event' => 'page.changeTemplate',

src/Panel/Ui/Dialogs/PageChangeTitleDialog.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Kirby\Panel\Ui\Dialogs;
44

5+
use Kirby\Cms\App;
56
use Kirby\Cms\Page;
67
use Kirby\Cms\PageRules;
78
use Kirby\Panel\Field;
@@ -25,8 +26,10 @@ class PageChangeTitleDialog extends FormDialog
2526
public function __construct(
2627
public Page $page
2728
) {
28-
$permissions = $page->permissions();
29-
$select = $this->request->get('select', 'title');
29+
$this->kirby = App::instance();
30+
$this->request = $this->kirby->request();
31+
$permissions = $page->permissions();
32+
$select = $this->request->get('select', 'title');
3033

3134
parent::__construct(
3235
fields: [
@@ -74,7 +77,7 @@ public function path(): string
7477
return $path;
7578
}
7679

77-
public function submit(): array
80+
public function submit(): array|true
7881
{
7982
$title = trim($this->request->get('title', ''));
8083
$slug = trim($this->request->get('slug', ''));
@@ -98,17 +101,17 @@ public function submit(): array
98101

99102
// the page title changed
100103
if ($this->page->title()->value() !== $title) {
101-
$this->page->changeTitle($title);
104+
$this->page = $this->page->changeTitle($title);
102105
$response['event'][] = 'page.changeTitle';
103106
}
104107

105108
// the slug changed
106109
if ($this->page->slug() !== $slug) {
107110
$response['event'][] = 'page.changeSlug';
108111

109-
$newPage = $this->page->changeSlug($slug);
110-
$oldUrl = $this->page->panel()->url(true);
111-
$newUrl = $newPage->panel()->url(true);
112+
$oldUrl = $this->page->panel()->url(true);
113+
$this->page = $this->page->changeSlug($slug);
114+
$newUrl = $this->page->panel()->url(true);
112115

113116
// check for a necessary redirect after the slug has changed
114117
if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) {

0 commit comments

Comments
 (0)