Compare commits

..

15 Commits

Author SHA1 Message Date
Jérémy Dufraisse
1c89b6cb4f fix(App/rewrite): detect when at root 2023-12-25 17:19:04 +01:00
Jérémy Dufraisse
910596dae3 fix(composer): migrate to accolades 2023-12-25 17:17:49 +01:00
Jérémy Dufraisse
00b18b134d feat(composer): allow php ^7.2.5 2023-03-23 11:43:30 +01:00
Jérémy Dufraisse
7b1cd11017 feat(AppTest): test themes and plugins url 2023-03-21 12:40:54 +01:00
Jérémy Dufraisse
02601c54a3 feat(AppTest): define test on url rewrite 2023-03-21 12:04:41 +01:00
Jérémy Dufraisse
d4711dddd1 fix(AppTest): add error handlers on exit 2023-03-21 08:55:54 +01:00
Jérémy Dufraisse
1f89a43499 feat(AppTest): next test to usr phpunit 2023-03-20 17:11:41 +01:00
Jérémy Dufraisse
43dd441473 fix(AppTest) :make it works 2023-03-20 16:15:18 +01:00
Jérémy Dufraisse
d8e64eeaa9 Merge branch 'feat/seacms-app-test-common' 2023-03-20 08:52:23 +01:00
Jérémy Dufraisse
b6a2a22389 feat(test/commen): add helpers for SERVER manipulating 2023-03-20 08:51:54 +01:00
Jérémy Dufraisse
efad1f8b92 fix(Test/Common): to be able to define all possible $_SERVER 2023-03-20 08:46:02 +01:00
Jérémy Dufraisse
fdd6f50d46 feat(Test/common): create 2023-03-19 20:18:57 +01:00
Jérémy Dufraisse
804ddb76d4 feat(tests): add them first step 2023-03-19 13:21:37 +01:00
Jérémy Dufraisse
0ad57c277f fix(SeacmsAppPlugin): use new version 2023-03-16 23:01:59 +01:00
Jérémy Dufraisse
323b145b94 refactor(composer-plugin): install it via seacms-app 2023-03-16 22:02:52 +01:00
10 changed files with 645 additions and 795 deletions

View File

@ -11,6 +11,7 @@ use Exception;
use Pico;
use SeacmsAppPlugin;
use SeaCMS\Api\SpecialOutputException;
use SeaCMS\App\TestInterface;
use Throwable;
set_error_handler(function (
@ -51,7 +52,7 @@ class App
*/
protected $pico;
public function __construct(string $contentFolderFromRoot)
public function __construct(string $contentFolderFromRoot, ?TestInterface $testRunner = null)
{
// sanitize content folder
$cwd = getcwd();
@ -76,7 +77,7 @@ class App
self::PLUGINS_PATH, // plugins dir
self::THEMES_PATH // themes dir
);
$this->pico->loadPlugin(new SeacmsAppPlugin($this->pico));
$this->pico->loadPlugin(new SeacmsAppPlugin($this->pico, $testRunner));
$this->update_SERVERIfNeeded($this->pico, $contentFolderFromRoot);
}

View File

@ -5,6 +5,8 @@
use SeaCMS\Api\LateApiAware;
use SeaCMS\Api\JsonResponse;
use SeaCMS\App\MdResponse;
use SeaCMS\App\TestInterface;
use SeaCMS\App\TestOnPageRenderingInterface;
/**
* A plugin for SeaCMS-app.
@ -15,7 +17,38 @@ class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware
* Pico API version.
* @var int
*/
const API_VERSION = 3;
const API_VERSION = 4;
/**
* define if test output should be defined
* @var bool
*/
protected $triggerTest;
/**
* define if test output should be defined onPageRendering
* @var bool
*/
protected $triggerTestOnPageRendering;
/**
* define test
* @var TestInterface
*/
protected $testRunner;
/**
* construct
* @param Pico $pico current instance of Pico
* @param ?TestInterface $testRunner optional
*/
public function __construct(Pico $pico, $testRunner = null)
{
parent::__construct($pico);
$this->triggerTest = !empty($testRunner) && ($testRunner instanceof TestInterface);
$this->triggerTestOnPageRendering = !empty($testRunner) && ($testRunner instanceof TestOnPageRenderingInterface);
$this->testRunner = ($this->triggerTest) ? $testRunner : null;
}
/**
* return api routes
@ -136,4 +169,29 @@ class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware
return $this->apiPageAsMd("$folder1/$folder2/$folder3/$pageName");
}
/**
* Triggered after Pico has rendered the page
*
* @param string &$output contents which will be sent to the user
*/
public function onPageRendered(&$output)
{
if ($this->triggerTest){
$this->testRunner->run($this,$output);
}
}
/**
* Triggered before Pico renders the page
*
* @param string &$templateName file name of the template
* @param array &$twigVariables template variables
*/
public function onPageRendering(&$templateName, array &$twigVariables)
{
if ($this->triggerTestOnPageRendering){
$this->testRunner->runOnPageRendering($this,$templateName,$twigVariables);
}
}
}

View File

@ -5,26 +5,29 @@
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": "^8.0",
"php": "^7.2.5||^8.0",
"ext-dom": "*",
"ext-filter": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-pcre": "*",
"picocms/composer-installer": "dev-pico-3.0",
"picocms/pico": "dev-fix-compatibility-php8 as v3.0.0-alpha.2",
"picocms/pico": "dev-pico-3.0",
"seacms/composer-plugin": "dev-master",
"seacms/seacms-api": "dev-master",
"seacms/seacms-auth": "dev-master"
},
"config": {
"optimize-autoloader": true,
"platform": {
"php": "8.0.0"
"php": "7.2.5"
},
"platform-check": true,
"sort-packages": true,
"allow-plugins": {
"picocms/composer-installer": true
"picocms/composer-installer": true,
"topfloor/composer-cleanup-vcs-dirs": false,
"seacms/composer-plugin": false
}
},
"suggest": {
@ -33,6 +36,7 @@
"autoload": {
"classmap": ["App.php","SeacmsAppPlugin.php"],
"psr-4": {
"SeaCMS\\App\\Test\\": "tests",
"SeaCMS\\App\\": "src"
}
},
@ -54,15 +58,15 @@
"repositories": [
{
"type": "vcs",
"url": "https://git.defis.info/SeaCMS/pico"
"url": "https://git.accolades.coop/SeaCMS/seacms-api"
},
{
"type": "vcs",
"url": "https://git.defis.info/SeaCMS/seacms-api"
"url": "https://git.accolades.coop/SeaCMS/seacms-auth"
},
{
"type": "vcs",
"url": "https://git.defis.info/SeaCMS/seacms-auth"
"url": "https://git.accolades.coop/SeaCMS/composer-plugin"
}
]
}

785
composer.lock generated
View File

@ -1,785 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "be708ff9986d2fb174120f724aaf733a",
"packages": [
{
"name": "erusev/parsedown",
"version": "v2.0.0-beta-1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "32278afaf36c758de026b66661d3afd6dfbea743"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/32278afaf36c758de026b66661d3afd6dfbea743",
"reference": "32278afaf36c758de026b66661d3afd6dfbea743",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": "^7.1||^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0.0",
"infection/infection": "^0.25.0",
"phpunit/phpunit": "^9.3.11||^8.5.21||^7.5.20",
"roave/infection-static-analysis-plugin": "^1.10.0",
"vimeo/psalm": "^4.10.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Erusev\\Parsedown\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "Parser for Markdown.",
"homepage": "http://parsedown.org",
"keywords": [
"markdown",
"parser"
],
"support": {
"issues": "https://github.com/erusev/parsedown/issues",
"source": "https://github.com/erusev/parsedown/tree/v2.0.0-beta-1"
},
"time": "2022-05-21T21:40:24+00:00"
},
{
"name": "erusev/parsedown-extra",
"version": "v2.0.0-beta-1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown-extra.git",
"reference": "aaed6a888230a9ffb5ef35e9f403ba2b5e4e21ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/aaed6a888230a9ffb5ef35e9f403ba2b5e4e21ef",
"reference": "aaed6a888230a9ffb5ef35e9f403ba2b5e4e21ef",
"shasum": ""
},
"require": {
"erusev/parsedown": "^2.0.0|^2.0.0-beta-1",
"ext-mbstring": "*",
"php": "^7.1||^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0.0",
"infection/infection": "^0.25.0",
"phpunit/phpunit": "^9.3.11||^8.5.21||^7.5.20",
"roave/infection-static-analysis-plugin": "^1.10.0",
"vimeo/psalm": "^4.10.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Erusev\\ParsedownExtra\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "An extension of Parsedown that adds support for Markdown Extra.",
"homepage": "https://github.com/erusev/parsedown-extra",
"keywords": [
"markdown",
"markdown extra",
"parsedown",
"parser"
],
"support": {
"issues": "https://github.com/erusev/parsedown-extra/issues",
"source": "https://github.com/erusev/parsedown-extra/tree/v2.0.0-beta-1"
},
"time": "2022-05-21T21:46:56+00:00"
},
{
"name": "picocms/composer-installer",
"version": "dev-pico-3.0",
"source": {
"type": "git",
"url": "https://github.com/picocms/composer-installer.git",
"reference": "8e59c0f0ab55af384b4a788179de4e169bb1f60e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/picocms/composer-installer/zipball/8e59c0f0ab55af384b4a788179de4e169bb1f60e",
"reference": "8e59c0f0ab55af384b4a788179de4e169bb1f60e",
"shasum": ""
},
"require": {
"composer-plugin-api": "^2.1",
"php": ">=7.2"
},
"type": "composer-plugin",
"extra": {
"class": "picocms\\ComposerInstaller\\Plugin",
"branch-alias": {
"dev-master": "1.0.x-dev",
"dev-pico-3.0": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"picocms\\ComposerInstaller\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniel Rudolf",
"email": "picocms.org@daniel-rudolf.de",
"role": "Lead Developer"
},
{
"name": "The Pico Community",
"homepage": "https://picocms.org/"
},
{
"name": "Contributors",
"homepage": "https://github.com/picocms/composer-installer/graphs/contributors"
}
],
"description": "A composer plugin responsible for installing plugins and themes for Pico, a stupidly simple, blazing fast, flat file CMS.",
"homepage": "https://picocms.org/",
"keywords": [
"composer",
"composer-installer",
"composer-plugin",
"pico",
"pico-cms",
"picocms",
"picocms-installer",
"picocms-plugin",
"picocms-theme"
],
"support": {
"issues": "https://github.com/picocms/composer-installer/issues",
"source": "https://github.com/picocms/composer-installer"
},
"time": "2022-02-27T16:50:04+00:00"
},
{
"name": "picocms/pico",
"version": "dev-fix-compatibility-php8",
"source": {
"type": "git",
"url": "https://git.defis.info/SeaCMS/pico",
"reference": "0187138622d9c8776be3324ed904abd6371c256f"
},
"require": {
"erusev/parsedown": "^2.0.0-beta-1",
"erusev/parsedown-extra": "^2.0.0-beta-1",
"ext-mbstring": "*",
"php": "^7.0.8 || ^8.0",
"symfony/yaml": "^3.4",
"twig/twig": "^2.12"
},
"suggest": {
"picocms/composer-installer": "This Composer plugin is responsible for installing Pico plugins and themes using the Composer package manager.",
"picocms/pico-deprecated": "PicoDeprecated's purpose is to maintain backward compatibility to older versions of Pico.",
"picocms/pico-theme": "Pico requires a theme to actually display the contents of your website. This is Pico's official default theme."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev",
"dev-pico-3.0": "3.0.x-dev"
}
},
"autoload": {
"psr-0": {
"Pico": "lib/",
"PicoPluginInterface": "lib/",
"AbstractPicoPlugin": "lib/"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Gilbert Pellegrom",
"email": "gilbert@pellegrom.me",
"role": "Project Founder"
},
{
"name": "Daniel Rudolf",
"email": "picocms.org@daniel-rudolf.de",
"role": "Lead Developer"
},
{
"name": "The Pico Community",
"homepage": "http://picocms.org/"
},
{
"name": "Contributors",
"homepage": "https://github.com/picocms/Pico/graphs/contributors"
}
],
"description": "Pico is a flat file CMS, this means there is no administration backend and database to deal with. You simply create .md files in the \"content\" folder and that becomes a page.",
"homepage": "http://picocms.org/",
"keywords": [
"cms",
"content-management",
"flat-file",
"markdown",
"markdown-to-html",
"php",
"pico",
"pico-cms",
"picocms",
"simple",
"twig",
"website",
"yaml"
],
"support": {
"docs": "http://picocms.org/docs",
"issues": "https://github.com/picocms/Pico/issues",
"source": "https://github.com/picocms/Pico"
},
"time": "2023-03-10T23:35:40+00:00"
},
{
"name": "seacms/seacms-api",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://git.defis.info/SeaCMS/seacms-api",
"reference": "f5b81d351454f2b7fe4c09d462f7802241ca94d1"
},
"require": {
"php": "^8.0"
},
"default-branch": true,
"type": "pico-plugin",
"autoload": {
"psr-4": {
"SeaCMS\\Api\\": "src"
},
"classmap": [
"SeacmsApi.php"
]
},
"license": [
"EUPL-1.2"
],
"authors": [
{
"name": "Jérémy Dufraisse",
"homepage": "https://github.com/J9rem",
"role": "SeaCMS developer"
}
],
"description": "API route for SeaCMS",
"homepage": "https://git.defis.info/SeaCMS/seacms-api",
"keywords": [
"api",
"pico",
"picocms",
"picocms-plugin"
],
"support": {
"docs": "https://git.defis.info/SeaCMS/seacms-api/src/branch/master/README.md",
"issues": "https://git.defis.info/SeaCMS/seacms-api/issues",
"source": "https://git.defis.info/SeaCMS/seacms-api"
},
"time": "2023-03-02T17:19:44+00:00"
},
{
"name": "seacms/seacms-auth",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://git.defis.info/SeaCMS/seacms-auth",
"reference": "eef1cad3ccb4deda8f9fbccf01880e0040be3c97"
},
"require": {
"php": "^8.0",
"seacms/seacms-api": "dev-master"
},
"default-branch": true,
"type": "pico-plugin",
"autoload": {
"classmap": [
"SeacmsAuth.php"
]
},
"license": [
"EUPL-1.2"
],
"authors": [
{
"name": "Jérémy Dufraisse",
"homepage": "https://github.com/J9rem",
"role": "SeaCMS developer"
}
],
"description": "API route for SeaCMS",
"homepage": "https://git.defis.info/SeaCMS/seacms-auth",
"keywords": [
"auth",
"pico",
"picocms",
"picocms-plugin"
],
"support": {
"docs": "https://git.defis.info/SeaCMS/seacms-auth/src/branch/master/README.md",
"issues": "https://git.defis.info/SeaCMS/seacms-auth/issues",
"source": "https://git.defis.info/SeaCMS/seacms-auth"
},
"time": "2023-03-11T17:16:33+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-ctype": "*"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-mbstring": "*"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-php72",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php72.git",
"reference": "869329b1e9894268a8a61dabb69153029b7a8c97"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/869329b1e9894268a8a61dabb69153029b7a8c97",
"reference": "869329b1e9894268a8a61dabb69153029b7a8c97",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Php72\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php72/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/yaml",
"version": "v3.4.47",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "88289caa3c166321883f67fe5130188ebbb47094"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/88289caa3c166321883f67fe5130188ebbb47094",
"reference": "88289caa3c166321883f67fe5130188ebbb47094",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/polyfill-ctype": "~1.8"
},
"conflict": {
"symfony/console": "<3.4"
},
"require-dev": {
"symfony/console": "~3.4|~4.0"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Yaml\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v3.4.47"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-10-24T10:57:07+00:00"
},
{
"name": "twig/twig",
"version": "v2.15.4",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "3e059001d6d597dd50ea7c74dd2464b4adea48d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/3e059001d6d597dd50ea7c74dd2464b4adea48d3",
"reference": "3e059001d6d597dd50ea7c74dd2464b4adea48d3",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "^1.3",
"symfony/polyfill-php72": "^1.8"
},
"require-dev": {
"psr/container": "^1.0",
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.15-dev"
}
},
"autoload": {
"psr-0": {
"Twig_": "lib/"
},
"psr-4": {
"Twig\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Twig Team",
"role": "Contributors"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com",
"role": "Project Founder"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "https://twig.symfony.com",
"keywords": [
"templating"
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v2.15.4"
},
"funding": [
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
"type": "tidelift"
}
],
"time": "2022-12-27T12:26:20+00:00"
}
],
"packages-dev": [],
"aliases": [
{
"package": "picocms/pico",
"version": "dev-fix-compatibility-php8",
"alias": "v3.0.0-alpha.2",
"alias_normalized": "3.0.0.0-alpha2"
}
],
"minimum-stability": "dev",
"stability-flags": {
"picocms/composer-installer": 20,
"picocms/pico": 20,
"seacms/seacms-api": 20,
"seacms/seacms-auth": 20
},
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^8.0",
"ext-dom": "*",
"ext-filter": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-pcre": "*"
},
"platform-dev": [],
"platform-overrides": {
"php": "8.0.0"
},
"plugin-api-version": "2.3.0"
}

46
src/TestBaseUrl.php Normal file
View File

@ -0,0 +1,46 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
namespace SeaCMS\App;
use SeacmsAppPlugin;
use SeaCMS\App\TestException;
use SeaCMS\App\TestOnPageRenderingInterface;
use SeaCMS\App\TestBaseUrlException;
/**
* test base Url
*/
class TestBaseUrl implements TestOnPageRenderingInterface
{
/**
* run tests
* @param SeacmsAppPlugin $plugin
* @param string $templateName file name of the template
* @param array $twigVariables template variables
* @throws TestException
*/
public function runOnPageRendering(SeacmsAppPlugin $plugin, string $templateName, array $twigVariables)
{
$pico = $plugin->getPico();
throw new TestBaseUrlException(
$pico->getBaseUrl(),
$pico->getRootDir(),
$pico->getPluginsDir(),
$pico->getThemesDir(),
$pico->getCurrentPage(),
$twigVariables,
"Testing base url"
);
}
/**
* run tests
* @param SeacmsAppPlugin $plugin
* @param string $output
* @throws TestException
*/
public function run(SeacmsAppPlugin $plugin, string $output){
}
}

View File

@ -0,0 +1,126 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
namespace SeaCMS\App;
use SeaCMS\App\TestException;
use Throwable;
/**
* define exception to caught return for tests
*/
class TestBaseUrlException extends TestException
{
/**
* caught baseUrl
* @var string
*/
protected $baseUrl;
/**
* plugin dir
* @var string
*/
protected $pluginDir;
/**
* root dir
* @var string
*/
protected $rootDir;
/**
* theme dir
* @var string
*/
protected $themeDir;
/**
* currentPage
* @var null|array
*/
protected $currentPage;
/**
* twigVariables
* @var null|array
*/
protected $twigVariables;
public function __construct(
string $baseUrl,
string $rootDir,
string $pluginDir,
string $themeDir,
?array $currentPage,
?array $twigVariables,
string $message = "",
int $code=0,
Throwable $th = null
)
{
parent::__construct($message,$code,$th);
$this->baseUrl = $baseUrl;
$this->rootDir = $rootDir;
$this->pluginDir = $pluginDir;
$this->themeDir = $themeDir;
$this->currentPage = $currentPage;
$this->twigVariables = $twigVariables;
}
/**
* get baseUrl
* @return string
*/
public function getBaseUrl(): string
{
return $this->baseUrl;
}
/**
* get pluginDir
* @return string
*/
public function getPluginDir(): string
{
return $this->pluginDir;
}
/**
* get rootDir
* @return string
*/
public function getRootDir(): string
{
return $this->rootDir;
}
/**
* get themeDir
* @return string
*/
public function getThemeDir(): string
{
return $this->themeDir;
}
/**
* get currentPage
* @return null|array
*/
public function getcurrentPage(): ?array
{
return $this->currentPage;
}
/**
* get twigVariables
* @return null|array
*/
public function getTwigVariables(): ?array
{
return $this->twigVariables;
}
}

14
src/TestException.php Normal file
View File

@ -0,0 +1,14 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
namespace SeaCMS\App;
use Exception;
use SeaCMS\App\TestException;
/**
* define exception to caught return for tests
*/
class TestException extends Exception
{}

22
src/TestInterface.php Normal file
View File

@ -0,0 +1,22 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
namespace SeaCMS\App;
use SeacmsAppPlugin;
use SeaCMS\App\TestException;
/**
* define interface for tests
*/
interface TestInterface
{
/**
* run tests
* @param SeacmsAppPlugin $plugin
* @param string $output
* @throws TestException
*/
public function run(SeacmsAppPlugin $plugin, string $output);
}

View File

@ -0,0 +1,24 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
namespace SeaCMS\App;
use SeacmsAppPlugin;
use SeaCMS\App\TestException;
use SeaCMS\App\TestInterface;
/**
* define interface for tests
*/
interface TestOnPageRenderingInterface extends TestInterface
{
/**
* run tests
* @param SeacmsAppPlugin $plugin
* @param string $templateName file name of the template
* @param array $twigVariables template variables
* @throws TestException
*/
public function runOnPageRendering(SeacmsAppPlugin $plugin, string $templateName, array $twigVariables);
}

340
tests/AppTest.php Normal file
View File

@ -0,0 +1,340 @@
<?php
/**
* SPDX-License-Identifier: EUPL-1.2
* Authors: see /README.md
*/
namespace SeaCMS\App\Test;
use PHPUnit\Framework\TestCase;
use SeaCMS\App;
use SeaCMS\App\TestBaseUrl;
use SeaCMS\App\TestBaseUrlException;
use Throwable;
final class AppTest extends TestCase {
/**
* register error handlers
*/
public function testInit()
{
$displayErrors = true;
set_error_handler(function(
int $errno,
string $errstr,
?string $errfile = null,
?int $errline = null,
?array $errcontext = null
) use (&$displayErrors){
if ($displayErrors){
echo "\nError $errstr ($errno)\nIn file $errfile\nLine : $errline\n";
}
});
register_shutdown_function(function (){
$lastErr = error_get_last();
if (!is_null($lastErr)){
echo "\nAn error occured\n".json_encode($lastErr)."\n";
}
});
$this->assertTrue($displayErrors);
}
/**
* @depends testInit
* @dataProvider apiRewriteProvider
* @covers App::update_SERVERIfNeeded
* @param string $rootFolder
* @param string $filePath
* @param string $shortScriptName
* @param string $queryString
* @param string $waitedBaseUrl
* @param string $waitedPageId
* @param string $waitedPageUrl
* @param string $waitedThemesUrl
* @param string $waitedPluginsUrl
*/
public function testApiRewrite(
string $rootFolder,
string $filePath,
string $shortScriptName,
string $queryString,
string $waitedBaseUrl,
string $waitedPageId,
string $waitedPageUrl,
string $waitedThemesUrl,
string $waitedPluginsUrl,
): void
{
$this->saveSERVER();
$this->defineServer(
true,
$filePath,
$shortScriptName,
$queryString
);
$app = new App($rootFolder,new TestBaseUrl());
$thrown = false;
$foundTh = null;
try {
$output = $app->runPico();
} catch (TestBaseUrlException $th) {
$thrown = true;
$foundTh = $th;
} catch (Throwable $th){
}
$cwd = getcwd();
$this->revertSERVER();
$this->assertTrue($thrown,"TestBaseUrlException not found");
$this->assertEquals($waitedBaseUrl,$foundTh->getBaseUrl(),"Not same baseUrl");
$this->assertEquals("$cwd/vendor/picocms/plugins/",$foundTh->getPluginDir(),"Not same pluginDir");
$this->assertEquals("$cwd/vendor/picocms/themes/",$foundTh->getThemeDir(),"Not same themeDir");
$this->assertEquals("$cwd/",$foundTh->getRootDir(),"Not same rootDir");
$currentPage = $foundTh->getcurrentPage();
$this->assertIsArray($currentPage,"Current Page should be an array");
$this->assertArrayHasKey('id',$currentPage,"Current Page should be an array with key 'id'");
$this->assertEquals($waitedPageId,$currentPage['id'],"Not waited page's id");
$this->assertArrayHasKey('url',$currentPage,"Current Page should be an array with key 'url'");
$this->assertEquals($waitedPageUrl,$currentPage['url'],"Not waited page's url");
$twigVariables = $foundTh->getTwigVariables();
$this->assertIsArray($twigVariables,"Twigvariables should be an array");
$this->assertArrayHasKey('themes_url',$twigVariables,"Twigvariables should be an array with key 'themes_url'");
$this->assertEquals($waitedThemesUrl,$twigVariables['themes_url'],"Not waited themes_url");
$this->assertArrayHasKey('plugins_url',$twigVariables,"Twigvariables should be an array with key 'plugins_url'");
$this->assertEquals($waitedPluginsUrl,$twigVariables['plugins_url'],"Not waited plugins_url");
}
public function apiRewriteProvider()
{
$data = [];
$this->prepareAPage($data,'','content','index');
$this->prepareAPage($data,'','content','sub/index');
$this->prepareAPage($data,'','content','theme');
$this->prepareAPage($data,'','sites/default','index');
$this->prepareAPage($data,'','sites/default','sub/index');
$this->prepareAPage($data,'','sites/default','theme');
$this->prepareAPage($data,'/sea','content','index');
$this->prepareAPage($data,'/sea','content','sub/index');
$this->prepareAPage($data,'/sea','content','theme');
$this->prepareAPage($data,'/sea','sites/default','index');
$this->prepareAPage($data,'/sea','sites/default','sub/index');
$this->prepareAPage($data,'/sea','sites/default','theme');
// echo "\n";
// foreach($data as $name => $line){
// echo "$name => ".implode(',',$line)."\n";
// }
return $data;
}
protected function prepareAPage(
array &$data,
string $baseScriptName,
string $rootFolder,
string $pageId
)
{
$baseUrl = 'http://localhost'.$baseScriptName.'/';
$isIndex = ($pageId == 'index');
$isSubIndex = (substr($pageId,-strlen('/index')) == '/index');
$pageIdInUrl = $isIndex ? '' : ($isSubIndex ? substr($pageId,0,-strlen('/index')) : $pageId) ;
$queriesStrings = $isIndex ? [['q'=>'','s'=>'','f'=>'']] : [
['q'=>$pageIdInUrl,'s'=>'','f'=>''],
['q'=>'','s'=>$pageIdInUrl,'f'=>''],
['q'=>'','s'=>$pageIdInUrl,'f'=>$pageIdInUrl],
['q'=>$pageIdInUrl,'s'=>$pageIdInUrl,'f'=>''],
['q'=>$pageIdInUrl,'s'=>$pageIdInUrl,'f'=>$pageIdInUrl]
];
foreach ($queriesStrings as $queryData) {
$queryString = empty($queryData['q']) ? '' :'?'.$queryData['q'];
$scriptNameMiddle = empty($queryData['s']) ? '' : $queryData['s'].'/';
foreach (['','index.php'] as $endScriptName) {
$formattedQueryString = str_replace('/','%2F',$queryString);
$pageUrl = empty($queryData['s']) ? (empty($queryData['q']) ? '' : $formattedQueryString) : $queryData['s'];
$canRewriteFromRoot = empty($queryData['s']) && empty($queryData['f']);
if ($rootFolder == 'content' && $canRewriteFromRoot){
$scriptName = "$baseScriptName/$scriptNameMiddle$endScriptName";
$name = $rootFolder.$scriptName.$queryString.'*';
$this->prepareData($data,$name,$rootFolder,'index.php',$scriptName,$queryData['q'],$baseUrl,$pageId,$pageUrl);
}
foreach ([false,true] as $withRewrite) {
if ($withRewrite){
$scriptName = "$baseScriptName/$scriptNameMiddle$endScriptName";
$name = $rootFolder.$scriptName.$queryString.' R';
$waitedUrl = $baseUrl;
} else {
$scriptName = "$baseScriptName/$rootFolder/$scriptNameMiddle$endScriptName";
$name = $rootFolder.$scriptName.$queryString;
$waitedUrl = $baseUrl.$rootFolder.'/';
}
if ($canRewriteFromRoot){
$this->prepareData($data,$name."*",$rootFolder,"index.php",$scriptName,$queryData['q'],$waitedUrl,$pageId,$pageUrl);
}
$formattedRootMiddle = empty($pageIdInUrl) ? '' : "/$pageIdInUrl";
$this->prepareData($data,$name,$rootFolder,"$rootFolder$formattedRootMiddle/index.php",$scriptName,$queryData['q'],$waitedUrl,$pageId,$pageUrl);
}
}
}
}
protected function prepareData(
array &$data,
string $name,
string $rootFolder,
string $filePath,
string $shortScriptName,
string $queryString,
string $waitedBaseUrl,
string $waitedPageId,
string $waitedPageEndUrl
)
{
$waitedPageUrl = $waitedBaseUrl.$waitedPageEndUrl;
$nbLevels = in_array($shortScriptName,['/','/index.php']) ? 0 : count(explode('/',$rootFolder));
$prefix = implode('/',array_fill(0,$nbLevels,'..'));
if (!empty($prefix)){
$prefix .= '/';
}
$waitedThemesUrl = $waitedBaseUrl.$prefix.'vendor/picocms/themes';
$waitedPluginsUrl = $waitedBaseUrl.$prefix.'vendor/picocms/plugins';
$data[$name] = compact([
'rootFolder',
'filePath',
'shortScriptName',
'queryString',
'waitedBaseUrl',
'waitedPageId',
'waitedPageUrl',
'waitedThemesUrl',
'waitedPluginsUrl'
]);
}
/**
* define $_SERVER because fastcgi not run in CLI
* @param bool $reset reset previous $_SERVER
* @param string $filePath realpath of current script file
* @param string $shortScriptName uri path of current script file
* @param string $queryString wanted query string
* @param string $method
* @param string $pathInfo
*/
public function defineServer(
bool $reset,
string $filePath,
string $shortScriptName,
string $queryString,
string $method = 'GET',
string $pathInfo = ''
)
{
if (is_file($filePath)){
if (!is_array($_SERVER) || $reset){
$new = [];
if (is_array($_SERVER)){
foreach(['SERVER_SOFTWARE','SERVER_PROTOCOL','GATEWAY_INTERFACE'] as $key){
if (array_key_exists($key,$_SERVER)){
$new[$key] = $_SERVER[$key];
}
}
}
$_SERVER = $new;
}
$_SERVER['QUERY_STRING'] = $queryString;
$_SERVER['REQUEST_METHOD'] = in_array($method,['GET','POST','PUT','DELETE','HEAD']) ? $method : 'GET';
// $_SERVER['CONTENT_TYPE'] = 'not defined';
// $_SERVER['CONTENT_LENGTH'] = 'not defined';
$documentRoot = dirname(realpath($filePath));
$fileName = basename(realpath($filePath));
$documentRootShort = (substr($documentRoot,-strlen(DIRECTORY_SEPARATOR)) != DIRECTORY_SEPARATOR)
? $documentRoot
: substr($documentRoot,0,-strlen(DIRECTORY_SEPARATOR));
$documentRootFull = $documentRootShort.DIRECTORY_SEPARATOR;
$scriptName = (basename($shortScriptName) == $fileName)
? $shortScriptName
: $shortScriptName.((empty($shortScriptName) || substr($shortScriptName,-1) == '/') ? '' : '/').$fileName;
$hashPos = strpos($queryString,'#');
$queryStringWithoutHash =
(empty($queryString) || ($hashPos === 0))
? ''
: (
($hashPos === false)
? "?$queryString"
: '?'.sustr($queryString,0,$hashPos+1)
);
$_SERVER['SCRIPT_FILENAME'] = $documentRootFull.$fileName;
$_SERVER['SCRIPT_NAME'] = $scriptName;
$_SERVER['PHP_SELF'] = $scriptName.$pathInfo;
$_SERVER['PATH_INFO'] = $pathInfo;
$_SERVER['ORIG_PATH_INFO'] = $pathInfo;
$_SERVER['PATH_TRANSLATED'] = $documentRootShort.$pathInfo;
if (substr($shortScriptName,-1) == '/'){
if (!empty($pathInfo) && substr($pathInfo,0,1) == '/'){
$_SERVER['DOCUMENT_URI'] = $shortScriptName.substr($pathInfo,1);
} else {
$_SERVER['DOCUMENT_URI'] = $shortScriptName.$pathInfo;
}
} else if (empty($pathInfo) || substr($pathInfo,0,1) == '/'){
$_SERVER['DOCUMENT_URI'] = $shortScriptName.$pathInfo;
} else {
$_SERVER['DOCUMENT_URI'] = $shortScriptName.'/'.$pathInfo;
}
$_SERVER['REQUEST_URI'] = $_SERVER['DOCUMENT_URI'].$queryStringWithoutHash;
$_SERVER['DOCUMENT_ROOT'] = $documentRootShort;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // forced
$_SERVER['REMOTE_PORT'] = '80'; // forced
$_SERVER['SERVER_ADDR'] = '127.0.0.1'; // forced
$_SERVER['SERVER_ADDR'] = '80'; // forced
$_SERVER['SERVER_NAME'] = 'localhost'; // forced
$_SERVER['HTTPS'] = null; // forced
}
}
/**
* save previous $_SERVER in $GLOBALS if existing
*/
public function saveSERVER()
{
if (!isset($GLOBALS['savedSERVER'])){
$GLOBALS['savedSERVER'] = [
'saved' => false,
'value' => null
];
}
if (!$GLOBALS['savedSERVER']['saved']){
if (!isset($_SERVER)){
$GLOBALS['savedSERVER']['value'] = null;
$GLOBALS['savedSERVER']['saved'] = true;
} else {
$GLOBALS['savedSERVER']['value'] = $_SERVER;
$GLOBALS['savedSERVER']['saved'] = true;
}
}
}
/**
* revert previous $_SERVER in $GLOBALS if existing
*/
public function revertSERVER()
{
if (isset($GLOBALS['savedSERVER']['saved']) && $GLOBALS['savedSERVER']['saved']){
if (is_null($GLOBALS['savedSERVER']['value'])){
unset($_SERVER);
} else {
$_SERVER = $GLOBALS['savedSERVER']['value'];
}
$GLOBALS['savedSERVER']['saved'] = false;
$GLOBALS['savedSERVER']['value'] = null;
}
}
}