This commit is contained in:
2019-09-27 00:29:18 +02:00
parent 40af43681e
commit b857814072
470 changed files with 37562 additions and 10060 deletions
+7
View File
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);
/**
*To help phpstan dealing with LogicException in Common\User\User.php
*/
define('GRAV_USER_INSTANCE', 'FLEX');
define('GRAV_REQUEST_TIME', microtime(true));
+107
View File
@@ -0,0 +1,107 @@
includes:
#- '../../vendor/phpstan/phpstan-strict-rules/rules.neon'
- '../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'
parameters:
fileExtensions:
- php
- dist
bootstrap: tests/phpstan/phpstan-bootstrap.php
excludes_analyse:
- system/src/Grav/Common/Errors/Resources/layout.html.php
reportUnmatchedIgnoredErrors: false
universalObjectCratesClasses:
- Grav\Common\Config\Config
- Grav\Common\Config\Languages
- Grav\Common\Config\Setup
- Grav\Common\Data\Data
- Grav\Common\GPM\Common\Package
- Grav\Common\GPM\Local\Package
- Grav\Common\GPM\Remote\Package
- Grav\Common\Session
ignoreErrors:
# FIXME: Bugs that need to be fixed
# TODO: Errors that needs some more thinking (bad design?)
- '#Access to an undefined property RocketTheme\\Toolbox\\Event\\Event::#'
- '#Access to an undefined property Grav\\Common\\Data\\Blueprint::#'
- '#Access to an undefined property Grav\\Common\\Media\\Interfaces\\MediaObjectInterface::#'
- '#Access to an undefined property Grav\\Common\\Page\\Interfaces\\PageInterface::#'
-
message: '#Cannot call method path\(\) on string#'
path: 'system/src/Grav/Common/Page/Media.php'
# TODO: system.twig.umask_fix will not work with Twig 2 anymore
-
message: '#Call to deprecated method writeCacheFile\(\) of class Twig\\Environment#'
path: 'system/src/Grav/Common/Twig/WriteCacheFileTrait.php'
# Needed: full coverage (probably with admin plugin...) then redesign constructor
-
message: '#Grav\\Common\\GPM\\Remote\\GravCore::__construct\(\) does not call parent constructor from Grav\\Common\\GPM\\Remote\\AbstractPackageCollection#'
path: 'system/src/Grav/Common/GPM/Remote/GravCore.php'
# PSR-16 Exception interfaces do not extend \Throwable
- '#PHPDoc tag \@throws with type Psr\\SimpleCache\\(CacheException|InvalidArgumentException) is not subtype of Throwable#'
- '#expects Exception, Psr\\SimpleCache\\InvalidArgumentException&Throwable given#'
# Needed: psr-17 (http-factories) support (through decorator or further investigations)
-
message: '#Call to an undefined static method Grav\\Framework\\Psr7\\Stream::create\(\)#'
path: 'system/src/Grav/Framework/Form/FormFlashFile.php'
# Medium __call() methods
- '#Call to an undefined method Grav\\Common\\Page\\Medium\\(\w*)Medium::#'
# Filesystem::getInstance()
-
message: '#Strict comparison using === between null and static#'
path: 'system/src/Grav/Framework/Filesystem/Filesystem.php'
# These errors are about plugins (need to find a better solution)
-
message: '#Call to static method sendEmail\(\) on an unknown class Grav\\Plugin\\Email\\Utils#'
path: 'system/src/Grav/Common/Scheduler/Job.php'
-
message: '#on an unknown class Grav\\Plugin\\Admin#'
path: 'system/src/Grav/Common/Page/Pages.php'
-
message: '#Call to method getFlash\(\) on an unknown class Grav\\Common\\Grav\\Plugin\\Form\\Forms#'
path: 'system/src/Grav/Common/Session.php'
# Can be ignored, after fopen there's always an $http_response_header locally available
-
message: '#Variable \$http_response_header in isset\(\) always exists and is not nullable#'
path: 'system/src/Grav/Common/GPM/Response.php'
# These errors can be ignored (they depend on installed extensions)
-
message: '#Instantiated class (Memcache|Memcached|Redis|RedisException) not found#'
path: 'system/src/Grav/Common/Cache.php'
-
message: '#on an unknown class (Memcache|Memcached|Redis|RedisException)#'
path: 'system/src/Grav/Common/Cache.php'
-
message: '#on an unknown class Collator#'
path: 'system/src/Grav/Common/Page/Pages.php'
# Support for deprecated features
-
message: '#Instantiation of deprecated class Doctrine\\Common\\Cache\\MemcacheCache#'
path: 'system/src/Grav/Common/Cache.php'
-
message: '#Call to deprecated method order#'
path: 'system/src/Grav/Common/Page/Pages.php'
-
message: '#Fetching class constant class of deprecated class Grav\\Common\\User\\User#'
path: 'system/src/Grav/Common/Service/AccountsServiceProvider.php'
-
message: '#Call to deprecated method getLegacyFiles\(\)#'
path: 'system/src/Grav/Common/Session.php'
-
message: '#Call to deprecated method getType\(\) of class#'
path: 'system/src/Grav/Framework/Object/Base/ObjectTrait.php'
-
message: '#deprecated class#'
path: 'system/src/Grav/Framework/Uri/Uri.php'
+41
View File
@@ -0,0 +1,41 @@
<?php
use Grav\Common\Grav;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
\define('GRAV_USER_INSTANCE', 'FLEX');
$autoload = require __DIR__ . '/../../vendor/autoload.php';
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
}
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
if (!file_exists(GRAV_ROOT . '/index.php')) {
exit('FATAL: Must be run from ROOT directory of Grav!');
}
$grav = Grav::instance(array('loader' => $autoload));
$grav->setup('tests');
$grav['config']->init();
// Find all plugins in Grav installation and autoload their classes.
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
$iterator = $locator->getIterator('plugins://');
foreach($iterator as $directory) {
if (!$directory->isDir()) {
continue;
}
$autoloader = $directory->getPathname() . '/vendor/autoload.php';
if (file_exists($autoloader)) {
require $autoloader;
}
}
+20
View File
@@ -0,0 +1,20 @@
includes:
#- '../../vendor/phpstan/phpstan-strict-rules/rules.neon'
- '../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'
parameters:
fileExtensions:
- php
excludes_analyse:
- %currentWorkingDirectory%/user/plugins/*/vendor/*
- %currentWorkingDirectory%/user/plugins/*/tests/*
bootstrap: tests/phpstan/plugins-bootstrap.php
reportUnmatchedIgnoredErrors: true
universalObjectCratesClasses:
- Grav\Common\Config\Config
- Grav\Common\Config\Languages
- Grav\Common\Config\Setup
- Grav\Common\Data\Data
- Grav\Common\GPM\Common\Package
- Grav\Common\GPM\Local\Package
- Grav\Common\GPM\Remote\Package
- Grav\Common\Session
+351 -171
View File
@@ -32,201 +32,298 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->add('test.css');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type":"css",
"elements":{
"asset":"\/test.css",
"asset_type":"css",
"order":0,
"group":"head",
"position":"pipeline",
"priority":10,
"attributes":{
"type":"text\/css",
"rel":"stylesheet"
},
"modified":false,
"query":""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
$this->assets->add('test.js');
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
$this->assertSame('<script src="/test.js"></script>' . PHP_EOL, $js);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
$array = $this->assets->getJs();
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type":"js",
"elements":{
"asset":"\/test.js",
"asset_type":"js",
"order":0,
"group":"head",
"position":"pipeline",
"priority":10,
"attributes":[
],
"modified":false,
"query":""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//test addCss(). Test adding asset to a separate group
$this->assets->reset();
$this->assets->addCSS('test.css');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type":"css",
"elements":{
"asset":"\/test.css",
"asset_type":"css",
"order":0,
"group":"head",
"position":"pipeline",
"priority":10,
"attributes":{
"type":"text\/css",
"rel":"stylesheet"
},
"modified":false,
"query":""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//test addCss(). Testing with remote URL
$this->assets->reset();
$this->assets->addCSS('http://www.somesite.com/test.css');
$css = $this->assets->css();
$this->assertSame('<link href="http://www.somesite.com/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="http://www.somesite.com/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => 'http://www.somesite.com/test.css',
'remote' => true,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type":"css",
"elements":{
"asset":"http:\/\/www.somesite.com\/test.css",
"asset_type":"css",
"order":0,
"group":"head",
"position":"pipeline",
"priority":10,
"attributes":{
"type":"text\/css",
"rel":"stylesheet"
},
"query":""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//test addCss() adding asset to a separate group, and with an alternate rel attribute
$this->assets->reset();
$this->assets->addCSS('test.css', ['group' => 'alternate']);
$css = $this->assets->css('alternate', ['rel' => 'alternate']);
$this->assertSame('<link href="/test.css" type="text/css" rel="alternate" />' . PHP_EOL, $css);
$this->assets->addCSS('test.css', ['group' => 'alternate', 'rel' => 'alternate']);
$css = $this->assets->css('alternate');
$this->assertSame('<link href="/test.css" type="text/css" rel="alternate">' . PHP_EOL, $css);
//test addJs()
$this->assets->reset();
$this->assets->addJs('test.js');
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
$this->assertSame('<script src="/test.js"></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type":"js",
"elements":{
"asset":"\/test.js",
"asset_type":"js",
"order":0,
"group":"head",
"position":"pipeline",
"priority":10,
"attributes":[],
"modified":false,
"query":""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//Test CSS Groups
$this->assets->reset();
$this->assets->addCSS('test.css', null, true, 'footer');
$this->assets->addCSS('test.css', ['group' => 'footer']);
$css = $this->assets->css();
$this->assertEmpty($css);
$css = $this->assets->css('footer');
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'footer',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type": "css",
"elements": {
"asset": "/test.css",
"asset_type": "css",
"order": 0,
"group": "footer",
"position": "pipeline",
"priority": 10,
"attributes": {
"type": "text/css",
"rel": "stylesheet"
},
"modified": false,
"query": ""
}
}
';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//Test JS Groups
$this->assets->reset();
$this->assets->addJs('test.js', null, true, null, 'footer');
$this->assets->addJs('test.js', ['group' => 'footer']);
$js = $this->assets->js();
$this->assertEmpty($js);
$js = $this->assets->js('footer');
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
$this->assertSame('<script src="/test.js"></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'footer',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type": "js",
"elements": {
"asset": "/test.js",
"asset_type": "js",
"order": 0,
"group": "footer",
"position": "pipeline",
"priority": 10,
"attributes": [],
"modified": false,
"query": ""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//Test async / defer
$this->assets->reset();
$this->assets->addJs('test.js', null, true, 'async', null);
$this->assets->addJs('test.js', ['loading' => 'async']);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" async></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => 'async',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type": "js",
"elements": {
"asset": "/test.js",
"asset_type": "js",
"order": 0,
"group": "head",
"position": "pipeline",
"priority": 10,
"attributes": {
"loading": "async"
},
"modified": false,
"query": ""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
$this->assets->reset();
$this->assets->addJs('test.js', null, true, 'defer', null);
$this->assets->addJs('test.js', ['loading' => 'defer']);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" defer></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => 'defer',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type": "js",
"elements": {
"asset": "/test.js",
"asset_type": "js",
"order": 0,
"group": "head",
"position": "pipeline",
"priority": 10,
"attributes": {
"loading": "defer"
},
"modified": false,
"query": ""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
//Test inline
$this->assets->reset();
$this->assets->addJs('/system/assets/jquery/jquery-2.x.min.js', null, true, 'inline', null);
$js = $this->assets->js();
$this->assertContains('jQuery Foundation', $js);
$this->assets->setJsPipeline(true);
$this->assets->addJs('/system/assets/jquery/jquery-3.x.min.js');
$js = $this->assets->js('head', ['loading' => 'inline']);
$this->assertContains('"jquery",[],function()', $js);
$this->assets->reset();
$this->assets->addCss('/system/assets/debugger.css', null, true, null, 'inline');
$css = $this->assets->css();
$this->assets->setCssPipeline(true);
$this->assets->addCss('/system/assets/debugger.css');
$css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertContains('div.phpdebugbar', $css);
$this->assets->reset();
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true, null, 'inline');
$css = $this->assets->css();
$this->assertContains('font-family: \'Roboto\';', $css);
$this->assets->setCssPipeline(true);
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto');
$css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertContains('font-family:\'Roboto\';', $css);
//Test adding media queries
$this->assets->reset();
$this->assets->add('test.css', ['media' => 'only screen and (min-width: 640px)']);
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 640px)" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 640px)">' . PHP_EOL, $css);
}
public function testAddingAssetPropertiesWithArray()
@@ -275,6 +372,81 @@ class AssetsTest extends \Codeception\TestCase\Test
'<script src="/test.js" async></script>' . PHP_EOL, $js);
}
public function testAddingLegacyFormat()
{
// regular CSS add
//test addCss(). Test adding asset to a separate group
$this->assets->reset();
$this->assets->addCSS('test.css', 15, true, 'bottom', 'async');
$css = $this->assets->css('bottom');
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" async>' . PHP_EOL, $css);
$array = $this->assets->getCss();
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type":"css",
"elements":{
"asset":"\/test.css",
"asset_type":"css",
"order":0,
"group":"bottom",
"position":"pipeline",
"priority":15,
"attributes":{
"type":"text\/css",
"rel":"stylesheet",
"loading":"async"
},
"modified":false,
"query":""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
$this->assets->reset();
$this->assets->addJs('test.js', 15, false, 'defer', 'bottom');
$js = $this->assets->js('bottom');
$this->assertSame('<script src="/test.js" defer></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
/** @var Assets\BaseAsset $item */
$item = reset($array);
$actual = json_encode($item);
$expected = '
{
"type": "js",
"elements": {
"asset": "/test.js",
"asset_type": "js",
"order": 0,
"group": "bottom",
"position": "after",
"priority": 15,
"attributes": {
"loading": "defer"
},
"modified": false,
"query": ""
}
}';
$this->assertJsonStringEqualsJsonString($expected, $actual);
$this->assets->reset();
$this->assets->addInlineCss('body { color: black }', 15, 'bottom');
$css = $this->assets->css('bottom');
$this->assertSame('<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . '</style>' . PHP_EOL, $css);
$this->assets->reset();
$this->assets->addInlineJs('alert("test")', 15, 'bottom', ['id' => 'foo']);
$js = $this->assets->js('bottom');
$this->assertSame('<script id="foo">' . PHP_EOL . 'alert("test")' . PHP_EOL . '</script>' . PHP_EOL, $js);
}
public function testAddingCSSAssetPropertiesWithArrayFromCollection()
{
$this->assets->registerCollection('test', ['/system/assets/whoops.css']);
@@ -284,25 +456,25 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->addCss('test', ['priority' => 1]);
$this->assets->addCss('test.css', ['priority' => 2]);
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
'<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
'<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
//Test multiple groups
$this->assets->reset();
$this->assets->addCss('test', ['priority' => 1, 'group' => 'footer']);
$this->assets->addCss('test.css', ['priority' => 2]);
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
$css = $this->assets->css('footer');
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
//Test adding array of assets
//Test priority too
$this->assets->reset();
$this->assets->addCss(['test', 'test.css'], ['loading' => 'async']);
$css = $this->assets->css();
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
'<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" async>' . PHP_EOL .
'<link href="/test.css" type="text/css" rel="stylesheet" async>' . PHP_EOL, $css);
}
public function testPriorityOfAssets()
@@ -312,8 +484,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->add('test-after.css');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
'<link href="/test-after.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
'<link href="/test-after.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
//----------------
$this->assets->reset();
@@ -321,8 +493,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->add('test.css', 2);
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
'<link href="/test-after.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
'<link href="/test-after.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
//----------------
$this->assets->reset();
@@ -331,9 +503,9 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->add('test-before.css', 3);
$css = $this->assets->css();
$this->assertSame('<link href="/test-before.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
'<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
'<link href="/test-after.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test-before.css" type="text/css" rel="stylesheet">' . PHP_EOL .
'<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
'<link href="/test-after.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
}
public function testPipeline()
@@ -344,37 +516,53 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->add('test.css', null, true);
$this->assets->setCssPipeline(true);
$css = $this->assets->css();
$this->assertSame('', $css);
$this->assertRegExp('#<link href=\"\/assets\/(.*).css\" type=\"text\/css\" rel=\"stylesheet\">#', $css);
//Add a core Grav CSS file, which is found. Pipeline will now return a file
$this->assets->add('/system/assets/debugger.css', null, true);
$css = $this->assets->css();
$this->assertContains('<link href=', $css);
$this->assertContains('type="text/css" rel="stylesheet" />', $css);
$this->assertRegExp('#<link href=\"\/assets\/(.*).css\" type=\"text\/css\" rel=\"stylesheet\">#', $css);
}
public function testPipelineWithTimestamp()
{
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->setCssPipeline(true);
//Add a core Grav CSS file, which is found. Pipeline will now return a file
$this->assets->add('/system/assets/debugger.css', null, true);
$css = $this->assets->css();
$this->assertContains('<link href=', $css);
$this->assertContains('type="text/css" rel="stylesheet" />', $css);
$this->assertContains($this->assets->getTimestamp(), $css);
$this->assertRegExp('#<link href=\"\/assets\/(.*).css\?foo\" type=\"text\/css\" rel=\"stylesheet\">#', $css);
}
public function testInline()
{
$this->assets->reset();
//File not existing. Pipeline searches for that file without reaching it. Output is empty.
$this->assets->add('test.css', ['loading' => 'inline']);
$css = $this->assets->css();
$this->assertSame("<style>\n\n</style>\n", $css);
$this->assets->reset();
//Add a core Grav CSS file, which is found. Pipeline will now return its content.
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', ['loading' => 'inline']);
$this->assets->addCss('/system/assets/debugger.css', ['loading' => 'inline']);
$css = $this->assets->css();
$this->assertContains('font-family: \'Roboto\';', $css);
$this->assertContains('div.phpdebugbar-header', $css);
}
public function testInlinePipeline()
{
$this->assets->reset();
$this->assets->setCssPipeline(true);
//File not existing. Pipeline searches for that file without reaching it. Output is empty.
$this->assets->add('test.css', null, true);
$this->assets->setCssPipeline(true);
$this->assets->add('test.css');
$css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertSame('', $css);
$this->assertSame("<style>\n\n</style>\n", $css);
//Add a core Grav CSS file, which is found. Pipeline will now return its content.
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true);
@@ -407,56 +595,56 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->setTimestamp('foo');
$this->assets->addCSS('test.css');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css?foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css?foo" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
// local CSS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('test.css?bar');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css?bar&foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="/test.css?bar&foo" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
// external CSS already
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('http://somesite.com/test.css');
$css = $this->assets->css();
$this->assertSame('<link href="http://somesite.com/test.css?foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="http://somesite.com/test.css?foo" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
// external CSS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('http://somesite.com/test.css?bar');
$css = $this->assets->css();
$this->assertSame('<link href="http://somesite.com/test.css?bar&foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$this->assertSame('<link href="http://somesite.com/test.css?bar&foo" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
// local JS nothing extra
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('test.js');
$css = $this->assets->js();
$this->assertSame('<script src="/test.js?foo" ></script>' . PHP_EOL, $css);
$this->assertSame('<script src="/test.js?foo"></script>' . PHP_EOL, $css);
// local JS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('test.js?bar');
$css = $this->assets->js();
$this->assertSame('<script src="/test.js?bar&foo" ></script>' . PHP_EOL, $css);
$this->assertSame('<script src="/test.js?bar&foo"></script>' . PHP_EOL, $css);
// external JS already
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('http://somesite.com/test.js');
$css = $this->assets->js();
$this->assertSame('<script src="http://somesite.com/test.js?foo" ></script>' . PHP_EOL, $css);
$this->assertSame('<script src="http://somesite.com/test.js?foo"></script>' . PHP_EOL, $css);
// external JS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('http://somesite.com/test.js?bar');
$css = $this->assets->js();
$this->assertSame('<script src="http://somesite.com/test.js?bar&foo" ></script>' . PHP_EOL, $css);
$this->assertSame('<script src="http://somesite.com/test.js?bar&foo"></script>' . PHP_EOL, $css);
}
public function testAddInlineCss()
@@ -464,7 +652,7 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->reset();
$this->assets->addInlineCss('body { color: black }');
$css = $this->assets->css();
$this->assertSame(PHP_EOL . '<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . PHP_EOL . '</style>' . PHP_EOL, $css);
$this->assertSame('<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . '</style>' . PHP_EOL, $css);
}
public function testAddInlineJs()
@@ -472,7 +660,7 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->reset();
$this->assets->addInlineJs('alert("test")');
$js = $this->assets->js();
$this->assertSame(PHP_EOL . '<script>' . PHP_EOL . 'alert("test")' . PHP_EOL . PHP_EOL . '</script>' . PHP_EOL, $js);
$this->assertSame('<script>' . PHP_EOL . 'alert("test")' . PHP_EOL . '</script>' . PHP_EOL, $js);
}
public function testGetCollections()
@@ -499,49 +687,41 @@ class AssetsTest extends \Codeception\TestCase\Test
{
$this->assets->addInlineJs('alert("test")');
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->js());
$this->assertCount(0, (array) $this->assets->getJs());
$this->assets->addAsyncJs('jquery');
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->js());
$this->assertCount(0, (array) $this->assets->getJs());
$this->assets->addInlineCss('body { color: black }');
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->css());
$this->assertCount(0, (array) $this->assets->getCss());
$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->css());
$this->assertCount(0, (array) $this->assets->getCss());
}
public function testResetJs()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->resetJs();
$this->assertCount(0, (array) $this->assets->js());
$this->assertCount(0, (array) $this->assets->getJs());
$this->assets->addAsyncJs('jquery');
$this->assets->resetJs();
$this->assertCount(0, (array) $this->assets->js());
$this->assertCount(0, (array) $this->assets->getJs());
}
public function testResetCss()
{
$this->assertCount(0, (array) $this->assets->js());
$this->assets->addInlineCss('body { color: black }');
$this->assets->resetCss();
$this->assertCount(0, (array) $this->assets->css());
$this->assertCount(0, (array) $this->assets->getCss());
$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->resetCss();
$this->assertCount(0, (array) $this->assets->css());
$this->assertCount(0, (array) $this->assets->getCss());
}
public function testAddDirCss()
@@ -19,7 +19,7 @@ class ExcerptsTest extends \Codeception\TestCase\Test
/** @var Grav $grav */
protected $grav;
/** @var Page $page */
/** @var PageInterface $page */
protected $page;
/** @var Pages $pages */
+1 -1
View File
@@ -13,7 +13,7 @@ class InflectorTest extends \Codeception\TestCase\Test
/** @var Grav $grav */
protected $grav;
/** @var Uri $uri */
/** @var Inflector $uri */
protected $inflector;
protected function _before()
@@ -2,6 +2,7 @@
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Page\Markdown\Excerpts;
use Grav\Common\Uri;
use Grav\Common\Config\Config;
use Grav\Common\Page\Pages;
@@ -56,14 +57,19 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->pages->init();
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
'markdown' => [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
],
'images' => $this->config->get('system.images', [])
];
$page = $this->pages->dispatch('/item2/item2-2');
$this->parsedown = new Parsedown($page, $defaults);
$excerpts = new Excerpts($page, $defaults);
$this->parsedown = new Parsedown($excerpts);
}
protected function _after()
@@ -179,14 +185,18 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->uri->initializeWithURL('http://testing.dev/')->init();
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
'markdown' => [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
],
'images' => $this->config->get('system.images', [])
];
$page = $this->pages->dispatch('/');
$this->parsedown = new Parsedown($page, $defaults);
$excerpts = new Excerpts($page, $defaults);
$this->parsedown = new Parsedown($excerpts);
$this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
$this->parsedown->text('![](home-sample-image.jpg)'));
@@ -230,15 +240,18 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->uri->initializeWithURL('http://testing.dev/')->init();
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
'markdown' => [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
],
'images' => $this->config->get('system.images', [])
];
$page = $this->pages->dispatch('/');
$this->parsedown = new Parsedown($page, $defaults);
$excerpts = new Excerpts($page, $defaults);
$this->parsedown = new Parsedown($excerpts);
$this->assertSame('<p><a href="/item1/item1-3">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item1-3)'));
+1 -1
View File
@@ -18,7 +18,7 @@ class PagesTest extends \Codeception\TestCase\Test
/** @var Pages $pages */
protected $pages;
/** @var Page $root_page */
/** @var PageInterface $root_page */
protected $root_page;
protected function _before()
+36 -18
View File
@@ -302,7 +302,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'https://api.getgrav.com:4040',
'extension' => null,
'addNonce' => 'https://username:password@api.getgrav.com:4040/v1/post/128/page:x/nonce:{{nonce}}?all=1',
'__toString' => 'https://username:password@api.getgrav.com:4040/v1/post/128/page:x?all=1'
'toOriginalString' => 'https://username:password@api.getgrav.com:4040/v1/post/128/page:x?all=1'
],
'https://google.com:443/' => [
'scheme' => 'https://',
@@ -392,7 +392,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => null,
'addNonce' => 'http://localhost/this%20is%20the%20path/my%20page/nonce:{{nonce}}',
'__toString' => 'http://localhost/this%20is%20the%20path/my%20page'
'toOriginalString' => 'http://localhost/this%20is%20the%20path/my%20page'
],
'http://localhost/pölöpölö/päläpälä' => [
'scheme' => 'http://',
@@ -415,7 +415,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => null,
'addNonce' => 'http://localhost/p%C3%B6l%C3%B6p%C3%B6l%C3%B6/p%C3%A4l%C3%A4p%C3%A4l%C3%A4/nonce:{{nonce}}',
'__toString' => 'http://localhost/p%C3%B6l%C3%B6p%C3%B6l%C3%B6/p%C3%A4l%C3%A4p%C3%A4l%C3%A4'
'toOriginalString' => 'http://localhost/p%C3%B6l%C3%B6p%C3%B6l%C3%B6/p%C3%A4l%C3%A4p%C3%A4l%C3%A4'
],
// Query params tests.
'http://localhost:8080/grav/it/ueper?test=x&test2=y' => [
@@ -573,7 +573,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => 'html',
'addNonce' => 'http://localhost/a-page.html/nonce:{{nonce}}',
'__toString' => 'http://localhost/a-page', // FIXME <-
'toOriginalString' => 'http://localhost/a-page.html',
],
'http://localhost/a-page.json' => [
'scheme' => 'http://',
@@ -596,7 +596,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => 'json',
'addNonce' => 'http://localhost/a-page.json/nonce:{{nonce}}',
'__toString' => 'http://localhost/a-page', // FIX ME <-
'toOriginalString' => 'http://localhost/a-page.json',
],
'http://localhost/admin/ajax.json/task:getnewsfeed' => [
'scheme' => 'http://',
@@ -619,7 +619,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => 'json',
'addNonce' => 'http://localhost/admin/ajax.json/task:getnewsfeed/nonce:{{nonce}}',
'__toString' => 'http://localhost/admin/ajax/task:getnewsfeed',
'toOriginalString' => 'http://localhost/admin/ajax.json/task:getnewsfeed',
],
'http://localhost/grav/admin/media.json/route:L1VzZXJzL3JodWsvd29ya3NwYWNlL2dyYXYtZGVtby1zYW1wbGVyL3VzZXIvYXNzZXRzL3FRMXB4Vk1ERTNJZzh5Ni5qcGc=/task:removeFileFromBlueprint/proute:/blueprint:Y29uZmlnL2RldGFpbHM=/type:config/field:deep.nested.custom_file/path:dXNlci9hc3NldHMvcVExcHhWTURFM0lnOHk2LmpwZw==' => [
'scheme' => 'http://',
@@ -642,7 +642,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => 'json',
'addNonce' => 'http://localhost/grav/admin/media.json/route:L1VzZXJzL3JodWsvd29ya3NwYWNlL2dyYXYtZGVtby1zYW1wbGVyL3VzZXIvYXNzZXRzL3FRMXB4Vk1ERTNJZzh5Ni5qcGc=/task:removeFileFromBlueprint/proute:/blueprint:Y29uZmlnL2RldGFpbHM=/type:config/field:deep.nested.custom_file/path:dXNlci9hc3NldHMvcVExcHhWTURFM0lnOHk2LmpwZw==/nonce:{{nonce}}',
'__toString' => 'http://localhost/grav/admin/media/route:L1VzZXJzL3JodWsvd29ya3NwYWNlL2dyYXYtZGVtby1zYW1wbGVyL3VzZXIvYXNzZXRzL3FRMXB4Vk1ERTNJZzh5Ni5qcGc=/task:removeFileFromBlueprint/proute:/blueprint:Y29uZmlnL2RldGFpbHM=/type:config/field:deep.nested.custom_file/path:dXNlci9hc3NldHMvcVExcHhWTURFM0lnOHk2LmpwZw==', // FIXME <-
'toOriginalString' => 'http://localhost/grav/admin/media.json/route:L1VzZXJzL3JodWsvd29ya3NwYWNlL2dyYXYtZGVtby1zYW1wbGVyL3VzZXIvYXNzZXRzL3FRMXB4Vk1ERTNJZzh5Ni5qcGc=/task:removeFileFromBlueprint/proute:/blueprint:Y29uZmlnL2RldGFpbHM=/type:config/field:deep.nested.custom_file/path:dXNlci9hc3NldHMvcVExcHhWTURFM0lnOHk2LmpwZw==',
],
'http://localhost/a-page.foo' => [
'scheme' => 'http://',
@@ -665,7 +665,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => 'foo',
'addNonce' => 'http://localhost/a-page.foo/nonce:{{nonce}}',
'__toString' => 'http://localhost/a-page.foo'
'toOriginalString' => 'http://localhost/a-page.foo'
],
// Fragment tests.
'http://localhost:8080/a/b/c#my-fragment' => [
@@ -712,7 +712,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => '',
'extension' => null,
//'addNonce' => '%22%3E%3Cscript%3Ealert%3C/localhost/script%3E:/nonce:{{nonce}}', // FIXME <-
'__toString' => '%22%3E%3Cscript%3Ealert%3C/localhost/script%3E:' // FIXME <-
'toOriginalString' => '%22%3E%3Cscript%3Ealert%3C/localhost/script%3E:' // FIXME <-
],
'http://"><script>alert</script>' => [
'scheme' => 'http://',
@@ -735,7 +735,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://unknown',
'extension' => null,
'addNonce' => 'http://unknown/script%3E/nonce:{{nonce}}',
'__toString' => 'http://unknown/script%3E'
'toOriginalString' => 'http://unknown/script%3E'
],
'http://localhost/"><script>alert</script>' => [
'scheme' => 'http://',
@@ -758,7 +758,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => null,
'addNonce' => 'http://localhost/%22%3E%3Cscript%3Ealert%3C/script%3E/nonce:{{nonce}}',
'__toString' => 'http://localhost/%22%3E%3Cscript%3Ealert%3C/script%3E'
'toOriginalString' => 'http://localhost/%22%3E%3Cscript%3Ealert%3C/script%3E'
],
'http://localhost/something/p1:foo/p2:"><script>alert</script>' => [
'scheme' => 'http://',
@@ -781,7 +781,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => null,
//'addNonce' => 'http://localhost/something/script%3E/p1:foo/p2:%22%3E%3Cscript%3Ealert%3C/nonce:{{nonce}}', // FIXME <-
'__toString' => 'http://localhost/something/script%3E/p1:foo/p2:%22%3E%3Cscript%3Ealert%3C'
'toOriginalString' => 'http://localhost/something/script%3E/p1:foo/p2:%22%3E%3Cscript%3Ealert%3C'
],
'http://localhost/something?p="><script>alert</script>' => [
'scheme' => 'http://',
@@ -804,7 +804,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => null,
'addNonce' => 'http://localhost/something/nonce:{{nonce}}?p=%22%3E%3Cscript%3Ealert%3C/script%3E',
'__toString' => 'http://localhost/something?p=%22%3E%3Cscript%3Ealert%3C/script%3E'
'toOriginalString' => 'http://localhost/something?p=%22%3E%3Cscript%3Ealert%3C/script%3E'
],
'http://localhost/something#"><script>alert</script>' => [
'scheme' => 'http://',
@@ -827,7 +827,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'http://localhost',
'extension' => null,
'addNonce' => 'http://localhost/something/nonce:{{nonce}}#%22%3E%3Cscript%3Ealert%3C/script%3E',
'__toString' => 'http://localhost/something#%22%3E%3Cscript%3Ealert%3C/script%3E'
'toOriginalString' => 'http://localhost/something#%22%3E%3Cscript%3Ealert%3C/script%3E'
],
'https://www.getgrav.org/something/"><script>eval(atob("aGlzdG9yeS5wdXNoU3RhdGUoJycsJycsJy8nKTskKCdoZWFkLGJvZHknKS5odG1sKCcnKS5sb2FkKCcvJyk7JC5wb3N0KCcvYWRtaW4nLGZ1bmN0aW9uKGRhdGEpeyQucG9zdCgkKGRhdGEpLmZpbmQoJ1tpZD1hZG1pbi11c2VyLWRldGFpbHNdIGEnKS5hdHRyKCdocmVmJykseydhZG1pbi1ub25jZSc6JChkYXRhKS5maW5kKCdbZGF0YS1jbGVhci1jYWNoZV0nKS5hdHRyKCdkYXRhLWNsZWFyLWNhY2hlJykuc3BsaXQoJzonKS5wb3AoKS50cmltKCksJ2RhdGFbcGFzc3dvcmRdJzonSW0zdjFsaDR4eDByJywndGFzayc6J3NhdmUnfSl9KQ=="))</script><' => [
'scheme' => 'https://',
@@ -850,7 +850,7 @@ class UriTest extends \Codeception\TestCase\Test
'rootUrl' => 'https://www.getgrav.org',
'extension' => null,
'addNonce' => 'https://www.getgrav.org/something/%22%3E%3Cscript%3Eeval%28atob%28%22aGlzdG9yeS5wdXNoU3RhdGUoJycsJycsJy8nKTskKCdoZWFkLGJvZHknKS5odG1sKCcnKS5sb2FkKCcvJyk7JC5wb3N0KCcvYWRtaW4nLGZ1bmN0aW9uKGRhdGEpeyQucG9zdCgkKGRhdGEpLmZpbmQoJ1tpZD1hZG1pbi11c2VyLWRldGFpbHNdIGEnKS5hdHRyKCdocmVmJykseydhZG1pbi1ub25jZSc6JChkYXRhKS5maW5kKCdbZGF0YS1jbGVhci1jYWNoZV0nKS5hdHRyKCdkYXRhLWNsZWFyLWNhY2hlJykuc3BsaXQoJzonKS5wb3AoKS50cmltKCksJ2RhdGFbcGFzc3dvcmRdJzonSW0zdjFsaDR4eDByJywndGFzayc6J3NhdmUnfSl9KQ==%22%29%29%3C/script%3E%3C/nonce:{{nonce}}',
'__toString' => 'https://www.getgrav.org/something/%22%3E%3Cscript%3Eeval%28atob%28%22aGlzdG9yeS5wdXNoU3RhdGUoJycsJycsJy8nKTskKCdoZWFkLGJvZHknKS5odG1sKCcnKS5sb2FkKCcvJyk7JC5wb3N0KCcvYWRtaW4nLGZ1bmN0aW9uKGRhdGEpeyQucG9zdCgkKGRhdGEpLmZpbmQoJ1tpZD1hZG1pbi11c2VyLWRldGFpbHNdIGEnKS5hdHRyKCdocmVmJykseydhZG1pbi1ub25jZSc6JChkYXRhKS5maW5kKCdbZGF0YS1jbGVhci1jYWNoZV0nKS5hdHRyKCdkYXRhLWNsZWFyLWNhY2hlJykuc3BsaXQoJzonKS5wb3AoKS50cmltKCksJ2RhdGFbcGFzc3dvcmRdJzonSW0zdjFsaDR4eDByJywndGFzayc6J3NhdmUnfSl9KQ==%22%29%29%3C/script%3E%3C'
'toOriginalString' => 'https://www.getgrav.org/something/%22%3E%3Cscript%3Eeval%28atob%28%22aGlzdG9yeS5wdXNoU3RhdGUoJycsJycsJy8nKTskKCdoZWFkLGJvZHknKS5odG1sKCcnKS5sb2FkKCcvJyk7JC5wb3N0KCcvYWRtaW4nLGZ1bmN0aW9uKGRhdGEpeyQucG9zdCgkKGRhdGEpLmZpbmQoJ1tpZD1hZG1pbi11c2VyLWRldGFpbHNdIGEnKS5hdHRyKCdocmVmJykseydhZG1pbi1ub25jZSc6JChkYXRhKS5maW5kKCdbZGF0YS1jbGVhci1jYWNoZV0nKS5hdHRyKCdkYXRhLWNsZWFyLWNhY2hlJykuc3BsaXQoJzonKS5wb3AoKS50cmltKCksJ2RhdGFbcGFzc3dvcmRdJzonSW0zdjFsaDR4eDByJywndGFzayc6J3NhdmUnfSl9KQ==%22%29%29%3C/script%3E%3C'
],
];
@@ -868,7 +868,7 @@ class UriTest extends \Codeception\TestCase\Test
protected function runTestSet(array $tests, $method, $params = [])
{
foreach ($tests as $url => $candidates) {
if (!array_key_exists($method, $candidates) && $method !== '__toString') {
if (!array_key_exists($method, $candidates) && $method !== 'toOriginalString') {
continue;
}
if ($method === 'addNonce') {
@@ -881,7 +881,7 @@ class UriTest extends \Codeception\TestCase\Test
}
$this->uri->initializeWithURL($url)->init();
if ($method === '__toString' && !isset($candidates[$method])) {
if ($method === 'toOriginalString' && !isset($candidates[$method])) {
$expected = $url;
} else {
$expected = $candidates[$method];
@@ -921,7 +921,7 @@ class UriTest extends \Codeception\TestCase\Test
public function testToString()
{
$this->runTestSet($this->tests, '__toString');
$this->runTestSet($this->tests, 'toOriginalString');
}
public function testScheme()
@@ -1121,6 +1121,24 @@ class UriTest extends \Codeception\TestCase\Test
];
$this->assertSame('http://foo:bar@localhost:8080/test?x=2#xxx', Uri::buildUrl($parsed_url));
/** @var Uri $uri */
$uri = Grav::instance()['uri'];
$uri->initializeWithUrlAndRootPath('https://testing.dev/subdir/path1/path2/file.html', '/subdir')->init();
$this->assertSame('https://testing.dev/subdir/path1/path2/file.html', Uri::buildUrl($uri->toArray(true)));
$uri->initializeWithUrlAndRootPath('https://testing.dev/subdir/path1/path2/file.foo', '/subdir')->init();
$this->assertSame('https://testing.dev/subdir/path1/path2/file.foo', Uri::buildUrl($uri->toArray(true)));
$uri->initializeWithUrlAndRootPath('https://testing.dev/subdir/path1/path2/file.html', '/subdir/path1')->init();
$this->assertSame('https://testing.dev/subdir/path1/path2/file.html', Uri::buildUrl($uri->toArray(true)));
$uri->initializeWithUrlAndRootPath('https://testing.dev/subdir/path1/path2/file.html/foo:blah/bang:boom', '/subdir')->init();
$this->assertSame('https://testing.dev/subdir/path1/path2/file.html/foo:blah/bang:boom', Uri::buildUrl($uri->toArray(true)));
$uri->initializeWithUrlAndRootPath('https://testing.dev/subdir/path1/path2/file.html/foo:blah/bang:boom?fig=something', '/subdir')->init();
$this->assertSame('https://testing.dev/subdir/path1/path2/file.html/foo:blah/bang:boom?fig=something', Uri::buildUrl($uri->toArray(true)));
}
public function testConvertUrl()
+194 -1
View File
@@ -2,6 +2,7 @@
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
/**
@@ -12,10 +13,14 @@ class UtilsTest extends \Codeception\TestCase\Test
/** @var Grav $grav */
protected $grav;
/** @var Uri $uri */
protected $uri;
protected function _before()
{
$grav = Fixtures::get('grav');
$this->grav = $grav();
$this->uri = $this->grav['uri'];
}
protected function _after()
@@ -35,6 +40,13 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertFalse(Utils::startsWith('ENGLISH', 'en'));
$this->assertFalse(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'e'));
$this->assertTrue(Utils::startsWith('english', 'En', false));
$this->assertTrue(Utils::startsWith('English', 'EN', false));
$this->assertTrue(Utils::startsWith('ENGLISH', 'en', false));
$this->assertTrue(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'e', false));
}
public function testEndsWith()
@@ -50,6 +62,12 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertFalse(Utils::endsWith('ENGLISH', 'Sh'));
$this->assertFalse(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
$this->assertTrue(Utils::endsWith('english', 'SH', false));
$this->assertTrue(Utils::endsWith('EngliSh', 'sH', false));
$this->assertTrue(Utils::endsWith('ENGLISH', 'sh', false));
$this->assertTrue(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'english', false));
}
public function testContains()
@@ -65,6 +83,12 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertFalse(Utils::contains('ENGLISH', 'SCH'));
$this->assertFalse(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
$this->assertTrue(Utils::contains('EngliSh', 'GLI', false));
$this->assertTrue(Utils::contains('EngliSh', 'ENGLISH', false));
$this->assertTrue(Utils::contains('ENGLISH', 'ish', false));
$this->assertTrue(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'english', false));
}
public function testSubstrToString()
@@ -72,6 +96,10 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertEquals('en', Utils::substrToString('english', 'glish'));
$this->assertEquals('english', Utils::substrToString('english', 'test'));
$this->assertNotEquals('en', Utils::substrToString('english', 'lish'));
$this->assertEquals('en', Utils::substrToString('english', 'GLISH', false));
$this->assertEquals('english', Utils::substrToString('english', 'TEST', false));
$this->assertNotEquals('en', Utils::substrToString('english', 'LISH', false));
}
public function testMergeObjects()
@@ -123,6 +151,8 @@ class UtilsTest extends \Codeception\TestCase\Test
public function testTruncateHtml()
{
$this->assertEquals('T...', Utils::truncateHtml('This is a string to truncate', 1));
$this->assertEquals('This is...', Utils::truncateHtml('This is a string to truncate', 7));
$this->assertEquals('<p>T...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 1));
$this->assertEquals('<p>This...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 4));
$this->assertEquals('<p>This is a...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 10));
@@ -134,6 +164,8 @@ class UtilsTest extends \Codeception\TestCase\Test
public function testSafeTruncateHtml()
{
$this->assertEquals('This...', Utils::safeTruncateHtml('This is a string to truncate', 1));
$this->assertEquals('This is a...', Utils::safeTruncateHtml('This is a string to truncate', 3));
$this->assertEquals('<p>This...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 1));
$this->assertEquals('<p>This is...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 2));
$this->assertEquals('<p>This is a string to...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 5));
@@ -192,7 +224,19 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertEquals('test', Utils::normalizePath('../test'));
$this->assertEquals('/test', Utils::normalizePath('/../test'));
$this->assertEquals('/test2', Utils::normalizePath('/test/../test2'));
$this->assertEquals('/test/test2', Utils::normalizePath('/test/./test2'));
$this->assertEquals('/test3', Utils::normalizePath('/test/../test2/../test3'));
$this->assertEquals('//cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css', Utils::normalizePath('//cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css'));
$this->assertEquals('//use.fontawesome.com/releases/v5.8.1/css/all.css', Utils::normalizePath('//use.fontawesome.com/releases/v5.8.1/css/all.css'));
$this->assertEquals('//use.fontawesome.com/releases/v5.8.1/webfonts/fa-brands-400.eot', Utils::normalizePath('//use.fontawesome.com/releases/v5.8.1/css/../webfonts/fa-brands-400.eot'));
$this->assertEquals('http://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css', Utils::normalizePath('http://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css'));
$this->assertEquals('http://use.fontawesome.com/releases/v5.8.1/css/all.css', Utils::normalizePath('http://use.fontawesome.com/releases/v5.8.1/css/all.css'));
$this->assertEquals('http://use.fontawesome.com/releases/v5.8.1/webfonts/fa-brands-400.eot', Utils::normalizePath('http://use.fontawesome.com/releases/v5.8.1/css/../webfonts/fa-brands-400.eot'));
$this->assertEquals('https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css', Utils::normalizePath('https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css'));
$this->assertEquals('https://use.fontawesome.com/releases/v5.8.1/css/all.css', Utils::normalizePath('https://use.fontawesome.com/releases/v5.8.1/css/all.css'));
$this->assertEquals('https://use.fontawesome.com/releases/v5.8.1/webfonts/fa-brands-400.eot', Utils::normalizePath('https://use.fontawesome.com/releases/v5.8.1/css/../webfonts/fa-brands-400.eot'));
}
public function testIsFunctionDisabled()
@@ -330,4 +374,153 @@ class UtilsTest extends \Codeception\TestCase\Test
{
$this->assertTrue(Utils::verifyNonce(Utils::getNonce('test-action'), 'test-action'));
}
public function testUrl()
{
$this->uri->initializeWithUrl('http://testing.dev/path1/path2')->init();
// Fail hard
$this->assertSame(false, Utils::url('', true));
$this->assertSame(false, Utils::url(''));
$this->assertSame(false, Utils::url(new stdClass()));
$this->assertSame(false, Utils::url(['foo','bar','baz']));
$this->assertSame(false, Utils::url('user://does/not/exist'));
// Fail Gracefully
$this->assertSame('/', Utils::url('/', false, true));
$this->assertSame('/', Utils::url('', false, true));
$this->assertSame('/', Utils::url(new stdClass(), false, true));
$this->assertSame('/', Utils::url(['foo','bar','baz'], false, true));
$this->assertSame('/user/does/not/exist', Utils::url('user://does/not/exist', false, true));
// Simple paths
$this->assertSame('/', Utils::url('/'));
$this->assertSame('/path1', Utils::url('/path1'));
$this->assertSame('/path1/path2', Utils::url('/path1/path2'));
$this->assertSame('/random/path1/path2', Utils::url('/random/path1/path2'));
$this->assertSame('/foobar.jpg', Utils::url('/foobar.jpg'));
$this->assertSame('/path1/foobar.jpg', Utils::url('/path1/foobar.jpg'));
$this->assertSame('/path1/path2/foobar.jpg', Utils::url('/path1/path2/foobar.jpg'));
$this->assertSame('/random/path1/path2/foobar.jpg', Utils::url('/random/path1/path2/foobar.jpg'));
// Simple paths with domain
$this->assertSame('http://testing.dev/', Utils::url('/', true));
$this->assertSame('http://testing.dev/path1', Utils::url('/path1', true));
$this->assertSame('http://testing.dev/path1/path2', Utils::url('/path1/path2', true));
$this->assertSame('http://testing.dev/random/path1/path2', Utils::url('/random/path1/path2', true));
$this->assertSame('http://testing.dev/foobar.jpg', Utils::url('/foobar.jpg', true));
$this->assertSame('http://testing.dev/path1/foobar.jpg', Utils::url('/path1/foobar.jpg', true));
$this->assertSame('http://testing.dev/path1/path2/foobar.jpg', Utils::url('/path1/path2/foobar.jpg', true));
$this->assertSame('http://testing.dev/random/path1/path2/foobar.jpg', Utils::url('/random/path1/path2/foobar.jpg', true));
// Relative paths from Grav root.
$this->assertSame('/subdir', Utils::url('subdir'));
$this->assertSame('/subdir/path1', Utils::url('subdir/path1'));
$this->assertSame('/subdir/path1/path2', Utils::url('subdir/path1/path2'));
$this->assertSame('/path1', Utils::url('path1'));
$this->assertSame('/path1/path2', Utils::url('path1/path2'));
$this->assertSame('/foobar.jpg', Utils::url('foobar.jpg'));
$this->assertSame('http://testing.dev/foobar.jpg', Utils::url('foobar.jpg', true));
// Relative paths from Grav root with domain.
$this->assertSame('http://testing.dev/foobar.jpg', Utils::url('foobar.jpg', true));
$this->assertSame('http://testing.dev/foobar.jpg', Utils::url('/foobar.jpg', true));
$this->assertSame('http://testing.dev/path1/foobar.jpg', Utils::url('/path1/foobar.jpg', true));
// All Non-existing streams should be treated as external URI / protocol.
$this->assertSame('http://domain.com/path', Utils::url('http://domain.com/path'));
$this->assertSame('ftp://domain.com/path', Utils::url('ftp://domain.com/path'));
$this->assertSame('sftp://domain.com/path', Utils::url('sftp://domain.com/path'));
$this->assertSame('ssh://domain.com', Utils::url('ssh://domain.com'));
$this->assertSame('pop://domain.com', Utils::url('pop://domain.com'));
$this->assertSame('foo://bar/baz', Utils::url('foo://bar/baz'));
$this->assertSame('foo://bar/baz', Utils::url('foo://bar/baz', true));
// $this->assertSame('mailto:joe@domain.com', Utils::url('mailto:joe@domain.com', true)); // FIXME <-
}
public function testUrlWithRoot()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/path1/path2', '/subdir')->init();
// Fail hard
$this->assertSame(false, Utils::url('', true));
$this->assertSame(false, Utils::url(''));
$this->assertSame(false, Utils::url(new stdClass()));
$this->assertSame(false, Utils::url(['foo','bar','baz']));
$this->assertSame(false, Utils::url('user://does/not/exist'));
// Fail Gracefully
$this->assertSame('/subdir/', Utils::url('/', false, true));
$this->assertSame('/subdir/', Utils::url('', false, true));
$this->assertSame('/subdir/', Utils::url(new stdClass(), false, true));
$this->assertSame('/subdir/', Utils::url(['foo','bar','baz'], false, true));
$this->assertSame('/subdir/user/does/not/exist', Utils::url('user://does/not/exist', false, true));
// Simple paths
$this->assertSame('/subdir/', Utils::url('/'));
$this->assertSame('/subdir/path1', Utils::url('/path1'));
$this->assertSame('/subdir/path1/path2', Utils::url('/path1/path2'));
$this->assertSame('/subdir/random/path1/path2', Utils::url('/random/path1/path2'));
$this->assertSame('/subdir/foobar.jpg', Utils::url('/foobar.jpg'));
$this->assertSame('/subdir/path1/foobar.jpg', Utils::url('/path1/foobar.jpg'));
$this->assertSame('/subdir/path1/path2/foobar.jpg', Utils::url('/path1/path2/foobar.jpg'));
$this->assertSame('/subdir/random/path1/path2/foobar.jpg', Utils::url('/random/path1/path2/foobar.jpg'));
// Simple paths with domain
$this->assertSame('http://testing.dev/subdir/', Utils::url('/', true));
$this->assertSame('http://testing.dev/subdir/path1', Utils::url('/path1', true));
$this->assertSame('http://testing.dev/subdir/path1/path2', Utils::url('/path1/path2', true));
$this->assertSame('http://testing.dev/subdir/random/path1/path2', Utils::url('/random/path1/path2', true));
$this->assertSame('http://testing.dev/subdir/foobar.jpg', Utils::url('/foobar.jpg', true));
$this->assertSame('http://testing.dev/subdir/path1/foobar.jpg', Utils::url('/path1/foobar.jpg', true));
$this->assertSame('http://testing.dev/subdir/path1/path2/foobar.jpg', Utils::url('/path1/path2/foobar.jpg', true));
$this->assertSame('http://testing.dev/subdir/random/path1/path2/foobar.jpg', Utils::url('/random/path1/path2/foobar.jpg', true));
// Paths including the grav base.
$this->assertSame('/subdir/', Utils::url('/subdir'));
$this->assertSame('/subdir/path1', Utils::url('/subdir/path1'));
$this->assertSame('/subdir/path1/path2', Utils::url('/subdir/path1/path2'));
$this->assertSame('/subdir/foobar.jpg', Utils::url('/subdir/foobar.jpg'));
$this->assertSame('/subdir/path1/foobar.jpg', Utils::url('/subdir/path1/foobar.jpg'));
// Relative paths from Grav root with domain.
$this->assertSame('http://testing.dev/subdir/', Utils::url('/subdir', true));
$this->assertSame('http://testing.dev/subdir/path1', Utils::url('/subdir/path1', true));
$this->assertSame('http://testing.dev/subdir/path1/path2', Utils::url('/subdir/path1/path2', true));
$this->assertSame('http://testing.dev/subdir/foobar.jpg', Utils::url('/subdir/foobar.jpg', true));
$this->assertSame('http://testing.dev/subdir/path1/foobar.jpg', Utils::url('/subdir/path1/foobar.jpg', true));
// Relative paths from Grav root.
$this->assertSame('/subdir/subdir', Utils::url('subdir'));
$this->assertSame('/subdir/subdir/path1', Utils::url('subdir/path1'));
$this->assertSame('/subdir/subdir/path1/path2', Utils::url('subdir/path1/path2'));
$this->assertSame('/subdir/path1', Utils::url('path1'));
$this->assertSame('/subdir/path1/path2', Utils::url('path1/path2'));
$this->assertSame('/subdir/foobar.jpg', Utils::url('foobar.jpg'));
$this->assertSame('http://testing.dev/subdir/foobar.jpg', Utils::url('foobar.jpg', true));
// All Non-existing streams should be treated as external URI / protocol.
$this->assertSame('http://domain.com/path', Utils::url('http://domain.com/path'));
$this->assertSame('ftp://domain.com/path', Utils::url('ftp://domain.com/path'));
$this->assertSame('sftp://domain.com/path', Utils::url('sftp://domain.com/path'));
$this->assertSame('ssh://domain.com', Utils::url('ssh://domain.com'));
$this->assertSame('pop://domain.com', Utils::url('pop://domain.com'));
$this->assertSame('foo://bar/baz', Utils::url('foo://bar/baz'));
$this->assertSame('foo://bar/baz', Utils::url('foo://bar/baz', true));
// $this->assertSame('mailto:joe@domain.com', Utils::url('mailto:joe@domain.com', true)); // FIXME <-
}
public function testUrlWithStreams()
{
}
public function testUrlwithExternals()
{
$this->uri->initializeWithUrl('http://testing.dev/path1/path2')->init();
$this->assertSame('http://foo.com', Utils::url('http://foo.com'));
$this->assertSame('https://foo.com', Utils::url('https://foo.com'));
$this->assertSame('//foo.com', Utils::url('//foo.com'));
$this->assertSame('//foo.com?param=x', Utils::url('//foo.com?param=x'));
}
}
@@ -0,0 +1,47 @@
<?php
use Grav\Framework\File\Formatter\CsvFormatter;
class CsvFormatterTest extends \Codeception\TestCase\Test
{
public function testEncodeWithAssocColumns()
{
$data = [
['col1' => 1, 'col2' => 2, 'col3' => 3],
['col1' => 'aaa', 'col2' => 'bbb', 'col3' => 'ccc'],
];
$encoded = (new CsvFormatter())->encode($data);
$lines = array_filter(explode(PHP_EOL, $encoded));
self::assertCount(3, $lines);
self::assertEquals('col1,col2,col3', $lines[0]);
}
/**
* TBD - If indexes are all numeric, what's the purpose
* of displaying header
*/
public function testEncodeWithIndexColumns()
{
$data = [
[0 => 1, 1 => 2, 2 => 3],
];
$encoded = (new CsvFormatter())->encode($data);
$lines = array_filter(explode(PHP_EOL, $encoded));
self::assertCount(2, $lines);
self::assertEquals('0,1,2', $lines[0]);
}
public function testEncodeEmptyData()
{
$encoded = (new CsvFormatter())->encode([]);
self::assertEquals('', $encoded);
}
}
@@ -0,0 +1,322 @@
<?php
use Grav\Framework\Filesystem\Filesystem;
class FilesystemTest extends \Codeception\TestCase\Test
{
protected $class;
protected $tests = [
'' => [
'parent' => '',
'normalize' => '',
'dirname' => '',
'pathinfo' => [
'basename' => '',
'filename' => '',
]
],
'.' => [
'parent' => '',
'normalize' => '',
'dirname' => '.',
'pathinfo' => [
'dirname' => '.',
'basename' => '.',
'extension' => '',
'filename' => '',
]
],
'./' => [
'parent' => '',
'normalize' => '',
'dirname' => '.',
'pathinfo' => [
'dirname' => '.',
'basename' => '.',
'extension' => '',
'filename' => '',
]
],
'././.' => [
'parent' => '',
'normalize' => '',
'dirname' => './.',
'pathinfo' => [
'dirname' => './.',
'basename' => '.',
'extension' => '',
'filename' => '',
]
],
'.file' => [
'parent' => '.',
'normalize' => '.file',
'dirname' => '.',
'pathinfo' => [
'dirname' => '.',
'basename' => '.file',
'extension' => 'file',
'filename' => '',
]
],
'/' => [
'parent' => '',
'normalize' => '/',
'dirname' => '/',
'pathinfo' => [
'dirname' => '/',
'basename' => '',
'filename' => '',
]
],
'/absolute' => [
'parent' => '/',
'normalize' => '/absolute',
'dirname' => '/',
'pathinfo' => [
'dirname' => '/',
'basename' => 'absolute',
'filename' => 'absolute',
]
],
'/absolute/' => [
'parent' => '/',
'normalize' => '/absolute',
'dirname' => '/',
'pathinfo' => [
'dirname' => '/',
'basename' => 'absolute',
'filename' => 'absolute',
]
],
'/very/long/absolute/path' => [
'parent' => '/very/long/absolute',
'normalize' => '/very/long/absolute/path',
'dirname' => '/very/long/absolute',
'pathinfo' => [
'dirname' => '/very/long/absolute',
'basename' => 'path',
'filename' => 'path',
]
],
'relative' => [
'parent' => '.',
'normalize' => 'relative',
'dirname' => '.',
'pathinfo' => [
'dirname' => '.',
'basename' => 'relative',
'filename' => 'relative',
]
],
'very/long/relative/path' => [
'parent' => 'very/long/relative',
'normalize' => 'very/long/relative/path',
'dirname' => 'very/long/relative',
'pathinfo' => [
'dirname' => 'very/long/relative',
'basename' => 'path',
'filename' => 'path',
]
],
'path/to/file.jpg' => [
'parent' => 'path/to',
'normalize' => 'path/to/file.jpg',
'dirname' => 'path/to',
'pathinfo' => [
'dirname' => 'path/to',
'basename' => 'file.jpg',
'extension' => 'jpg',
'filename' => 'file',
]
],
'user://' => [
'parent' => '',
'normalize' => 'user://',
'dirname' => 'user://',
'pathinfo' => [
'dirname' => 'user://',
'basename' => '',
'filename' => '',
'scheme' => 'user',
]
],
'user://.' => [
'parent' => '',
'normalize' => 'user://',
'dirname' => 'user://',
'pathinfo' => [
'dirname' => 'user://',
'basename' => '',
'filename' => '',
'scheme' => 'user',
]
],
'user://././.' => [
'parent' => '',
'normalize' => 'user://',
'dirname' => 'user://',
'pathinfo' => [
'dirname' => 'user://',
'basename' => '',
'filename' => '',
'scheme' => 'user',
]
],
'user://./././file' => [
'parent' => 'user://',
'normalize' => 'user://file',
'dirname' => 'user://',
'pathinfo' => [
'dirname' => 'user://',
'basename' => 'file',
'filename' => 'file',
'scheme' => 'user',
]
],
'user://./././folder/file' => [
'parent' => 'user://folder',
'normalize' => 'user://folder/file',
'dirname' => 'user://folder',
'pathinfo' => [
'dirname' => 'user://folder',
'basename' => 'file',
'filename' => 'file',
'scheme' => 'user',
]
],
'user://.file' => [
'parent' => 'user://',
'normalize' => 'user://.file',
'dirname' => 'user://',
'pathinfo' => [
'dirname' => 'user://',
'basename' => '.file',
'extension' => 'file',
'filename' => '',
'scheme' => 'user',
]
],
'user:///' => [
'parent' => '',
'normalize' => 'user:///',
'dirname' => 'user:///',
'pathinfo' => [
'dirname' => 'user:///',
'basename' => '',
'filename' => '',
'scheme' => 'user',
]
],
'user:///absolute' => [
'parent' => 'user:///',
'normalize' => 'user:///absolute',
'dirname' => 'user:///',
'pathinfo' => [
'dirname' => 'user:///',
'basename' => 'absolute',
'filename' => 'absolute',
'scheme' => 'user',
]
],
'user:///very/long/absolute/path' => [
'parent' => 'user:///very/long/absolute',
'normalize' => 'user:///very/long/absolute/path',
'dirname' => 'user:///very/long/absolute',
'pathinfo' => [
'dirname' => 'user:///very/long/absolute',
'basename' => 'path',
'filename' => 'path',
'scheme' => 'user',
]
],
'user://relative' => [
'parent' => 'user://',
'normalize' => 'user://relative',
'dirname' => 'user://',
'pathinfo' => [
'dirname' => 'user://',
'basename' => 'relative',
'filename' => 'relative',
'scheme' => 'user',
]
],
'user://very/long/relative/path' => [
'parent' => 'user://very/long/relative',
'normalize' => 'user://very/long/relative/path',
'dirname' => 'user://very/long/relative',
'pathinfo' => [
'dirname' => 'user://very/long/relative',
'basename' => 'path',
'filename' => 'path',
'scheme' => 'user',
]
],
'user://path/to/file.jpg' => [
'parent' => 'user://path/to',
'normalize' => 'user://path/to/file.jpg',
'dirname' => 'user://path/to',
'pathinfo' => [
'dirname' => 'user://path/to',
'basename' => 'file.jpg',
'extension' => 'jpg',
'filename' => 'file',
'scheme' => 'user',
]
],
];
protected function _before()
{
$this->class = Filesystem::getInstance();
}
protected function _after()
{
unset($this->class);
}
protected function runTestSet(array $tests, $method)
{
$class = $this->class;
foreach ($tests as $path => $candidates) {
if (!array_key_exists($method, $candidates)) {
continue;
}
$expected = $candidates[$method];
$result = $class->{$method}($path);
$this->assertSame($expected, $result, "Test {$method}('{$path}')");
if (function_exists($method) && !strpos($path, '://')) {
$cmp_result = $method($path);
$this->assertSame($cmp_result, $result, "Compare to original {$method}('{$path}')");
}
}
}
public function testParent()
{
$this->runTestSet($this->tests, 'parent');
}
public function testNormalize()
{
$this->runTestSet($this->tests, 'normalize');
}
public function testDirname()
{
$this->runTestSet($this->tests, 'dirname');
}
public function testPathinfo()
{
$this->runTestSet($this->tests, 'pathinfo');
}
}