Skip to content

Commit b8a9a4d

Browse files
authored
Merge pull request #251 from mzur/k4
Kirby 4 Support
2 parents aadb892 + 8208988 commit b8a9a4d

36 files changed

+9344
-107
lines changed

.github/workflows/php.yml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
php-versions: ['8.0', '8.1', '8.2']
15+
kirby-versions: ['^3.5', '^4.0-beta.1']
1516

1617
steps:
1718
- uses: actions/checkout@v2
@@ -39,5 +40,8 @@ jobs:
3940
- name: Install dependencies
4041
run: composer install --prefer-dist --no-progress --no-plugins
4142

43+
- name: Install Kirby Version
44+
run: composer require -w getkirby/cms:${{ matrix.kirby-versions }}
45+
4246
- name: Run test suite
4347
run: vendor/bin/phpunit

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
A versatile [Kirby](http://getkirby.com) plugin to handle web form actions.
44

5-
[![Documentation Status](https://readthedocs.org/projects/kirby-uniform/badge/?version=latest)](https://kirby-uniform.readthedocs.io/en/latest/?badge=latest) [![Tests](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml/badge.svg)](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml) ![Kirby 3](https://img.shields.io/badge/Kirby-3-green.svg)
5+
[![Documentation Status](https://readthedocs.org/projects/kirby-uniform/badge/?version=latest)](https://kirby-uniform.readthedocs.io/en/latest/?badge=latest) [![Tests](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml/badge.svg)](https://github.com/mzur/kirby-uniform/actions/workflows/php.yml) ![Kirby >=3](https://img.shields.io/badge/Kirby-%3E=3-green.svg)
66

7-
This is Uniform for Kirby 3. You can find Uniform for Kirby 2 in the [kirby-2 branch](https://github.com/mzur/kirby-uniform/tree/kirby-2).
7+
This is Uniform for Kirby >=3. You can find Uniform for Kirby 2 in the [kirby-2 branch](https://github.com/mzur/kirby-uniform/tree/kirby-2).
88

99
Builtin actions:
1010

composer.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
"docs": "http://kirby-uniform.readthedocs.io"
1717
},
1818
"require": {
19-
"mzur/kirby-form": "^3.0",
20-
"getkirby/composer-installer": "^1.2"
19+
"mzur/kirby-form": "^3.0"
2120
},
2221
"require-dev": {
2322
"phpunit/phpunit": "^9.0",
24-
"mzur/kirby-defuse-session": "^1.0",
25-
"getkirby/cms": "^3.5"
23+
"getkirby/cms": "^3.5 || ^4.0"
2624
},
2725
"autoload": {
2826
"psr-4": {
@@ -40,7 +38,7 @@
4038
"config": {
4139
"optimize-autoloader": true,
4240
"allow-plugins": {
43-
"getkirby/composer-installer": true
41+
"getkirby/composer-installer": false
4442
}
4543
}
4644
}

phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
9-
processIsolation="false"
9+
processIsolation="true"
1010
stopOnFailure="false">
1111
<testsuites>
1212
<testsuite name="Application Test Suite">

src/Actions/EmailAction.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ protected function resolveTemplate($string) {
113113
return is_scalar($item);
114114
});
115115

116-
$minorVersion = intval(explode('.', App::version())[1]);
116+
$version = explode('.', App::version());
117+
$majorVersion = intval($version[0]);
118+
$minorVersion = intval($version[1]);
117119
$fallback = ['fallback' => ''];
118120

119121
// The arguments to Str::template changed in Kirby 3.6.
120-
if ($minorVersion <= 5) {
122+
if ($majorVersion <= 3 && $minorVersion <= 5) {
121123
$fallback = '';
122124
}
123125

tests/Actions/EmailActionTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Kirby\Cms\App;
88
use Uniform\Tests\TestCase;
99
use Uniform\Actions\EmailAction;
10-
use Mzur\Kirby\DefuseSession\Defuse;
1110
use Uniform\Exceptions\PerformerException;
1211

1312
class EmailActionTest extends TestCase
@@ -285,7 +284,7 @@ public function testHandleEmailExceptionNoDebug()
285284

286285
public function testHandleEmailExceptionDebug()
287286
{
288-
Defuse::defuse(['options' => ['debug' => true]]);
287+
App::instance()->extend(['options' => ['debug' => true]]);
289288
$this->form->data('field', 'value');
290289
$action = new EmailActionStub($this->form, [
291290
'service' => 'thrower',

tests/Actions/LogActionTest.php

+5-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Kirby\Cms\App;
7+
use Kirby\Http\Environment;
78
use Uniform\Actions\LogAction;
89
use Uniform\Exceptions\PerformerException;
910
use Uniform\Form;
@@ -27,15 +28,10 @@ public function testFileOptionRequired()
2728

2829
public function testPerform()
2930
{
30-
// We use both SERVER and clone() to be compatible with Kirby 3.5 and 3.7.
3131
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
3232
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla';
33-
App::instance()->clone([
34-
'server' => [
35-
'REMOTE_ADDR' => '127.0.0.1',
36-
'HTTP_USER_AGENT' => 'Mozilla'
37-
]
38-
]);
33+
App::instance()->environment()->detect();
34+
App::instance()->clone();
3935
$this->form->data('message', '<hello>');
4036
$this->form->data('data', ['some', 'data']);
4137
$action = new LogActionStub($this->form, ['file' => '/dev/null']);
@@ -48,15 +44,10 @@ public function testPerform()
4844

4945
public function testPerformEscapeHtml()
5046
{
51-
// We use both SERVER and clone() to be compatible with Kirby 3.5 and 3.7.
5247
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
5348
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla';
54-
App::instance()->clone([
55-
'server' => [
56-
'REMOTE_ADDR' => '127.0.0.1',
57-
'HTTP_USER_AGENT' => 'Mozilla'
58-
]
59-
]);
49+
App::instance()->environment()->detect();
50+
App::instance()->clone();
6051
$this->form->data('message', '<hello>');
6152
$action = new LogActionStub($this->form, [
6253
'file' => '/dev/null',

tests/FormTest.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace Uniform\Tests;
44

5-
use Uniform\Form;
5+
use Jevets\Kirby\Exceptions\TokenMismatchException;
66
use Jevets\Kirby\Flash;
7-
use Uniform\Guards\Guard;
7+
use Kirby\Cms\App;
88
use Uniform\Actions\Action;
99
use Uniform\Exceptions\Exception;
10-
use Mzur\Kirby\DefuseSession\Defuse;
11-
use Jevets\Kirby\Exceptions\TokenMismatchException;
10+
use Uniform\Form;
11+
use Uniform\Guards\Guard;
1212

1313
class FormTest extends TestCase
1414
{
@@ -17,20 +17,19 @@ class FormTest extends TestCase
1717
public function setUp(): void
1818
{
1919
parent::setUp();
20-
Defuse::defuse(['options' => ['debug' => true]]);
2120
$this->form = new FormStub;
2221
}
2322

24-
public function testValidateCsrfException()
23+
public function testValidateCsrfExceptionDebug()
2524
{
25+
App::instance()->extend(['options' => ['debug' => true]]);
2626
csrf(); // Generate a token.
2727
$this->expectException(TokenMismatchException::class);
2828
$this->form->validate();
2929
}
3030

3131
public function testValidateCsrfExceptionNoDebug()
3232
{
33-
Defuse::defuse(['options' => ['debug' => false]]);
3433
csrf(); // Generate a token.
3534

3635
try {
@@ -66,6 +65,7 @@ public function testValidateRedirect()
6665

6766
public function testGuardValidates()
6867
{
68+
App::instance()->extend(['options' => ['debug' => true]]);
6969
$this->expectException(TokenMismatchException::class);
7070
$this->form->guard();
7171
}
@@ -131,12 +131,14 @@ public function testGuardMagicMethod()
131131

132132
public function testActionValidates()
133133
{
134+
App::instance()->extend(['options' => ['debug' => true]]);
134135
$this->expectException(TokenMismatchException::class);
135136
$this->form->action(Action::class);
136137
}
137138

138139
public function testActionValidatesWithoutGuards()
139140
{
141+
App::instance()->extend(['options' => ['debug' => true]]);
140142
$this->expectException(TokenMismatchException::class);
141143
$this->form->withoutGuards()->action(Action::class);
142144
}

tests/TestCase.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
use Jevets\Kirby\Form;
66
use Jevets\Kirby\Flash;
7-
use Mzur\Kirby\DefuseSession\Defuse;
87

98
class TestCase extends \PHPUnit\Framework\TestCase
109
{
1110
/**
1211
* Default preparation for each test.
12+
*
1313
*/
1414
public function setUp(): void
1515
{
1616
parent::setUp();
17-
Defuse::defuse();
1817
$flash = Flash::getInstance();
1918
$flash->set(Form::FLASH_KEY_DATA, null);
2019
$flash->set(Form::FLASH_KEY_ERRORS, null);

vendor/autoload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
require_once __DIR__ . '/composer/autoload_real.php';
1111

12-
return ComposerAutoloaderInitacc6b15f3c23738a905ac70a3027e17a::getLoader();
12+
return ComposerAutoloaderInit979ccd9ac382cfbe433fc1293b41c6ce::getLoader();

0 commit comments

Comments
 (0)