vite config : ignore /local and /public/** to improve perf
This commit is contained in:
parent
3c9eed7804
commit
c11a85e7f8
32 changed files with 1235 additions and 858 deletions
175
public/site/plugins/kql/tests/InterceptorTest.php
Normal file
175
public/site/plugins/kql/tests/InterceptorTest.php
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Kql;
|
||||
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Cms\Blueprint;
|
||||
use Kirby\Cms\Content;
|
||||
use Kirby\Cms\Field;
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Cms\FileBlueprint;
|
||||
use Kirby\Cms\FileVersion;
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Cms\PageBlueprint;
|
||||
use Kirby\Cms\Role;
|
||||
use Kirby\Cms\Site;
|
||||
use Kirby\Cms\SiteBlueprint;
|
||||
use Kirby\Cms\User;
|
||||
use Kirby\Cms\UserBlueprint;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AppExtended extends App
|
||||
{
|
||||
}
|
||||
class FileExtended extends File
|
||||
{
|
||||
}
|
||||
class PageExtended extends Page
|
||||
{
|
||||
}
|
||||
class RoleExtended extends User
|
||||
{
|
||||
}
|
||||
class SiteExtended extends Site
|
||||
{
|
||||
}
|
||||
class UserExtended extends User
|
||||
{
|
||||
}
|
||||
|
||||
class InterceptorTest extends TestCase
|
||||
{
|
||||
public function objectProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
new App(),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\App'
|
||||
],
|
||||
[
|
||||
new AppExtended(),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\App'
|
||||
],
|
||||
[
|
||||
new Blueprint([
|
||||
'model' => new Page([
|
||||
'slug' => 'test'
|
||||
]),
|
||||
'name' => 'test',
|
||||
]),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Blueprint'
|
||||
],
|
||||
[
|
||||
new Content(),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Content'
|
||||
],
|
||||
[
|
||||
new Field(null, 'key', 'value'),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Field'
|
||||
],
|
||||
[
|
||||
new File(['filename' => 'test.jpg']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\File'
|
||||
],
|
||||
[
|
||||
new FileBlueprint([
|
||||
'model' => new File([
|
||||
'filename' => 'test.jpg'
|
||||
]),
|
||||
'name' => 'test',
|
||||
]),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Blueprint'
|
||||
],
|
||||
[
|
||||
new FileExtended(['filename' => 'test.jpg']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\File'
|
||||
],
|
||||
[
|
||||
new FileVersion([
|
||||
'original' => new File([
|
||||
'filename' => 'test.jpg',
|
||||
]),
|
||||
'url' => '/test.jpg'
|
||||
]),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\FileVersion'
|
||||
],
|
||||
[
|
||||
new Page(['slug' => 'test']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Page'
|
||||
],
|
||||
[
|
||||
new PageBlueprint([
|
||||
'model' => new Page([
|
||||
'slug' => 'test'
|
||||
]),
|
||||
'name' => 'test',
|
||||
]),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Blueprint'
|
||||
],
|
||||
[
|
||||
new PageExtended(['slug' => 'test']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Page'
|
||||
],
|
||||
[
|
||||
new Role(['name' => 'admin']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Role'
|
||||
],
|
||||
[
|
||||
new Site(),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Site'
|
||||
],
|
||||
[
|
||||
new SiteBlueprint([
|
||||
'model' => new Site(),
|
||||
'name' => 'test',
|
||||
]),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Blueprint'
|
||||
],
|
||||
[
|
||||
new SiteExtended(),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Site'
|
||||
],
|
||||
[
|
||||
new User(['email' => 'test@getkirby.com']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\User'
|
||||
],
|
||||
[
|
||||
new UserBlueprint([
|
||||
'model' => new User(['email' => 'test@getkirby.com']),
|
||||
'name' => 'test',
|
||||
]),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\Blueprint'
|
||||
],
|
||||
[
|
||||
new UserExtended(['email' => 'test@getkirby.com']),
|
||||
'Kirby\\Kql\\Interceptors\\Cms\\User'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider objectProvider
|
||||
*/
|
||||
public function testReplace($object, $inspector)
|
||||
{
|
||||
$result = Interceptor::replace($object);
|
||||
$this->assertInstanceOf($inspector, $result);
|
||||
}
|
||||
|
||||
public function testReplaceNonObject()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
$this->expectExceptionMessage('Unsupported value: string');
|
||||
|
||||
$result = Interceptor::replace('hello');
|
||||
}
|
||||
|
||||
public function testReplaceUnknownObject()
|
||||
{
|
||||
$this->expectException('Kirby\Exception\PermissionException');
|
||||
$this->expectExceptionMessage('Access to the class "stdClass" is not supported');
|
||||
|
||||
$object = new \stdClass();
|
||||
$result = Interceptor::replace($object);
|
||||
}
|
||||
}
|
||||
158
public/site/plugins/kql/tests/KqlTest.php
Normal file
158
public/site/plugins/kql/tests/KqlTest.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Kql;
|
||||
|
||||
use Kirby\Cms\App;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class KqlTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->app = new App([
|
||||
'roots' => [
|
||||
'index' => '/dev/null'
|
||||
],
|
||||
'site' => [
|
||||
'children' => [
|
||||
[
|
||||
'slug' => 'projects'
|
||||
],
|
||||
[
|
||||
'slug' => 'about'
|
||||
],
|
||||
[
|
||||
'slug' => 'contact'
|
||||
]
|
||||
],
|
||||
'content' => [
|
||||
'title' => 'Test Site'
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testForbiddenMethod()
|
||||
{
|
||||
$this->expectException("Kirby\Exception\PermissionException");
|
||||
$this->expectExceptionMessage('The method "Kirby\Cms\Page::delete()" is not allowed in the API context');
|
||||
$result = Kql::run('site.children.first.delete');
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
$result = Kql::run('site.title');
|
||||
$expected = 'Test Site';
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
public function testQuery()
|
||||
{
|
||||
$result = Kql::run([
|
||||
'query' => 'site.children',
|
||||
'select' => 'slug'
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'slug' => 'projects',
|
||||
],
|
||||
[
|
||||
'slug' => 'about',
|
||||
],
|
||||
[
|
||||
'slug' => 'contact',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
public function testSelectWithAlias()
|
||||
{
|
||||
$result = Kql::run([
|
||||
'select' => [
|
||||
'myTitle' => 'site.title'
|
||||
]
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
'myTitle' => 'Test Site',
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
public function testSelectWithArray()
|
||||
{
|
||||
$result = Kql::run([
|
||||
'select' => ['title', 'url']
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
'title' => 'Test Site',
|
||||
'url' => '/'
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
public function testSelectWithBoolean()
|
||||
{
|
||||
$result = Kql::run([
|
||||
'select' => [
|
||||
'title' => true
|
||||
]
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
'title' => 'Test Site'
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
public function testSelectWithQuery()
|
||||
{
|
||||
$result = Kql::run([
|
||||
'select' => [
|
||||
'children' => [
|
||||
'query' => 'site.children',
|
||||
'select' => 'slug'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
'children' => [
|
||||
[
|
||||
'slug' => 'projects',
|
||||
],
|
||||
[
|
||||
'slug' => 'about',
|
||||
],
|
||||
[
|
||||
'slug' => 'contact',
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
public function testSelectWithString()
|
||||
{
|
||||
$result = Kql::run([
|
||||
'select' => [
|
||||
'title' => 'site.title.upper'
|
||||
]
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
'title' => 'TEST SITE'
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
}
|
||||
25
public/site/plugins/kql/tests/bootstrap.php
Normal file
25
public/site/plugins/kql/tests/bootstrap.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
ini_set('memory_limit', '512M');
|
||||
ini_set('display_errors', 'on');
|
||||
ini_set('display_startup_errors', 'on');
|
||||
|
||||
require_once dirname(__DIR__, 1) . '/vendor/autoload.php';
|
||||
|
||||
// regular setup
|
||||
$bootstrapper = dirname(__DIR__, 4) . '/kirby/bootstrap.php';
|
||||
|
||||
if (is_file($bootstrapper)) {
|
||||
require_once $bootstrapper;
|
||||
}
|
||||
|
||||
// sandbox
|
||||
$bootstrapper = dirname(__DIR__, 5) . '/kirby/bootstrap.php';
|
||||
|
||||
if (is_file($bootstrapper)) {
|
||||
require_once $bootstrapper;
|
||||
}
|
||||
|
||||
kirby();
|
||||
Loading…
Add table
Add a link
Reference in a new issue