restored dashboard from usable

This commit is contained in:
Bachir Soussi Chiadmi
2018-10-25 16:18:42 +02:00
commit abc70f9e12
454 changed files with 46195 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
// This is global bootstrap for autoloading
namespace Grav;
use Codeception\Util\Fixtures;
use Faker\Factory;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
ini_set('error_log', __DIR__ . '/error.log');
// Ensure vendor libraries exist
$autoload = __DIR__ . '/../vendor/autoload.php';
if (!is_file($autoload)) {
throw new \RuntimeException("Please run: <i>bin/grav install</i>");
}
use Grav\Common\Grav;
// Register the auto-loader.
$loader = require_once $autoload;
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
throw new \RuntimeException(sprintf('You are running PHP %s, but Grav needs at least <strong>PHP %s</strong> to run.', $ver, $req));
}
// Set timezone to default, falls back to system if php.ini not set
date_default_timezone_set(@date_default_timezone_get());
// Set internal encoding if mbstring loaded
if (!extension_loaded('mbstring')) {
throw new \RuntimeException("'mbstring' extension is not loaded. This is required for Grav to run correctly");
}
mb_internal_encoding('UTF-8');
// Get the Grav instance
$grav = Grav::instance(['loader' => $loader]);
$grav['uri']->init();
$grav['debugger']->init();
$grav['assets']->init();
$grav['config']->set('system.cache.enabled', false);
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$locator->addPath('tests', '', 'tests', false);
// Set default $_SERVER value used for nonces
empty( $_SERVER['HTTP_CLIENT_IP'] ) && $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1';
$fake = Factory::create();
Fixtures::add('grav', $grav);
Fixtures::add('fake', $fake);
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace Helper;
use Codeception;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
/**
* Class Unit
* @package Helper
*/
class Unit extends Codeception\Module
{
/**
* HOOK: used after configuration is loaded
*/
public function _initialize() {
}
/**
* HOOK: on every Actor class initialization
*/
public function _cleanup() {
}
/**
* HOOK: before suite
*
* @param array $settings
*/
public function _beforeSuite($settings = []) {
}
/**
* HOOK: after suite
**/
public function _afterSuite() {
}
/**
* HOOK: before each step
*
* @param Codeception\Step $step*
*/
public function _beforeStep(Codeception\Step $step) {
}
/**
* HOOK: after each step
*
* @param Codeception\Step $step
*/
public function _afterStep(Codeception\Step $step) {
}
/**
* HOOK: before each suite
*
* @param Codeception\TestCase $test
*/
public function _before(Codeception\TestCase $test) {
}
/**
* HOOK: before each suite
*
* @param Codeception\TestCase $test
*/
public function _after(Codeception\TestCase $test) {
}
/**
* HOOK: on fail
*
* @param Codeception\TestCase $test
* @param $fail
*/
public function _failed(Codeception\TestCase $test, $fail) {
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
+12
View File
@@ -0,0 +1,12 @@
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost:8080/grav
- \Helper\Acceptance
+2
View File
@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests
@@ -0,0 +1,10 @@
---
title: Item 1-1-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-1-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-1-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-2-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-2-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-2-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-3-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-3-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-3-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

@@ -0,0 +1,10 @@
---
title: Item 2-1-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-1-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-1-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-2-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-2-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-2-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

@@ -0,0 +1,10 @@
---
title: Item 2-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

@@ -0,0 +1,10 @@
---
title: Item 2-3-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-3-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-3-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,14 @@
---
title: Animal
taxonomy:
tag: [animal, cat]
---
<h1>Tags: animal</h1
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-1-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-1-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-2-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-2-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-2-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-3-1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-3-2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3-3-3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Item 3
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Home
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Blog
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Post 1
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: Post 2
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,10 @@
---
title: About
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,5 @@
---
title: Simple Page
---
Simple Page Content
+11
View File
@@ -0,0 +1,11 @@
# Codeception Test Suite Configuration
#
# Suite for functional (integration) tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- \Helper\Functional
+2
View File
@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests
+9
View File
@@ -0,0 +1,9 @@
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
+432
View File
@@ -0,0 +1,432 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Assets;
/**
* Class AssetsTest
*/
class AssetsTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var Assets $assets */
protected $assets;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->assets = $this->grav['assets'];
}
protected function _after()
{
}
public function testAddingAssets()
{
//test add()
$this->assets->add('test.css');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'group' => 'head'
], reset($array));
$this->assets->add('test.js');
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" ></script>' . PHP_EOL, $js);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'group' => 'head'
], reset($array));
//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);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'group' => 'head'
], reset($array));
//test addJs()
$this->assets->reset();
$this->assets->addJs('test.js');
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" ></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head'
], reset($array));
//Test CSS Groups
$this->assets->reset();
$this->assets->addCSS('test.css', null, true, '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);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'group' => 'footer'
], reset($array));
//Test JS Groups
$this->assets->reset();
$this->assets->addJs('test.js', null, true, null, 'footer');
$js = $this->assets->js();
$this->assertEmpty($js);
$js = $this->assets->js('footer');
$this->assertSame('<script src="/test.js" type="text/javascript" ></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'footer'
], reset($array));
//Test async / defer
$this->assets->reset();
$this->assets->addJs('test.js', null, true, 'async', null);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => 'async',
'group' => 'head'
], reset($array));
$this->assets->reset();
$this->assets->addJs('test.js', null, true, 'defer', null);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" defer></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => 'defer',
'group' => 'head'
], reset($array));
}
public function testAddingAssetPropertiesWithArray()
{
//Test adding assets with object to define properties
$this->assets->reset();
$this->assets->addJs('test.js', ['loading' => 'async']);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js);
$this->assets->reset();
}
public function testAddingJSAssetPropertiesWithArrayFromCollection()
{
//Test adding properties with array
$this->assets->reset();
$this->assets->addJs('jquery', ['loading' => 'async']);
$js = $this->assets->js();
$this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js);
//Test priority too
$this->assets->reset();
$this->assets->addJs('jquery', ['loading' => 'async', 'priority' => 1]);
$this->assets->addJs('test.js', ['loading' => 'async', 'priority' => 2]);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL .
'<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js);
//Test multiple groups
$this->assets->reset();
$this->assets->addJs('jquery', ['loading' => 'async', 'priority' => 1, 'group' => 'footer']);
$this->assets->addJs('test.js', ['loading' => 'async', 'priority' => 2]);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js);
$js = $this->assets->js('footer');
$this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js);
//Test adding array of assets
//Test priority too
$this->assets->reset();
$this->assets->addJs(['jquery', 'test.js'], ['loading' => 'async']);
$js = $this->assets->js();
$this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL .
'<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js);
}
public function testAddingCSSAssetPropertiesWithArrayFromCollection()
{
$this->assets->registerCollection('test', ['/system/assets/whoops.css']);
//Test priority too
$this->assets->reset();
$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);
//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);
$css = $this->assets->css('footer');
$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);
}
public function testPriorityOfAssets()
{
$this->assets->reset();
$this->assets->add('test.css');
$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->assets->reset();
$this->assets->add('test-after.css', 1);
$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->assets->reset();
$this->assets->add('test-after.css', 1);
$this->assets->add('test.css', 2);
$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);
}
public function testPipeline()
{
$this->assets->reset();
//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);
$css = $this->assets->css();
$this->assertSame('', $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);
}
public function testAddAsyncJs()
{
$this->assets->reset();
$this->assets->addAsyncJs('jquery');
$js = $this->assets->js();
$this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js);
}
public function testAddDeferJs()
{
$this->assets->reset();
$this->assets->addDeferJs('jquery');
$js = $this->assets->js();
$this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" defer></script>' . PHP_EOL, $js);
}
public function testAddInlineCss()
{
$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);
}
public function testAddInlineJs()
{
$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);
}
public function testGetCollections()
{
$this->assertTrue(is_array($this->assets->getCollections()));
$this->assertTrue(in_array('jquery', array_keys($this->assets->getCollections())));
$this->assertTrue(in_array('system://assets/jquery/jquery-2.x.min.js', $this->assets->getCollections()));
}
public function testExists()
{
$this->assertTrue($this->assets->exists('jquery'));
$this->assertFalse($this->assets->exists('another-unexisting-library'));
}
public function testRegisterCollection()
{
$this->assets->registerCollection('debugger', ['/system/assets/debugger.css']);
$this->assertTrue($this->assets->exists('debugger'));
$this->assertTrue(in_array('debugger', array_keys($this->assets->getCollections())));
}
public function testReset()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->reset();
$this->assertTrue(count($this->assets->js()) == 0);
$this->assets->addAsyncJs('jquery');
$this->assets->reset();
$this->assertTrue(count($this->assets->js()) == 0);
$this->assets->addInlineCss('body { color: black }');
$this->assets->reset();
$this->assertTrue(count($this->assets->css()) == 0);
$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->reset();
$this->assertTrue(count($this->assets->css()) == 0);
}
public function testResetJs()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->resetJs();
$this->assertTrue(count($this->assets->js()) == 0);
$this->assets->addAsyncJs('jquery');
$this->assets->resetJs();
$this->assertTrue(count($this->assets->js()) == 0);
}
public function testResetCss()
{
$this->assertTrue(count($this->assets->js()) == 0);
$this->assets->addInlineCss('body { color: black }');
$this->assets->resetCss();
$this->assertTrue(count($this->assets->css()) == 0);
$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->resetCss();
$this->assertTrue(count($this->assets->css()) == 0);
}
public function testAddDirCss()
{
$this->assets->addDirCss('/system');
$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) == 0);
$this->assets->reset();
$this->assets->addDirCss('/system/assets');
$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) == 0);
$this->assets->reset();
$this->assets->addDirJs('/system');
$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) == 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
$this->assets->reset();
$this->assets->addDirJs('/system/assets');
$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) == 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
$this->assets->reset();
$this->assets->addDir('/system/assets');
$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
//Use streams
$this->assets->reset();
$this->assets->addDir('system://assets');
$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
/**
* Class BrowserTest
*/
class BrowserTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
protected function _before()
{
$this->grav = Fixtures::get('grav');
}
protected function _after()
{
}
public function testGetBrowser()
{ /* Already covered by PhpUserAgent tests */
}
public function testGetPlatform()
{ /* Already covered by PhpUserAgent tests */
}
public function testGetLongVersion()
{ /* Already covered by PhpUserAgent tests */
}
public function testGetVersion()
{ /* Already covered by PhpUserAgent tests */
}
public function testIsHuman()
{
//Already Partially covered by PhpUserAgent tests
//Make sure it recognizes the test as not human
$this->assertFalse($this->grav['browser']->isHuman());
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Composer;
class ComposerTest extends \Codeception\TestCase\Test
{
protected function _before()
{
}
protected function _after()
{
}
public function testGetComposerLocation()
{
$composerLocation = Composer::getComposerLocation();
$this->assertTrue(is_string($composerLocation));
$this->assertTrue($composerLocation[0] == '/');
}
public function testGetComposerExecutor()
{
$composerExecutor = Composer::getComposerExecutor();
$this->assertTrue(is_string($composerExecutor));
$this->assertTrue($composerExecutor[0] == '/');
$this->assertTrue(strstr($composerExecutor, 'php') !== null);
$this->assertTrue(strstr($composerExecutor, 'composer') !== null);
}
}
@@ -0,0 +1,715 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Config\Config;
use Grav\Common\Page\Pages;
use Grav\Common\Markdown\Parsedown;
use Grav\Common\Language\Language;
/**
* Class ParsedownTest
*/
class ParsedownTest extends \Codeception\TestCase\Test
{
/** @var Parsedown $parsedown */
protected $parsedown;
/** @var Grav $grav */
protected $grav;
/** @var Pages $pages */
protected $pages;
/** @var Config $config */
protected $config;
/** @var Uri $uri */
protected $uri;
/** @var Language $language */
protected $language;
protected $old_home;
static $run = false;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->pages = $this->grav['pages'];
$this->config = $this->grav['config'];
$this->uri = $this->grav['uri'];
$this->language = $this->grav['language'];
$this->old_home = $this->config->get('system.home.alias');
$this->config->set('system.home.alias', '/item1');
$this->config->set('system.absolute_urls', false);
$this->config->set('system.languages.supported', []);
unset($this->grav['language']);
$this->grav['language'] = new Language($this->grav);
if (!self::$run) {
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
$this->pages->init();
self::$run = true;
}
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
];
$page = $this->pages->dispatch('/item2/item2-2');
$this->parsedown = new Parsedown($page, $defaults);
}
protected function _after()
{
$this->config->set('system.home.alias', $this->old_home);
}
public function testImages()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><img src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg)'));
$this->assertRegexp('|<p><img src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](/home-cache-image.jpg?cache)'));
$this->assertSame('<p><img src="/item2/item2-2/missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](missing-image.jpg)'));
$this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
$this->config->set('system.languages.supported', ['fr','en']);
unset($this->grav['language']);
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><img src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg)'));
$this->assertRegexp('|<p><img src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
}
public function testImagesSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertRegexp('|<p><img src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](/home-cache-image.jpg?cache)'));
$this->assertSame('<p><img src="/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg)'));
$this->assertRegexp('|<p><img src="\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertSame('<p><img src="/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](missing-image.jpg)'));
$this->assertSame('<p><img src="/subdir/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
}
public function testImagesAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><img src="http://testing.dev/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg)'));
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](/home-cache-image.jpg?cache)'));
$this->assertSame('<p><img src="http://testing.dev/item2/item2-2/missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](missing-image.jpg)'));
$this->assertSame('<p><img src="http://testing.dev/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
}
public function testImagesSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><img src="http://testing.dev/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg)'));
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)'));
$this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](missing-image.jpg)'));
$this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
}
public function testRootImages()
{
$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'],
];
$page = $this->pages->dispatch('/');
$this->parsedown = new Parsedown($page, $defaults);
$this->assertSame('<p><img src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
$this->parsedown->text('![](home-sample-image.jpg)'));
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](home-cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g\?foo=1" \/><\/p>|',
$this->parsedown->text('![](home-cache-image.jpg?cropResize=200,200&foo)'));
$this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
$this->config->set('system.languages.supported', ['fr','en']);
unset($this->grav['language']);
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><img src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
$this->parsedown->text('![](home-sample-image.jpg)'));
}
public function testRootImagesSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><img src="http://testing.dev/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg)'));
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)'));
$this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](missing-image.jpg)'));
$this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
}
public function testRootAbsoluteLinks()
{
$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'],
];
$page = $this->pages->dispatch('/');
$this->parsedown = new Parsedown($page, $defaults);
$this->assertSame('<p><a href="/item1/item1-3">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item1-3)'));
$this->assertSame('<p><a href="/item2">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../item2)'));
$this->assertSame('<p><a href="/?foo=bar">With Query</a></p>',
$this->parsedown->text('[With Query](?foo=bar)'));
$this->assertSame('<p><a href="/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/foo:bar)'));
$this->assertSame('<p><a href="/#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](#foo)'));
$this->config->set('system.languages.supported', ['fr','en']);
unset($this->grav['language']);
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><a href="/fr/item2">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../item2)'));
$this->assertSame('<p><a href="/fr/item1/item1-3">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item1-3)'));
$this->assertSame('<p><a href="/fr/?foo=bar">With Query</a></p>',
$this->parsedown->text('[With Query](?foo=bar)'));
$this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/foo:bar)'));
$this->assertSame('<p><a href="/fr/#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](#foo)'));
}
public function testAnchorLinksLangRelativeUrls()
{
$this->config->set('system.languages.supported', ['fr','en']);
unset($this->grav['language']);
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><a href="/fr/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="/fr/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
$this->assertSame('<p><a href="/fr/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
}
public function testAnchorLinksLangAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->config->set('system.languages.supported', ['fr','en']);
unset($this->grav['language']);
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testExternalLinks()
{
$this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
$this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
$this->parsedown->text('[google.com](https://www.google.com)'));
}
public function testExternalLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
$this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
$this->parsedown->text('[google.com](https://www.google.com)'));
}
public function testExternalLinksSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
$this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
$this->parsedown->text('[google.com](https://www.google.com)'));
}
public function testAnchorLinksRelativeUrls()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
$this->assertSame('<p><a href="/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
}
public function testAnchorLinksAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksWithPortAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev:8080/item2/item2-2')->init();
$this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev:8080/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksSubDirRelativeUrls()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="/subdir/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testSlugRelativeLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/">Up to Root Level</a></p>',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('<p><a href="/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('<p><a href="/item3/item3-3">Up and Down</a></p>',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('<p><a href="/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('<p><a href="/item2?foo=bar">Up a Level with Query</a></p>',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('<p><a href="/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('<p><a href="/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('<p><a href="/item3/item3-3#foo">Up and Down with Anchor</a></p>',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testSlugRelativeLinksAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="http://testing.dev/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('<p><a href="http://testing.dev/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('<p><a href="http://testing.dev/">Up to Root Level</a></p>',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('<p><a href="http://testing.dev/item3/item3-3">Up and Down</a></p>',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/item2?foo=bar">Up a Level with Query</a></p>',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('<p><a href="http://testing.dev/item3/item3-3#foo">Up and Down with Anchor</a></p>',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testSlugRelativeLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="/subdir/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('<p><a href="/subdir/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('<p><a href="/subdir">Up to Root Level</a></p>',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('<p><a href="/subdir/item3/item3-3">Up and Down</a></p>',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('<p><a href="/subdir/item2?foo=bar">Up a Level with Query</a></p>',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('<p><a href="/subdir/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('<p><a href="/subdir/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('<p><a href="/subdir/item3/item3-3#foo">Up and Down with Anchor</a></p>',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testSlugRelativeLinksSubDirAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../item2-1)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](item2-2-1)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](..)'));
$this->assertSame('<p><a href="http://testing.dev/subdir">Up to Root Level</a></p>',
$this->parsedown->text('[Up to Root Level](../..)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3">Up and Down</a></p>',
$this->parsedown->text('[Up and Down](../../item3/item3-3)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
$this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2?foo=bar">Up a Level with Query</a></p>',
$this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
$this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
$this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3#foo">Up and Down with Anchor</a></p>',
$this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
}
public function testDirectoryRelativeLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
$this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)'));
$this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](../01.item2-1)'));
$this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](01.item2-2-1)'));
$this->assertSame('<p><a href="/item3/item3-3">Up and Down</a></p>',
$this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)'));
$this->assertSame('<p><a href="/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
$this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)'));
$this->assertSame('<p><a href="/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
$this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)'));
$this->assertSame('<p><a href="/item3/item3-3#foo">Up and Down with Anchor</a></p>',
$this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)'));
}
public function testAbsoluteLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/">Root</a></p>',
$this->parsedown->text('[Root](/)'));
$this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](/item2/item2-1)'));
$this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
$this->assertSame('<p><a href="/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](/item2)'));
$this->assertSame('<p><a href="/item2?foo=bar">With Query</a></p>',
$this->parsedown->text('[With Query](/item2?foo=bar)'));
$this->assertSame('<p><a href="/item2/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/item2/foo:bar)'));
$this->assertSame('<p><a href="/item2#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](/item2#foo)'));
}
public function testDirectoryAbsoluteLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="/subdir/">Root</a></p>',
$this->parsedown->text('[Root](/)'));
$this->assertSame('<p><a href="/subdir/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](/item2/item2-1)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
$this->assertSame('<p><a href="/subdir/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](/item2)'));
$this->assertSame('<p><a href="/subdir/item2?foo=bar">With Query</a></p>',
$this->parsedown->text('[With Query](/item2?foo=bar)'));
$this->assertSame('<p><a href="/subdir/item2/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/item2/foo:bar)'));
$this->assertSame('<p><a href="/subdir/item2#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](/item2#foo)'));
}
public function testDirectoryAbsoluteLinksSubDirAbsoluteUrl()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="http://testing.dev/subdir/">Root</a></p>',
$this->parsedown->text('[Root](/)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1">Peer Page</a></p>',
$this->parsedown->text('[Peer Page](/item2/item2-1)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
$this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2">Up a Level</a></p>',
$this->parsedown->text('[Up a Level](/item2)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2?foo=bar">With Query</a></p>',
$this->parsedown->text('[With Query](/item2?foo=bar)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/item2/foo:bar)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](/item2#foo)'));
}
public function testSpecialProtocols()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
$this->parsedown->text('[mailto](mailto:user@domain.com)'));
$this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
$this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
$this->parsedown->text('[sms](sms:123-555-12345)'));
}
public function testSpecialProtocolsSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
$this->parsedown->text('[mailto](mailto:user@domain.com)'));
$this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
$this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
$this->parsedown->text('[sms](sms:123-555-12345)'));
}
public function testSpecialProtocolsSubDirAbsoluteUrl()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
$this->parsedown->text('[mailto](mailto:user@domain.com)'));
$this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
$this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
$this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
$this->parsedown->text('[sms](sms:123-555-12345)'));
}
public function testReferenceLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$sample = '[relative link][r_relative]
[r_relative]: ../item2-3#blah';
$this->assertSame('<p><a href="/item2/item2-3#blah">relative link</a></p>',
$this->parsedown->text($sample));
$sample = '[absolute link][r_absolute]
[r_absolute]: /item3#blah';
$this->assertSame('<p><a href="/item3#blah">absolute link</a></p>',
$this->parsedown->text($sample));
$sample = '[external link][r_external]
[r_external]: http://www.cnn.com';
$this->assertSame('<p><a href="http://www.cnn.com">external link</a></p>',
$this->parsedown->text($sample));
}
public function testAttributeLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/item2/item2-3" class="button">Relative Class</a></p>',
$this->parsedown->text('[Relative Class](../item2-3?classes=button)'));
$this->assertSame('<p><a href="/item2/item2-3" id="unique">Relative ID</a></p>',
$this->parsedown->text('[Relative ID](../item2-3?id=unique)'));
$this->assertSame('<p><a href="https://github.com/getgrav/grav" class="button big">External</a></p>',
$this->parsedown->text('[External](https://github.com/getgrav/grav?classes=button,big)'));
$this->assertSame('<p><a href="/item2/item2-3?id=unique">Relative Noprocess</a></p>',
$this->parsedown->text('[Relative Noprocess](../item2-3?id=unique&noprocess)'));
$this->assertSame('<p><a href="/item2/item2-3" target="_blank">Relative Target</a></p>',
$this->parsedown->text('[Relative Target](../item2-3?target=_blank)'));
$this->assertSame('<p><a href="/item2/item2-3" rel="nofollow">Relative Rel</a></p>',
$this->parsedown->text('[Relative Rel](../item2-3?rel=nofollow)'));
$this->assertSame('<p><a href="/item2/item2-3?foo=bar&baz=qux" rel="nofollow" class="button">Relative Mixed</a></p>',
$this->parsedown->text('[Relative Mixed](../item2-3?foo=bar&baz=qux&rel=nofollow&class=button)'));
}
public function testInvalidLinks()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/item2/item2-2/no-page">Non Existent Page</a></p>',
$this->parsedown->text('[Non Existent Page](no-page)'));
$this->assertSame('<p><a href="/item2/item2-2/existing-file.zip">Existent File</a></p>',
$this->parsedown->text('[Existent File](existing-file.zip)'));
$this->assertSame('<p><a href="/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
$this->parsedown->text('[Non Existent File](missing-file.zip)'));
}
public function testInvalidLinksSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="/subdir/item2/item2-2/no-page">Non Existent Page</a></p>',
$this->parsedown->text('[Non Existent Page](no-page)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>',
$this->parsedown->text('[Existent File](existing-file.zip)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
$this->parsedown->text('[Non Existent File](missing-file.zip)'));
}
public function testInvalidLinksSubDirAbsoluteUrl()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/no-page">Non Existent Page</a></p>',
$this->parsedown->text('[Non Existent Page](no-page)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>',
$this->parsedown->text('[Existent File](existing-file.zip)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
$this->parsedown->text('[Non Existent File](missing-file.zip)'));
}
/**
* @param $string
*
* @return mixed
*/
private function stripLeadingWhitespace($string)
{
return preg_replace('/^\s*(.*)/', '', $string);
}
}
+286
View File
@@ -0,0 +1,286 @@
<?php
use Codeception\Util\Fixtures;
use Codeception\Util\Stub;
use Grav\Common\Grav;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Page;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
/**
* Class PagesTest
*/
class PagesTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var Pages $pages */
protected $pages;
/** @var Page $root_page */
protected $root_page;
static $run = false;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->pages = $this->grav['pages'];
$this->grav['config']->set('system.home.alias', '/home');
if (!self::$run) {
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$locator->addPath('page', '', 'tests/fake/simple-site/user/pages', false);
$this->pages->init();
self::$run = true;
}
}
public function testBase()
{
$this->assertSame('', $this->pages->base());
$this->pages->base('/test');
$this->assertSame('/test', $this->pages->base());
$this->pages->base('');
$this->assertSame(null, $this->pages->base());
}
public function testLastModified()
{
$this->assertSame(null, $this->pages->lastModified());
$this->pages->lastModified('test');
$this->assertSame('test', $this->pages->lastModified());
}
public function testInstances()
{
$this->assertTrue(is_array($this->pages->instances()));
foreach($this->pages->instances() as $instance) {
$this->assertInstanceOf('Grav\Common\Page\Page', $instance);
}
}
public function testRoutes()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$this->assertTrue(is_array($this->pages->routes()));
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/01.home', $this->pages->routes()['/']);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/01.home', $this->pages->routes()['/home']);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog', $this->pages->routes()['/blog']);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', $this->pages->routes()['/blog/post-one']);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', $this->pages->routes()['/blog/post-two']);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/03.about', $this->pages->routes()['/about']);
}
public function testAddPage()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$path = $locator->findResource('tests://') . '/fake/single-pages/01.simple-page/default.md';
$aPage = new Page();
$aPage->init(new \SplFileInfo($path));
$this->pages->addPage($aPage, '/new-page');
$this->assertTrue(in_array('/new-page', array_keys($this->pages->routes())));
$this->assertSame($locator->findResource('tests://') . '/fake/single-pages/01.simple-page', $this->pages->routes()['/new-page']);
}
public function testSort()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$aPage = $this->pages->dispatch('/blog');
$subPagesSorted = $this->pages->sort($aPage);
$this->assertTrue(is_array($subPagesSorted));
$this->assertTrue(count($subPagesSorted) === 2);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[0]);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[1]);
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
$subPagesSorted = $this->pages->sort($aPage, null, 'desc');
$this->assertTrue(is_array($subPagesSorted));
$this->assertTrue(count($subPagesSorted) === 2);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[0]);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[1]);
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
}
public function testSortCollection()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$aPage = $this->pages->dispatch('/blog');
$subPagesSorted = $this->pages->sortCollection($aPage->children(), $aPage->orderBy());
$this->assertTrue(is_array($subPagesSorted));
$this->assertTrue(count($subPagesSorted) === 2);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[0]);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[1]);
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
$subPagesSorted = $this->pages->sortCollection($aPage->children(), $aPage->orderBy(), 'desc');
$this->assertTrue(is_array($subPagesSorted));
$this->assertTrue(count($subPagesSorted) === 2);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[0]);
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[1]);
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
}
public function testGet()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
//Page existing
$aPage = $this->pages->get($locator->findResource('tests://') . '/fake/simple-site/user/pages/03.about');
$this->assertTrue(is_object($aPage));
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
//Page not existing
$anotherPage = $this->pages->get($locator->findResource('tests://') . '/fake/simple-site/user/pages/03.non-existing');
$this->assertFalse(is_object($anotherPage));
$this->assertNull($anotherPage);
}
public function testChildren()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
//Page existing
$children = $this->pages->children($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog');
$this->assertInstanceOf('Grav\Common\Page\Collection', $children);
//Page not existing
$children = $this->pages->children($locator->findResource('tests://') . '/fake/whatever/non-existing');
$this->assertSame([], $children->toArray());
}
public function testDispatch()
{
$aPage = $this->pages->dispatch('/blog');
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
$aPage = $this->pages->dispatch('/about');
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
$aPage = $this->pages->dispatch('/blog/post-one');
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
//Page not existing
$aPage = $this->pages->dispatch('/non-existing');
$this->assertNull($aPage);
}
public function testRoot()
{
$root = $this->pages->root();
$this->assertInstanceOf('Grav\Common\Page\Page', $root);
$this->assertSame('pages', $root->folder());
}
public function testBlueprints()
{
}
public function testAll()
{
$this->assertTrue(is_object($this->pages->all()));
$this->assertTrue(is_array($this->pages->all()->toArray()));
foreach($this->pages->all() as $page) {
$this->assertInstanceOf('Grav\Common\Page\Page', $page);
}
}
public function testGetList()
{
$list = $this->pages->getList();
$this->assertTrue(is_array($list));
$this->assertSame('Home', $list['/']);
$this->assertSame('Blog', $list['/blog']);
}
public function testGetTypes()
{
}
public function testTypes()
{
}
public function testModularTypes()
{
}
public function testPageTypes()
{
}
public function testAccessLevels()
{
}
public function testParents()
{
}
public function testParentsRawRoutes()
{
}
public function testGetHomeRoute()
{
}
public function testResetPages()
{
}
}
+414
View File
@@ -0,0 +1,414 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
/**
* Class UriTest
*/
class UriTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var Uri $uri */
protected $uri;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->uri = $this->grav['uri'];
}
protected function _after()
{
}
public function testValidatingHostname()
{
$this->assertTrue($this->uri->validateHostname('localhost') == 1);
$this->assertTrue($this->uri->validateHostname('google.com') == 1);
$this->assertTrue($this->uri->validateHostname('google.it') == 1);
$this->assertTrue($this->uri->validateHostname('goog.le') == 1);
$this->assertTrue($this->uri->validateHostname('goog.wine') == 1);
$this->assertTrue($this->uri->validateHostname('goog.localhost') == 1);
$this->assertFalse($this->uri->validateHostname('localhost:80') == 1);
$this->assertFalse($this->uri->validateHostname('http://localhost') == 1);
$this->assertFalse($this->uri->validateHostname('localhost!') == 1);
}
public function testInitializingUris()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertTrue($this->uri->params() == null);
$this->assertTrue($this->uri->query() == '');
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertFalse($this->uri->params() == null);
$this->assertTrue($this->uri->query() == '');
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertTrue($this->uri->params() == null);
$this->assertTrue($this->uri->query() != '');
$this->assertTrue($this->uri->query() == 'test=x');
$this->assertTrue($this->uri->port() == '8080');
$this->uri->initializeWithURL('http://localhost:80/grav/it/ueper?test=x')->init();
$this->assertTrue($this->uri->port() == '80');
$this->uri->initializeWithURL('http://localhost/grav/it/ueper?test=x')->init();
$this->assertTrue($this->uri->port() == '80');
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertTrue($this->uri->params() == null);
$this->uri->initializeWithURL('http://grav/grav/it/ueper')->init();
$this->assertTrue($this->uri->params() == null);
}
public function testPaths()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame(['grav', 'it', 'ueper'], $this->uri->paths());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame(['grav', 'it'], $this->uri->paths());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame(['grav', 'it', 'ueper'], $this->uri->paths());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame(['a', 'b', 'c', 'd'], $this->uri->paths());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame(['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f'],
$this->uri->paths());
}
public function testRoute()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame('/grav/it/ueper', $this->uri->route());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('/grav/it', $this->uri->route());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame('/grav/it/ueper', $this->uri->route());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame('/a/b/c/d', $this->uri->route());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame('/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f', $this->uri->route());
}
public function testQuery()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame('', $this->uri->query());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame('test=x', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
$this->assertSame('x', $this->uri->query('test'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y')->init();
$this->assertSame('test=x&test2=y', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
$this->assertSame('x', $this->uri->query('test'));
$this->assertSame('y', $this->uri->query('test2'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y')->init();
$this->assertSame('test=x&test2=y&test3=x&test4=y', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
$this->assertSame('x', $this->uri->query('test'));
$this->assertSame('y', $this->uri->query('test2'));
$this->assertSame('y', $this->uri->query('test4'));
//Test all after the ? is encoded in the query
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y/test')->init();
$this->assertSame('test=x&test2=y&test3=x&test4=y%2Ftest', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
$this->assertSame('x', $this->uri->query('test'));
$this->assertSame('y', $this->uri->query('test2'));
$this->assertSame('y/test', $this->uri->query('test4'));
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame('', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame('', $this->uri->query());
$this->assertSame(null, $this->uri->query('id'));
}
public function testParams()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame(null, $this->uri->params());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('/ueper:xxx', $this->uri->params());
$this->assertSame('/ueper:xxx', $this->uri->params('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx/test:yyy')->init();
$this->assertSame('/ueper:xxx/test:yyy', $this->uri->params());
$this->assertSame('/ueper:xxx', $this->uri->params('ueper'));
$this->assertSame('/test:yyy', $this->uri->params('test'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame(null, $this->uri->params());
$this->assertSame(null, $this->uri->params('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y')->init();
$this->assertSame(null, $this->uri->params());
$this->assertSame(null, $this->uri->params('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y')->init();
$this->assertSame(null, $this->uri->params());
$this->assertSame(null, $this->uri->params('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y/test')->init();
$this->assertSame(null, $this->uri->params());
$this->assertSame(null, $this->uri->params('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame(null, $this->uri->params());
$this->assertSame(null, $this->uri->params('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame(null, $this->uri->params());
$this->assertSame(null, $this->uri->params('ueper'));
}
public function testParam()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('xxx', $this->uri->param('ueper'));
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx/test:yyy')->init();
$this->assertSame('xxx', $this->uri->param('ueper'));
$this->assertSame('yyy', $this->uri->param('test'));
}
public function testUrl()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame('/grav/it/ueper', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('/grav/it', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx/test:yyy')->init();
$this->assertSame('/grav/it', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame('/grav/it/ueper', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y')->init();
$this->assertSame('/grav/it/ueper', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y')->init();
$this->assertSame('/grav/it/ueper', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y/test')->init();
$this->assertSame('/grav/it/ueper', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame('/a/b/c/d', $this->uri->url());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame('/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f', $this->uri->url());
}
public function testPath()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame('/grav/it/ueper', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('/grav/it', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx/test:yyy')->init();
$this->assertSame('/grav/it', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame('/grav/it/ueper', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y')->init();
$this->assertSame('/grav/it/ueper', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y')->init();
$this->assertSame('/grav/it/ueper', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y/test')->init();
$this->assertSame('/grav/it/ueper', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame('/a/b/c/d', $this->uri->path());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame('/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f', $this->uri->path());
$this->uri->initializeWithURL('http://localhost/')->init();
$this->assertSame('/', $this->uri->path());
}
public function testExtension()
{
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame(null, $this->uri->extension());
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame('x', $this->uri->extension('x'));
$this->uri->initializeWithURL('http://localhost/a-page.html')->init();
$this->assertSame('html', $this->uri->extension());
$this->uri->initializeWithURL('http://localhost/a-page.xml')->init();
$this->assertSame('xml', $this->uri->extension());
$this->uri->initializeWithURL('http://localhost/a-page.foo')->init();
$this->assertSame('foo', $this->uri->extension());
}
public function testHost()
{
$address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';
if ($this->uri->host() == 'localhost' || $address == '::1' || $address == '127.0.0.1') {
$address = 'localhost';
}
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame($address, $this->uri->host());
$this->uri->initializeWithURL('http://localhost/')->init();
$this->assertSame($address, $this->uri->host());
}
public function testPort()
{
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame('80', $this->uri->port());
$this->uri->initializeWithURL('http://localhost:8080/a-page')->init();
$this->assertSame(8080, $this->uri->port());
$this->uri->initializeWithURL('http://localhost:443/a-page')->init();
$this->assertSame(443, $this->uri->port());
$this->uri->initializeWithURL('https://localhost/a-page')->init();
$this->assertSame('80', $this->uri->port());
}
public function testEnvironment()
{
$address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';
if ($this->uri->host() == 'localhost' || $address == '::1' || $address == '127.0.0.1') {
$address = 'localhost';
}
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame($address, $this->uri->environment());
$this->uri->initializeWithURL('http://localhost:8080/a-page')->init();
$this->assertSame($address, $this->uri->environment());
$this->uri->initializeWithURL('http://foobar.it:443/a-page')->init();
$this->assertSame($address, $this->uri->environment());
$this->uri->initializeWithURL('https://google.com/a-page')->init();
$this->assertSame($address, $this->uri->environment());
}
public function testBasename()
{
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
$this->assertSame('ueper', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx')->init();
$this->assertSame('it', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper:xxx/test:yyy')->init();
$this->assertSame('it', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x')->init();
$this->assertSame('ueper', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y')->init();
$this->assertSame('ueper', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y')->init();
$this->assertSame('ueper', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper?test=x&test2=y&test3=x&test4=y/test')->init();
$this->assertSame('ueper', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame('d', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame('f', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost/')->init();
$this->assertSame('', $this->uri->basename());
$this->uri->initializeWithURL('http://localhost/test.xml')->init();
$this->assertSame('test.xml', $this->uri->basename());
}
public function testBase()
{
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame('http://localhost', $this->uri->base());
$this->uri->initializeWithURL('http://localhost:8080/a-page')->init();
$this->assertSame('http://localhost:8080', $this->uri->base());
$this->uri->initializeWithURL('http://foobar.it:80/a-page')->init();
$this->assertSame('http://foobar.it', $this->uri->base());
$this->uri->initializeWithURL('https://google.com/a-page')->init();
$this->assertSame('http://google.com', $this->uri->base());
}
public function testRootUrl()
{
//Without explicitly adding the root path via `initializeWithUrlAndRootPath`,
//tests always default to the base empty root path
$this->uri->initializeWithURL('http://localhost/a-page')->init();
$this->assertSame('http://localhost', $this->uri->rootUrl(true));
$this->uri->initializeWithURL('http://localhost:8080/a-page')->init();
$this->assertSame('http://localhost:8080', $this->uri->rootUrl(true));
$this->uri->initializeWithURL('http://foobar.it:80/a-page')->init();
$this->assertSame('http://foobar.it', $this->uri->rootUrl(true));
$this->uri->initializeWithURL('https://google.com/a-page/xxx')->init();
$this->assertSame('http://google.com', $this->uri->rootUrl(true));
$this->uri->initializeWithUrlAndRootPath('https://localhost/grav/page-foo', '/grav')->init();
$this->assertSame('/grav', $this->uri->rootUrl());
$this->assertSame('http://localhost/grav', $this->uri->rootUrl(true));
}
public function testCurrentPage()
{
$this->uri->initializeWithURL('http://localhost/foo/page:test')->init();
$this->assertSame('test', $this->uri->currentPage());
$this->uri->initializeWithURL('http://localhost:8080/a-page')->init();
$this->assertSame(1, $this->uri->currentPage());
$this->uri->initializeWithURL('http://localhost:8080/a-page/page:2')->init();
$this->assertSame('2', $this->uri->currentPage());
$this->uri->initializeWithURL('http://localhost:8080/a-page/page:x')->init();
$this->assertSame('x', $this->uri->currentPage());
$this->uri->initializeWithURL('http://localhost:8080/a-page/page:')->init();
$this->assertSame('', $this->uri->currentPage());
}
public function testReferrer()
{
$this->uri->initializeWithURL('http://localhost/foo/page:test')->init();
$this->assertSame('/foo', $this->uri->referrer());
$this->uri->initializeWithURL('http://localhost/foo/bar/page:test')->init();
$this->assertSame('/foo/bar', $this->uri->referrer());
}
public function testIp()
{
$this->uri->initializeWithURL('http://localhost/foo/page:test')->init();
$this->assertSame('UNKNOWN', $this->uri->ip());
}
public function testIsExternal()
{
$this->uri->initializeWithURL('http://localhost/')->init();
$this->assertFalse($this->uri->isExternal('/test'));
$this->assertFalse($this->uri->isExternal('/foo/bar'));
$this->assertTrue($this->uri->isExternal('http://localhost/test'));
$this->assertTrue($this->uri->isExternal('http://google.it/test'));
}
public function testBuildUrl()
{
$parsed_url = [
'scheme' => 'http',
'host' => 'localhost',
'port' => '8080',
];
$this->assertSame('http://localhost:8080', Uri::buildUrl($parsed_url));
$parsed_url = [
'scheme' => 'http',
'host' => 'localhost',
'port' => '8080',
'user' => 'foo',
'pass' => 'bar',
'path' => '/test',
'query' => 'x=2',
'fragment' => 'xxx',
];
$this->assertSame('http://foo:bar@localhost:8080/test?x=2#xxx', Uri::buildUrl($parsed_url));
}
public function testConvertUrl()
{
}
public function testAddNonce()
{
$url = 'http://localhost/foo';
$this->assertStringStartsWith($url, Uri::addNonce($url, 'test-action'));
$this->assertStringStartsWith($url . '/nonce:', Uri::addNonce($url, 'test-action'));
$this->uri->initializeWithURL(Uri::addNonce($url, 'test-action'))->init();
$this->assertTrue(is_string($this->uri->param('nonce')));
$this->assertSame(Utils::getNonce('test-action'), $this->uri->param('nonce'));
}
}
+263
View File
@@ -0,0 +1,263 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Utils;
/**
* Class UtilsTest
*/
class UtilsTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
protected function _before()
{
$this->grav = Fixtures::get('grav');
}
protected function _after()
{
}
public function testStartsWith()
{
$this->assertTrue(Utils::startsWith('english', 'en'));
$this->assertTrue(Utils::startsWith('English', 'En'));
$this->assertTrue(Utils::startsWith('ENGLISH', 'EN'));
$this->assertTrue(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'EN'));
$this->assertFalse(Utils::startsWith('english', 'En'));
$this->assertFalse(Utils::startsWith('English', 'EN'));
$this->assertFalse(Utils::startsWith('ENGLISH', 'en'));
$this->assertFalse(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'e'));
}
public function testEndsWith()
{
$this->assertTrue(Utils::endsWith('english', 'sh'));
$this->assertTrue(Utils::endsWith('EngliSh', 'Sh'));
$this->assertTrue(Utils::endsWith('ENGLISH', 'SH'));
$this->assertTrue(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'ENGLISH'));
$this->assertFalse(Utils::endsWith('english', 'de'));
$this->assertFalse(Utils::endsWith('EngliSh', 'sh'));
$this->assertFalse(Utils::endsWith('ENGLISH', 'Sh'));
$this->assertFalse(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
}
public function testContains()
{
$this->assertTrue(Utils::contains('english', 'nglis'));
$this->assertTrue(Utils::contains('EngliSh', 'gliSh'));
$this->assertTrue(Utils::contains('ENGLISH', 'ENGLI'));
$this->assertTrue(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'ENGLISH'));
$this->assertFalse(Utils::contains('EngliSh', 'GLI'));
$this->assertFalse(Utils::contains('EngliSh', 'English'));
$this->assertFalse(Utils::contains('ENGLISH', 'SCH'));
$this->assertFalse(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
}
public function testSubstrToString()
{
$this->assertEquals(Utils::substrToString('english', 'glish'), 'en');
$this->assertEquals(Utils::substrToString('english', 'test'), 'english');
$this->assertNotEquals(Utils::substrToString('english', 'lish'), 'en');
}
public function testMergeObjects()
{
$obj1 = new stdClass();
$obj1->test1 = 'x';
$obj2 = new stdClass();
$obj2->test2 = 'y';
$objMerged = Utils::mergeObjects($obj1, $obj2);
$this->assertObjectHasAttribute('test1', $objMerged);
$this->assertObjectHasAttribute('test2', $objMerged);
}
public function testDateFormats()
{
$dateFormats = Utils::dateFormats();
$this->assertTrue(is_array($dateFormats));
$this->assertContainsOnly('string', $dateFormats);
$default_format = $this->grav['config']->get('system.pages.dateformat.default');
if ($default_format !== null) {
$this->assertTrue(isset($dateFormats[$default_format]));
}
}
public function testTruncate()
{
$this->assertEquals(Utils::truncate('english', 5), 'engli' . '&hellip;');
$this->assertEquals(Utils::truncate('english'), 'english');
$this->assertEquals(Utils::truncate('This is a string to truncate'), 'This is a string to truncate');
$this->assertEquals(Utils::truncate('This is a string to truncate', 2), 'Th' . '&hellip;');
$this->assertEquals(Utils::truncate('english', 5, true, " ", "..."), 'engli' . '...');
$this->assertEquals(Utils::truncate('english'), 'english');
$this->assertEquals(Utils::truncate('This is a string to truncate'), 'This is a string to truncate');
$this->assertEquals(Utils::truncate('This is a string to truncate', 3, true), 'This ');
}
public function testSafeTruncate()
{
$this->assertEquals(Utils::safeTruncate('This is a string to truncate', 1), 'This ');
$this->assertEquals(Utils::safeTruncate('This is a string to truncate', 4), 'This ');
$this->assertEquals(Utils::safeTruncate('This is a string to truncate', 5), 'This is ');
}
public function testTruncateHtml()
{
$this->assertEquals(Utils::truncateHtml('<p>This is a string to truncate</p>', 1), '<p>T…</p>');
$this->assertEquals(Utils::truncateHtml('<p>This is a string to truncate</p>', 4), '<p>This…</p>');
}
public function testSafeTruncateHtml()
{
$this->assertEquals(Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 1), '<p>This…</p>');
$this->assertEquals(Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 4), '<p>This…</p>');
}
public function testGenerateRandomString()
{
$this->assertNotEquals(Utils::generateRandomString(), Utils::generateRandomString());
$this->assertNotEquals(Utils::generateRandomString(20), Utils::generateRandomString(20));
}
public function download()
{
}
public function testGetMimeType()
{
$this->assertEquals(Utils::getMimeType(''), 'application/octet-stream');
$this->assertEquals(Utils::getMimeType('jpg'), 'image/jpeg');
$this->assertEquals(Utils::getMimeType('png'), 'image/png');
$this->assertEquals(Utils::getMimeType('txt'), 'text/plain');
$this->assertEquals(Utils::getMimeType('doc'), 'application/msword');
}
public function testNormalizePath()
{
$this->assertEquals(Utils::normalizePath('/test'), '/test');
$this->assertEquals(Utils::normalizePath('test'), 'test');
$this->assertEquals(Utils::normalizePath('../test'), 'test');
$this->assertEquals(Utils::normalizePath('/../test'), '/test');
$this->assertEquals(Utils::normalizePath('/test/../test2'), '/test2');
$this->assertEquals(Utils::normalizePath('/test/./test2'), '/test/test2');
}
public function testIsFunctionDisabled()
{
$disabledFunctions = explode(',', ini_get('disable_functions'));
if ($disabledFunctions[0]) {
$this->assertEquals(Utils::isFunctionDisabled($disabledFunctions[0]), true);
}
}
public function testTimezones()
{
$timezones = Utils::timezones();
$this->assertTrue(is_array($timezones));
$this->assertContainsOnly('string', $timezones);
}
public function testArrayFilterRecursive()
{
$array = [
'test' => '',
'test2' => 'test2'
];
$array = Utils::arrayFilterRecursive($array, function ($k, $v) {
return !(is_null($v) || $v === '');
});
$this->assertContainsOnly('string', $array);
$this->assertFalse(isset($array['test']));
$this->assertTrue(isset($array['test2']));
$this->assertEquals($array['test2'], 'test2');
}
public function testPathPrefixedByLangCode()
{
$languagesEnabled = $this->grav['config']->get('system.languages.supported', []);
$arrayOfLanguages = ['en', 'de', 'it', 'es', 'dk', 'el'];
$languagesNotEnabled = array_diff($arrayOfLanguages, $languagesEnabled);
$oneLanguageNotEnabled = reset($languagesNotEnabled);
if (count($languagesEnabled)) {
$this->assertTrue(Utils::pathPrefixedByLangCode('/' . $languagesEnabled[0] . '/test'));
}
$this->assertFalse(Utils::pathPrefixedByLangCode('/' . $oneLanguageNotEnabled . '/test'));
$this->assertFalse(Utils::pathPrefixedByLangCode('/test'));
$this->assertFalse(Utils::pathPrefixedByLangCode('/xx'));
$this->assertFalse(Utils::pathPrefixedByLangCode('/xx/'));
$this->assertFalse(Utils::pathPrefixedByLangCode('/'));
}
public function testDate2timestamp()
{
$timestamp = strtotime('10 September 2000');
$this->assertSame($timestamp, Utils::date2timestamp('10 September 2000'));
$this->assertSame($timestamp, Utils::date2timestamp('2000-09-10 00:00:00'));
}
public function testResolve()
{
$array = [
'test' => [
'test2' => 'test2Value'
]
];
$this->assertEquals(Utils::resolve($array, 'test.test2'), 'test2Value');
}
public function testIsPositive()
{
$this->assertTrue(Utils::isPositive(true));
$this->assertTrue(Utils::isPositive(1));
$this->assertTrue(Utils::isPositive('1'));
$this->assertTrue(Utils::isPositive('yes'));
$this->assertTrue(Utils::isPositive('on'));
$this->assertTrue(Utils::isPositive('true'));
$this->assertFalse(Utils::isPositive(false));
$this->assertFalse(Utils::isPositive(0));
$this->assertFalse(Utils::isPositive('0'));
$this->assertFalse(Utils::isPositive('no'));
$this->assertFalse(Utils::isPositive('off'));
$this->assertFalse(Utils::isPositive('false'));
$this->assertFalse(Utils::isPositive('some'));
$this->assertFalse(Utils::isPositive(2));
}
public function testGetNonce()
{
$this->assertTrue(is_string(Utils::getNonce('test-action')));
$this->assertTrue(is_string(Utils::getNonce('test-action', true)));
$this->assertSame(Utils::getNonce('test-action'), Utils::getNonce('test-action'));
$this->assertNotSame(Utils::getNonce('test-action'), Utils::getNonce('test-action2'));
}
public function testVerifyNonce()
{
$this->assertTrue(Utils::verifyNonce(Utils::getNonce('test-action'), 'test-action'));
}
}
+4
View File
@@ -0,0 +1,4 @@
<?php
// Here you can initialize variables that will be available to your tests
define('GRAV_CLI', true);