Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kirby 4 Support #251

Merged
merged 9 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2']
kirby-versions: ['^3.5', '^4.0-beta.1']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -39,5 +40,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-plugins

- name: Install Kirby Version
run: composer require -w getkirby/cms:${{ matrix.kirby-versions }}

- name: Run test suite
run: vendor/bin/phpunit
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

[![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)
[![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)

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).
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).

Builtin actions:

Expand Down
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
"docs": "http://kirby-uniform.readthedocs.io"
},
"require": {
"mzur/kirby-form": "^3.0",
"getkirby/composer-installer": "^1.2"
"mzur/kirby-form": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"mzur/kirby-defuse-session": "^1.0",
"getkirby/cms": "^3.5"
"getkirby/cms": "^3.5 || ^4.0"
},
"autoload": {
"psr-4": {
Expand All @@ -40,7 +38,7 @@
"config": {
"optimize-autoloader": true,
"allow-plugins": {
"getkirby/composer-installer": true
"getkirby/composer-installer": false
}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
processIsolation="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
Expand Down
6 changes: 4 additions & 2 deletions src/Actions/EmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ protected function resolveTemplate($string) {
return is_scalar($item);
});

$minorVersion = intval(explode('.', App::version())[1]);
$version = explode('.', App::version());
$majorVersion = intval($version[0]);
$minorVersion = intval($version[1]);
$fallback = ['fallback' => ''];

// The arguments to Str::template changed in Kirby 3.6.
if ($minorVersion <= 5) {
if ($majorVersion <= 3 && $minorVersion <= 5) {
$fallback = '';
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Actions/EmailActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Kirby\Cms\App;
use Uniform\Tests\TestCase;
use Uniform\Actions\EmailAction;
use Mzur\Kirby\DefuseSession\Defuse;
use Uniform\Exceptions\PerformerException;

class EmailActionTest extends TestCase
Expand Down Expand Up @@ -285,7 +284,7 @@ public function testHandleEmailExceptionNoDebug()

public function testHandleEmailExceptionDebug()
{
Defuse::defuse(['options' => ['debug' => true]]);
App::instance()->extend(['options' => ['debug' => true]]);
$this->form->data('field', 'value');
$action = new EmailActionStub($this->form, [
'service' => 'thrower',
Expand Down
19 changes: 5 additions & 14 deletions tests/Actions/LogActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Kirby\Cms\App;
use Kirby\Http\Environment;
use Uniform\Actions\LogAction;
use Uniform\Exceptions\PerformerException;
use Uniform\Form;
Expand All @@ -27,15 +28,10 @@ public function testFileOptionRequired()

public function testPerform()
{
// We use both SERVER and clone() to be compatible with Kirby 3.5 and 3.7.
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla';
App::instance()->clone([
'server' => [
'REMOTE_ADDR' => '127.0.0.1',
'HTTP_USER_AGENT' => 'Mozilla'
]
]);
App::instance()->environment()->detect();
App::instance()->clone();
$this->form->data('message', '<hello>');
$this->form->data('data', ['some', 'data']);
$action = new LogActionStub($this->form, ['file' => '/dev/null']);
Expand All @@ -48,15 +44,10 @@ public function testPerform()

public function testPerformEscapeHtml()
{
// We use both SERVER and clone() to be compatible with Kirby 3.5 and 3.7.
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla';
App::instance()->clone([
'server' => [
'REMOTE_ADDR' => '127.0.0.1',
'HTTP_USER_AGENT' => 'Mozilla'
]
]);
App::instance()->environment()->detect();
App::instance()->clone();
$this->form->data('message', '<hello>');
$action = new LogActionStub($this->form, [
'file' => '/dev/null',
Expand Down
16 changes: 9 additions & 7 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Uniform\Tests;

use Uniform\Form;
use Jevets\Kirby\Exceptions\TokenMismatchException;
use Jevets\Kirby\Flash;
use Uniform\Guards\Guard;
use Kirby\Cms\App;
use Uniform\Actions\Action;
use Uniform\Exceptions\Exception;
use Mzur\Kirby\DefuseSession\Defuse;
use Jevets\Kirby\Exceptions\TokenMismatchException;
use Uniform\Form;
use Uniform\Guards\Guard;

class FormTest extends TestCase
{
Expand All @@ -17,20 +17,19 @@ class FormTest extends TestCase
public function setUp(): void
{
parent::setUp();
Defuse::defuse(['options' => ['debug' => true]]);
$this->form = new FormStub;
}

public function testValidateCsrfException()
public function testValidateCsrfExceptionDebug()
{
App::instance()->extend(['options' => ['debug' => true]]);
csrf(); // Generate a token.
$this->expectException(TokenMismatchException::class);
$this->form->validate();
}

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

try {
Expand Down Expand Up @@ -66,6 +65,7 @@ public function testValidateRedirect()

public function testGuardValidates()
{
App::instance()->extend(['options' => ['debug' => true]]);
$this->expectException(TokenMismatchException::class);
$this->form->guard();
}
Expand Down Expand Up @@ -131,12 +131,14 @@ public function testGuardMagicMethod()

public function testActionValidates()
{
App::instance()->extend(['options' => ['debug' => true]]);
$this->expectException(TokenMismatchException::class);
$this->form->action(Action::class);
}

public function testActionValidatesWithoutGuards()
{
App::instance()->extend(['options' => ['debug' => true]]);
$this->expectException(TokenMismatchException::class);
$this->form->withoutGuards()->action(Action::class);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@

use Jevets\Kirby\Form;
use Jevets\Kirby\Flash;
use Mzur\Kirby\DefuseSession\Defuse;

class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* Default preparation for each test.
*
*/
public function setUp(): void
{
parent::setUp();
Defuse::defuse();
$flash = Flash::getInstance();
$flash->set(Form::FLASH_KEY_DATA, null);
$flash->set(Form::FLASH_KEY_ERRORS, null);
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

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

return ComposerAutoloaderInitacc6b15f3c23738a905ac70a3027e17a::getLoader();
return ComposerAutoloaderInit979ccd9ac382cfbe433fc1293b41c6ce::getLoader();
Loading
Loading