first commit

This commit is contained in:
2019-03-28 17:57:56 +01:00
commit b0e25fd66f
561 changed files with 56803 additions and 0 deletions

35
tests/_bootstrap.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace Grav;
use Codeception\Util\Fixtures;
use Faker\Factory;
use Grav\Common\Grav;
ini_set('error_log', __DIR__ . '/error.log');
$grav = function() {
Grav::resetInstance();
$grav = Grav::instance();
$grav['config']->init();
foreach (array_keys($grav['setup']->getStreams()) as $stream) {
@stream_wrapper_unregister($stream);
}
$grav['streams'];
$grav['uri']->init();
$grav['debugger']->init();
$grav['assets']->init();
$grav['config']->set('system.cache.enabled', false);
$grav['locator']->addPath('tests', '', 'tests', false);
return $grav;
};
Fixtures::add('grav', $grav);
$fake = Factory::create();
Fixtures::add('fake', $fake);

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
*/
}

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
*/
}

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
{
}

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
{
}

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) {
}
}

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
*/
}

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

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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

View File

@@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,5 @@
---
title: Simple Page
---
Simple Page Content

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

View File

@@ -0,0 +1,40 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Console\Gpm\DirectInstallCommand;
/**
* Class DirectInstallCommandTest
*/
class DirectInstallCommandTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var DirectInstallCommand */
protected $directInstall;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->directInstallCommand = new DirectInstallCommand();
}
}
/**
* Why this test file is empty
*
* Wasn't able to call a symfony\console. Kept having $output problem.
* symfony console \NullOutput didn't cut it.
*
* We would also need to Mock tests since downloading packages would
* make tests slow and unreliable. But it's not worth the time ATM.
*
* Look at Gpm/InstallCommandTest.php
*
* For the full story: https://git.io/vSlI3
*/

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

9
tests/unit.suite.yml Normal file
View File

@@ -0,0 +1,9 @@
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit

View File

@@ -0,0 +1,598 @@
<?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()
{
$grav = Fixtures::get('grav');
$this->grav = $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',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
$this->assets->add('test.js');
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => '/test.css',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
//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',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
//test addCss(). Testing with remote URL
$this->assets->reset();
$this->assets->addCSS('http://www.somesite.com/test.css');
$css = $this->assets->css();
$this->assertSame('<link href="http://www.somesite.com/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
$array = $this->assets->getCss();
$this->assertSame([
'asset' => 'http://www.somesite.com/test.css',
'remote' => true,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
//test addCss() adding asset to a separate group, and with an alternate rel attribute
$this->assets->reset();
$this->assets->addCSS('test.css', ['group' => 'alternate']);
$css = $this->assets->css('alternate', ['rel' => 'alternate']);
$this->assertSame('<link href="/test.css" type="text/css" rel="alternate" />' . PHP_EOL, $css);
//test addJs()
$this->assets->reset();
$this->assets->addJs('test.js');
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
//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',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'footer',
'modified' => false,
'query' => ''
], 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" ></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'footer',
'modified' => false,
'query' => ''
], reset($array));
//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" async></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => 'async',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
$this->assets->reset();
$this->assets->addJs('test.js', null, true, 'defer', null);
$js = $this->assets->js();
$this->assertSame('<script src="/test.js" defer></script>' . PHP_EOL, $js);
$array = $this->assets->getJs();
$this->assertSame([
'asset' => '/test.js',
'remote' => false,
'priority' => 10,
'order' => 0,
'pipeline' => true,
'loading' => 'defer',
'group' => 'head',
'modified' => false,
'query' => ''
], reset($array));
//Test inline
$this->assets->reset();
$this->assets->addJs('/system/assets/jquery/jquery-2.x.min.js', null, true, 'inline', null);
$js = $this->assets->js();
$this->assertContains('jQuery Foundation', $js);
$this->assets->reset();
$this->assets->addCss('/system/assets/debugger.css', null, true, null, 'inline');
$css = $this->assets->css();
$this->assertContains('div.phpdebugbar', $css);
$this->assets->reset();
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true, null, 'inline');
$css = $this->assets->css();
$this->assertContains('font-family: \'Roboto\';', $css);
//Test adding media queries
$this->assets->reset();
$this->assets->add('test.css', ['media' => 'only screen and (min-width: 640px)']);
$css = $this->assets->css();
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 640px)" />' . PHP_EOL, $css);
}
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" 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" 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" async></script>' . PHP_EOL .
'<script src="/system/assets/jquery/jquery-2.x.min.js" 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" async></script>' . PHP_EOL, $js);
$js = $this->assets->js('footer');
$this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" 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" async></script>' . PHP_EOL .
'<script src="/test.js" 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 testPipelineWithTimestamp()
{
$this->assets->reset();
$this->assets->setTimestamp('foo');
//Add a core Grav CSS file, which is found. Pipeline will now return a file
$this->assets->add('/system/assets/debugger.css', null, true);
$css = $this->assets->css();
$this->assertContains('<link href=', $css);
$this->assertContains('type="text/css" rel="stylesheet" />', $css);
$this->assertContains($this->assets->getTimestamp(), $css);
}
public function testInlinePipeline()
{
$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('head', ['loading' => 'inline']);
$this->assertSame('', $css);
//Add a core Grav CSS file, which is found. Pipeline will now return its content.
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true);
$this->assets->add('/system/assets/debugger.css', null, true);
$css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertContains('font-family:\'Roboto\';', $css);
$this->assertContains('div.phpdebugbar', $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" 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" defer></script>' . PHP_EOL, $js);
}
public function testTimestamps()
{
// local CSS nothing extra
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('test.css');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css?foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
// local CSS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('test.css?bar');
$css = $this->assets->css();
$this->assertSame('<link href="/test.css?bar&foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
// external CSS already
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('http://somesite.com/test.css');
$css = $this->assets->css();
$this->assertSame('<link href="http://somesite.com/test.css?foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
// external CSS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addCSS('http://somesite.com/test.css?bar');
$css = $this->assets->css();
$this->assertSame('<link href="http://somesite.com/test.css?bar&foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
// local JS nothing extra
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('test.js');
$css = $this->assets->js();
$this->assertSame('<script src="/test.js?foo" ></script>' . PHP_EOL, $css);
// local JS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('test.js?bar');
$css = $this->assets->js();
$this->assertSame('<script src="/test.js?bar&foo" ></script>' . PHP_EOL, $css);
// external JS already
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('http://somesite.com/test.js');
$css = $this->assets->js();
$this->assertSame('<script src="http://somesite.com/test.js?foo" ></script>' . PHP_EOL, $css);
// external JS already with param
$this->assets->reset();
$this->assets->setTimestamp('foo');
$this->assets->addJs('http://somesite.com/test.js?bar');
$css = $this->assets->js();
$this->assertSame('<script src="http://somesite.com/test.js?bar&foo" ></script>' . PHP_EOL, $css);
}
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->assertInternalType('array', $this->assets->getCollections());
$this->assertContains('jquery', array_keys($this->assets->getCollections()));
$this->assertContains('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->assertContains('debugger', array_keys($this->assets->getCollections()));
}
public function testReset()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->js());
$this->assets->addAsyncJs('jquery');
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->js());
$this->assets->addInlineCss('body { color: black }');
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->css());
$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->reset();
$this->assertCount(0, (array) $this->assets->css());
}
public function testResetJs()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->resetJs();
$this->assertCount(0, (array) $this->assets->js());
$this->assets->addAsyncJs('jquery');
$this->assets->resetJs();
$this->assertCount(0, (array) $this->assets->js());
}
public function testResetCss()
{
$this->assertCount(0, (array) $this->assets->js());
$this->assets->addInlineCss('body { color: black }');
$this->assets->resetCss();
$this->assertCount(0, (array) $this->assets->css());
$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->resetCss();
$this->assertCount(0, (array) $this->assets->css());
}
public function testAddDirCss()
{
$this->assets->addDirCss('/system');
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertCount(0, (array) $this->assets->getJs());
$this->assets->reset();
$this->assets->addDirCss('/system/assets');
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertCount(0, (array) $this->assets->getJs());
$this->assets->reset();
$this->assets->addDirJs('/system');
$this->assertInternalType('array', $this->assets->getCss());
$this->assertCount(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs());
$this->assets->reset();
$this->assets->addDirJs('/system/assets');
$this->assertInternalType('array', $this->assets->getCss());
$this->assertCount(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs());
$this->assets->reset();
$this->assets->addDir('/system/assets');
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs());
//Use streams
$this->assets->reset();
$this->assets->addDir('system://assets');
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs());
}
}

View File

@@ -0,0 +1,48 @@
<?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()
{
$grav = Fixtures::get('grav');
$this->grav = $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());
}
}

View File

@@ -0,0 +1,32 @@
<?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->assertInternalType('string', $composerLocation);
$this->assertSame('/', $composerLocation[0]);
}
public function testGetComposerExecutor()
{
$composerExecutor = Composer::getComposerExecutor();
$this->assertInternalType('string', $composerExecutor);
$this->assertSame('/', $composerExecutor[0]);
$this->assertNotNull(strstr($composerExecutor, 'php'));
$this->assertNotNull(strstr($composerExecutor, 'composer'));
}
}

View File

@@ -0,0 +1,323 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\GPM\GPM;
define('EXCEPTION_BAD_FORMAT', 1);
define('EXCEPTION_INCOMPATIBLE_VERSIONS', 2);
class GpmStub extends GPM
{
public $data;
public function findPackage($packageName, $ignore_exception = false)
{
if (isset($this->data[$packageName])) {
return $this->data[$packageName];
}
}
public function findPackages($searches = [])
{
return $this->data;
}
}
/**
* Class InstallCommandTest
*/
class GpmTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var GpmStub */
protected $gpm;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->gpm = new GpmStub();
}
protected function _after()
{
}
public function testCalculateMergedDependenciesOfPackages()
{
//////////////////////////////////////////////////////////////////////////////////////////
// First working example
//////////////////////////////////////////////////////////////////////////////////////////
$this->gpm->data = [
'admin' => (object)[
'dependencies' => [
["name" => "grav", "version" => ">=1.0.10"],
["name" => "form", "version" => "~2.0"],
["name" => "login", "version" => ">=2.0"],
["name" => "errors", "version" => "*"],
["name" => "problems"],
]
],
'test' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">=1.0"]
]
],
'grav',
'form' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">=3.2"]
]
]
];
$packages = ['admin', 'test'];
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies);
$this->assertCount(5, $dependencies);
$this->assertSame('>=1.0.10', $dependencies['grav']);
$this->assertArrayHasKey('errors', $dependencies);
$this->assertArrayHasKey('problems', $dependencies);
//////////////////////////////////////////////////////////////////////////////////////////
// Second working example
//////////////////////////////////////////////////////////////////////////////////////////
$packages = ['admin', 'form'];
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies);
$this->assertCount(5, $dependencies);
$this->assertSame('>=3.2', $dependencies['errors']);
//////////////////////////////////////////////////////////////////////////////////////////
// Third working example
//////////////////////////////////////////////////////////////////////////////////////////
$this->gpm->data = [
'admin' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">=4.0"],
]
],
'test' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">=1.0"]
]
],
'another' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">=3.2"]
]
]
];
$packages = ['admin', 'test', 'another'];
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies);
$this->assertCount(1, $dependencies);
$this->assertSame('>=4.0', $dependencies['errors']);
//////////////////////////////////////////////////////////////////////////////////////////
// Test alpha / beta / rc
//////////////////////////////////////////////////////////////////////////////////////////
$this->gpm->data = [
'admin' => (object)[
'dependencies' => [
["name" => "package1", "version" => ">=4.0.0-rc1"],
["name" => "package4", "version" => ">=3.2.0"],
]
],
'test' => (object)[
'dependencies' => [
["name" => "package1", "version" => ">=4.0.0-rc2"],
["name" => "package2", "version" => ">=3.2.0-alpha"],
["name" => "package3", "version" => ">=3.2.0-alpha.2"],
["name" => "package4", "version" => ">=3.2.0-alpha"],
]
],
'another' => (object)[
'dependencies' => [
["name" => "package2", "version" => ">=3.2.0-beta.11"],
["name" => "package3", "version" => ">=3.2.0-alpha.1"],
["name" => "package4", "version" => ">=3.2.0-beta"],
]
]
];
$packages = ['admin', 'test', 'another'];
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertSame('>=4.0.0-rc2', $dependencies['package1']);
$this->assertSame('>=3.2.0-beta.11', $dependencies['package2']);
$this->assertSame('>=3.2.0-alpha.2', $dependencies['package3']);
$this->assertSame('>=3.2.0', $dependencies['package4']);
//////////////////////////////////////////////////////////////////////////////////////////
// Raise exception if no version is specified
//////////////////////////////////////////////////////////////////////////////////////////
$this->gpm->data = [
'admin' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">=4.0"],
]
],
'test' => (object)[
'dependencies' => [
["name" => "errors", "version" => ">="]
]
],
];
$packages = ['admin', 'test'];
try {
$this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->fail("Expected Exception not thrown");
} catch (Exception $e) {
$this->assertEquals(EXCEPTION_BAD_FORMAT, $e->getCode());
$this->assertStringStartsWith("Bad format for version of dependency", $e->getMessage());
}
//////////////////////////////////////////////////////////////////////////////////////////
// Raise exception if incompatible versions are specified
//////////////////////////////////////////////////////////////////////////////////////////
$this->gpm->data = [
'admin' => (object)[
'dependencies' => [
["name" => "errors", "version" => "~4.0"],
]
],
'test' => (object)[
'dependencies' => [
["name" => "errors", "version" => "~3.0"]
]
],
];
$packages = ['admin', 'test'];
try {
$this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->fail("Expected Exception not thrown");
} catch (Exception $e) {
$this->assertEquals(EXCEPTION_INCOMPATIBLE_VERSIONS, $e->getCode());
$this->assertStringEndsWith("required in two incompatible versions", $e->getMessage());
}
//////////////////////////////////////////////////////////////////////////////////////////
// Test dependencies of dependencies
//////////////////////////////////////////////////////////////////////////////////////////
$this->gpm->data = [
'admin' => (object)[
'dependencies' => [
["name" => "grav", "version" => ">=1.0.10"],
["name" => "form", "version" => "~2.0"],
["name" => "login", "version" => ">=2.0"],
["name" => "errors", "version" => "*"],
["name" => "problems"],
]
],
'login' => (object)[
'dependencies' => [
["name" => "antimatter", "version" => ">=1.0"]
]
],
'grav',
'antimatter' => (object)[
'dependencies' => [
["name" => "something", "version" => ">=3.2"]
]
]
];
$packages = ['admin'];
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies);
$this->assertCount(7, $dependencies);
$this->assertSame('>=1.0.10', $dependencies['grav']);
$this->assertArrayHasKey('errors', $dependencies);
$this->assertArrayHasKey('problems', $dependencies);
$this->assertArrayHasKey('antimatter', $dependencies);
$this->assertArrayHasKey('something', $dependencies);
$this->assertSame('>=3.2', $dependencies['something']);
}
public function testVersionFormatIsNextSignificantRelease()
{
$this->assertFalse($this->gpm->versionFormatIsNextSignificantRelease('>=1.0'));
$this->assertFalse($this->gpm->versionFormatIsNextSignificantRelease('>=2.3.4'));
$this->assertFalse($this->gpm->versionFormatIsNextSignificantRelease('>=2.3.x'));
$this->assertFalse($this->gpm->versionFormatIsNextSignificantRelease('1.0'));
$this->assertTrue($this->gpm->versionFormatIsNextSignificantRelease('~2.3.x'));
$this->assertTrue($this->gpm->versionFormatIsNextSignificantRelease('~2.0'));
}
public function testVersionFormatIsEqualOrHigher()
{
$this->assertTrue($this->gpm->versionFormatIsEqualOrHigher('>=1.0'));
$this->assertTrue($this->gpm->versionFormatIsEqualOrHigher('>=2.3.4'));
$this->assertTrue($this->gpm->versionFormatIsEqualOrHigher('>=2.3.x'));
$this->assertFalse($this->gpm->versionFormatIsEqualOrHigher('~2.3.x'));
$this->assertFalse($this->gpm->versionFormatIsEqualOrHigher('1.0'));
}
public function testCheckNextSignificantReleasesAreCompatible()
{
/*
* ~1.0 is equivalent to >=1.0 < 2.0.0
* ~1.2 is equivalent to >=1.2 <2.0.0
* ~1.2.3 is equivalent to >=1.2.3 <1.3.0
*/
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.0', '1.2'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.2', '1.0'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.0', '1.0.10'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.1', '1.1.10'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('30.0', '30.10'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.0', '1.1.10'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.0', '1.8'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('1.0.1', '1.1'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('2.0.0-beta', '2.0'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('2.0.0-rc.1', '2.0'));
$this->assertTrue($this->gpm->checkNextSignificantReleasesAreCompatible('2.0', '2.0.0-alpha'));
$this->assertFalse($this->gpm->checkNextSignificantReleasesAreCompatible('1.0', '2.2'));
$this->assertFalse($this->gpm->checkNextSignificantReleasesAreCompatible('1.0.0-beta.1', '2.0'));
$this->assertFalse($this->gpm->checkNextSignificantReleasesAreCompatible('0.9.99', '1.0.0'));
$this->assertFalse($this->gpm->checkNextSignificantReleasesAreCompatible('0.9.99', '1.0.10'));
$this->assertFalse($this->gpm->checkNextSignificantReleasesAreCompatible('0.9.99', '1.0.10.2'));
}
public function testCalculateVersionNumberFromDependencyVersion()
{
$this->assertSame('2.0', $this->gpm->calculateVersionNumberFromDependencyVersion('>=2.0'));
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('>=2.0.2'));
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('~2.0.2'));
$this->assertSame('1', $this->gpm->calculateVersionNumberFromDependencyVersion('~1'));
$this->assertNull($this->gpm->calculateVersionNumberFromDependencyVersion(''));
$this->assertNull($this->gpm->calculateVersionNumberFromDependencyVersion('*'));
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('2.0.2'));
}
}

View File

@@ -0,0 +1,85 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Helpers\Excerpts;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Config\Config;
use Grav\Common\Page\Pages;
use Grav\Common\Language\Language;
/**
* Class ExcerptsTest
*/
class ExcerptsTest extends \Codeception\TestCase\Test
{
/** @var Parsedown $parsedown */
protected $parsedown;
/** @var Grav $grav */
protected $grav;
/** @var Page $page */
protected $page;
/** @var Pages $pages */
protected $pages;
/** @var Config $config */
protected $config;
/** @var Uri $uri */
protected $uri;
/** @var Language $language */
protected $language;
protected $old_home;
protected function _before()
{
$grav = Fixtures::get('grav');
$this->grav = $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);
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
$this->pages->init();
$defaults = [
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
];
$this->page = $this->pages->dispatch('/item2/item2-2');
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
}
protected function _after()
{
$this->config->set('system.home.alias', $this->old_home);
}
public function testProcessImageHtml()
{
$this->assertRegexp('|<img alt="Sample Image" src="\/images\/.*-sample-image.jpe?g\" data-src="sample-image\.jpg\?cropZoom=300,300" \/>|',
Excerpts::processImageHtml('<img src="sample-image.jpg?cropZoom=300,300" alt="Sample Image" />', $this->page));
$this->assertRegexp('|<img alt="Sample Image" class="foo" src="\/images\/.*-sample-image.jpe?g\" data-src="sample-image\.jpg\?classes=foo" \/>|',
Excerpts::processImageHtml('<img src="sample-image.jpg?classes=foo" alt="Sample Image" />', $this->page));
}
}

View File

@@ -0,0 +1,147 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Inflector;
use Grav\Common\Utils;
/**
* Class InflectorTest
*/
class InflectorTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var Uri $uri */
protected $inflector;
protected function _before()
{
$grav = Fixtures::get('grav');
$this->grav = $grav();
$this->inflector = $this->grav['inflector'];
}
protected function _after()
{
}
public function testPluralize()
{
$this->assertSame('words', $this->inflector->pluralize('word'));
$this->assertSame('kisses', $this->inflector->pluralize('kiss'));
$this->assertSame('volcanoes', $this->inflector->pluralize('volcanoe'));
$this->assertSame('cherries', $this->inflector->pluralize('cherry'));
$this->assertSame('days', $this->inflector->pluralize('day'));
$this->assertSame('knives', $this->inflector->pluralize('knife'));
}
public function testSingularize()
{
$this->assertSame('word', $this->inflector->singularize('words'));
$this->assertSame('kiss', $this->inflector->singularize('kisses'));
$this->assertSame('volcanoe', $this->inflector->singularize('volcanoe'));
$this->assertSame('cherry', $this->inflector->singularize('cherries'));
$this->assertSame('day', $this->inflector->singularize('days'));
$this->assertSame('knife', $this->inflector->singularize('knives'));
}
public function testTitleize()
{
$this->assertSame('This String Is Titleized', $this->inflector->titleize('ThisStringIsTitleized'));
$this->assertSame('This String Is Titleized', $this->inflector->titleize('this string is titleized'));
$this->assertSame('This String Is Titleized', $this->inflector->titleize('this_string_is_titleized'));
$this->assertSame('This String Is Titleized', $this->inflector->titleize('this-string-is-titleized'));
$this->assertSame('This string is titleized', $this->inflector->titleize('ThisStringIsTitleized', 'first'));
$this->assertSame('This string is titleized', $this->inflector->titleize('this string is titleized', 'first'));
$this->assertSame('This string is titleized', $this->inflector->titleize('this_string_is_titleized', 'first'));
$this->assertSame('This string is titleized', $this->inflector->titleize('this-string-is-titleized', 'first'));
}
public function testCamelize()
{
$this->assertSame('ThisStringIsCamelized', $this->inflector->camelize('This String Is Camelized'));
$this->assertSame('ThisStringIsCamelized', $this->inflector->camelize('thisStringIsCamelized'));
$this->assertSame('ThisStringIsCamelized', $this->inflector->camelize('This_String_Is_Camelized'));
$this->assertSame('ThisStringIsCamelized', $this->inflector->camelize('this string is camelized'));
$this->assertSame('GravSPrettyCoolMy1', $this->inflector->camelize("Grav's Pretty Cool. My #1!"));
}
public function testUnderscorize()
{
$this->assertSame('this_string_is_underscorized', $this->inflector->underscorize('This String Is Underscorized'));
$this->assertSame('this_string_is_underscorized', $this->inflector->underscorize('ThisStringIsUnderscorized'));
$this->assertSame('this_string_is_underscorized', $this->inflector->underscorize('This_String_Is_Underscorized'));
$this->assertSame('this_string_is_underscorized', $this->inflector->underscorize('This-String-Is-Underscorized'));
}
public function testHyphenize()
{
$this->assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('This String Is Hyphenized'));
$this->assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('ThisStringIsHyphenized'));
$this->assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('This-String-Is-Hyphenized'));
$this->assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('This_String_Is_Hyphenized'));
}
public function testHumanize()
{
//$this->assertSame('This string is humanized', $this->inflector->humanize('ThisStringIsHumanized'));
$this->assertSame('This string is humanized', $this->inflector->humanize('this_string_is_humanized'));
//$this->assertSame('This string is humanized', $this->inflector->humanize('this-string-is-humanized'));
$this->assertSame('This String Is Humanized', $this->inflector->humanize('this_string_is_humanized', 'all'));
//$this->assertSame('This String Is Humanized', $this->inflector->humanize('this-string-is-humanized'), 'all');
}
public function testVariablize()
{
$this->assertSame('thisStringIsVariablized', $this->inflector->variablize('This String Is Variablized'));
$this->assertSame('thisStringIsVariablized', $this->inflector->variablize('ThisStringIsVariablized'));
$this->assertSame('thisStringIsVariablized', $this->inflector->variablize('This_String_Is_Variablized'));
$this->assertSame('thisStringIsVariablized', $this->inflector->variablize('this string is variablized'));
$this->assertSame('gravSPrettyCoolMy1', $this->inflector->variablize("Grav's Pretty Cool. My #1!"));
}
public function testTableize()
{
$this->assertSame('people', $this->inflector->tableize('Person'));
$this->assertSame('pages', $this->inflector->tableize('Page'));
$this->assertSame('blog_pages', $this->inflector->tableize('BlogPage'));
$this->assertSame('admin_dependencies', $this->inflector->tableize('adminDependency'));
$this->assertSame('admin_dependencies', $this->inflector->tableize('admin-dependency'));
$this->assertSame('admin_dependencies', $this->inflector->tableize('admin_dependency'));
}
public function testClassify()
{
$this->assertSame('Person', $this->inflector->classify('people'));
$this->assertSame('Page', $this->inflector->classify('pages'));
$this->assertSame('BlogPage', $this->inflector->classify('blog_pages'));
$this->assertSame('AdminDependency', $this->inflector->classify('admin_dependencies'));
}
public function testOrdinalize()
{
$this->assertSame('1st', $this->inflector->ordinalize(1));
$this->assertSame('2nd', $this->inflector->ordinalize(2));
$this->assertSame('3rd', $this->inflector->ordinalize(3));
$this->assertSame('4th', $this->inflector->ordinalize(4));
$this->assertSame('5th', $this->inflector->ordinalize(5));
$this->assertSame('16th', $this->inflector->ordinalize(16));
$this->assertSame('51st', $this->inflector->ordinalize(51));
$this->assertSame('111th', $this->inflector->ordinalize(111));
$this->assertSame('123rd', $this->inflector->ordinalize(123));
}
public function testMonthize()
{
$this->assertSame(0, $this->inflector->monthize(10));
$this->assertSame(1, $this->inflector->monthize(33));
$this->assertSame(1, $this->inflector->monthize(41));
$this->assertSame(11, $this->inflector->monthize(364));
}
}

View File

@@ -0,0 +1,24 @@
<?php
use Grav\Common\Language\LanguageCodes;
/**
* Class ParsedownTest
*/
class LanguageCodesTest extends \Codeception\TestCase\Test
{
public function testRtl()
{
$this->assertSame('ltr',
LanguageCodes::getOrientation('en'));
$this->assertSame('rtl',
LanguageCodes::getOrientation('ar'));
$this->assertSame('rtl',
LanguageCodes::getOrientation('he'));
$this->assertTrue(LanguageCodes::isRtl('ar'));
$this->assertFalse(LanguageCodes::isRtl('fr'));
}
}

View File

@@ -0,0 +1,744 @@
<?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;
protected function _before()
{
$grav = Fixtures::get('grav');
$this->grav = $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);
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
$this->pages->init();
$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->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 alt="" 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 alt="" src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><img alt="" 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 alt="" src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
$this->assertRegexp('|<p><img alt="" 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->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
$this->parsedown->text('![](/home-missing-image.jpg)'));
$this->assertSame('<p><img src="https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg" alt="" /></p>',
$this->parsedown->text('![](https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg)'));
}
public function testImagesSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
$this->assertRegexp('|<p><img alt="" src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](/home-cache-image.jpg?cache)'));
$this->assertSame('<p><img alt="" 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 alt="" 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 alt="" 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 alt="" src="http:\/\/testing.dev\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img alt="" 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 alt="" 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 alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img alt="" 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 testImagesAttributes()
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><img title="My Title" alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg "My Title")'));
$this->assertSame('<p><img alt="" class="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg?classes=foo)'));
$this->assertSame('<p><img alt="" class="foo bar" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg?classes=foo,bar)'));
$this->assertSame('<p><img alt="" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![](sample-image.jpg?id=foo)'));
$this->assertSame('<p><img alt="Alt Text" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![Alt Text](sample-image.jpg?id=foo)'));
$this->assertSame('<p><img alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo)'));
$this->assertSame('<p><img title="My Title" alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
$this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo "My Title")'));
}
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 alt="" 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 alt="" src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](home-cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img alt="" 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 alt="" 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 alt="" 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 alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
$this->parsedown->text('![](cache-image.jpg?cache)'));
$this->assertRegexp('|<p><img alt="" 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="#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="#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="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$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/#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)'));
$this->assertSame('<p><a href="https://github.com/getgrav/grav/issues/new?title=%5Badd-resource%5D%20New%20Plugin%2FTheme&body=Hello%20%2A%2AThere%2A%2A">complex url</a></p>',
$this->parsedown->text('[complex url](https://github.com/getgrav/grav/issues/new?title=[add-resource]%20New%20Plugin/Theme&body=Hello%20**There**)'));
}
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="#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="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$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/#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="#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="#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="#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)'));
$this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
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)'));
$this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
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)'));
$this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
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="#something" class="button">Anchor Class</a></p>',
$this->parsedown->text('[Anchor Class](?classes=button#something)'));
$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);
}
}

View File

@@ -0,0 +1,281 @@
<?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;
protected function _before()
{
$grav = Fixtures::get('grav');
$this->grav = $grav();
$this->pages = $this->grav['pages'];
$this->grav['config']->set('system.home.alias', '/home');
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$locator->addPath('page', '', 'tests/fake/simple-site/user/pages', false);
$this->pages->init();
}
public function testBase()
{
$this->assertSame('', $this->pages->base());
$this->pages->base('/test');
$this->assertSame('/test', $this->pages->base());
$this->pages->base('');
$this->assertNull($this->pages->base());
}
public function testLastModified()
{
$this->assertNull($this->pages->lastModified());
$this->pages->lastModified('test');
$this->assertSame('test', $this->pages->lastModified());
}
public function testInstances()
{
$this->assertInternalType('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->assertInternalType('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->assertContains('/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->assertInternalType('array', $subPagesSorted);
$this->assertCount(2, $subPagesSorted);
$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->assertContains($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted));
$this->assertContains($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->assertInternalType('array', $subPagesSorted);
$this->assertCount(2, $subPagesSorted);
$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->assertContains($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted));
$this->assertContains($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->assertInternalType('array', $subPagesSorted);
$this->assertCount(2, $subPagesSorted);
$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->assertContains($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted));
$this->assertContains($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->assertInternalType('array', $subPagesSorted);
$this->assertCount(2, $subPagesSorted);
$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->assertContains($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted));
$this->assertContains($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->assertInternalType('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->assertNotInternalType('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->assertInternalType('object', $this->pages->all());
$this->assertInternalType('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->assertInternalType('array', $list);
$this->assertSame('&mdash;-&rtrif; Home', $list['/']);
$this->assertSame('&mdash;-&rtrif; 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()
{
}
}

View File

@@ -0,0 +1,208 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Twig\TwigExtension;
/**
* Class TwigExtensionTest
*/
class TwigExtensionTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var TwigExtension $twig_ext */
protected $twig_ext;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->twig_ext = new TwigExtension();
}
public function testInflectorFilter()
{
$this->assertSame('people', $this->twig_ext->inflectorFilter('plural', 'person'));
$this->assertSame('shoe', $this->twig_ext->inflectorFilter('singular', 'shoes'));
$this->assertSame('Welcome Page', $this->twig_ext->inflectorFilter('title', 'welcome page'));
$this->assertSame('SendEmail', $this->twig_ext->inflectorFilter('camel', 'send_email'));
$this->assertSame('camel_cased', $this->twig_ext->inflectorFilter('underscor', 'CamelCased'));
$this->assertSame('something-text', $this->twig_ext->inflectorFilter('hyphen', 'Something Text'));
$this->assertSame('Something text to read', $this->twig_ext->inflectorFilter('human', 'something_text_to_read'));
$this->assertSame(5, $this->twig_ext->inflectorFilter('month', 175));
$this->assertSame('10th', $this->twig_ext->inflectorFilter('ordinal', 10));
}
public function testMd5Filter()
{
$this->assertSame(md5('grav'), $this->twig_ext->md5Filter('grav'));
$this->assertSame(md5('devs@getgrav.org'), $this->twig_ext->md5Filter('devs@getgrav.org'));
}
public function testKsortFilter()
{
$object = array("name"=>"Bob","age"=>8,"colour"=>"red");
$this->assertSame(array("age"=>8,"colour"=>"red","name"=>"Bob"), $this->twig_ext->ksortFilter($object));
}
public function testContainsFilter()
{
$this->assertTrue($this->twig_ext->containsFilter('grav','grav'));
$this->assertTrue($this->twig_ext->containsFilter('So, I found this new cms, called grav, and it\'s pretty awesome guys','grav'));
}
public function testNicetimeFilter()
{
$now = time();
$threeMinutes = time() - (60*3);
$threeHours = time() - (60*60*3);
$threeDays = time() - (60*60*24*3);
$threeMonths = time() - (60*60*24*30*3);
$threeYears = time() - (60*60*24*365*3);
$measures = ['minutes','hours','days','months','years'];
$this->assertSame('No date provided', $this->twig_ext->nicetimeFunc(null));
for ($i=0; $i<count($measures); $i++) {
$time = 'three' . ucfirst($measures[$i]);
$this->assertSame('3 ' . $measures[$i] . ' ago', $this->twig_ext->nicetimeFunc($$time));
}
}
public function testRandomizeFilter()
{
$array = [1,2,3,4,5];
$this->assertContains(2, $this->twig_ext->randomizeFilter($array));
$this->assertSame($array, $this->twig_ext->randomizeFilter($array, 5));
$this->assertSame($array[0], $this->twig_ext->randomizeFilter($array, 1)[0]);
$this->assertSame($array[3], $this->twig_ext->randomizeFilter($array, 4)[3]);
$this->assertSame($array[1], $this->twig_ext->randomizeFilter($array, 4)[1]);
}
public function testModulusFilter()
{
$this->assertSame(3, $this->twig_ext->modulusFilter(3,4));
$this->assertSame(1, $this->twig_ext->modulusFilter(11,2));
$this->assertSame(0, $this->twig_ext->modulusFilter(10,2));
$this->assertSame(2, $this->twig_ext->modulusFilter(10,4));
}
public function testAbsoluteUrlFilter()
{
}
public function testMarkdownFilter()
{
}
public function testStartsWithFilter()
{
}
public function testEndsWithFilter()
{
}
public function testDefinedDefaultFilter()
{
}
public function testRtrimFilter()
{
}
public function testLtrimFilter()
{
}
public function testRepeatFunc()
{
}
public function testRegexReplace()
{
}
public function testUrlFunc()
{
}
public function testEvaluateFunc()
{
}
public function testDump()
{
}
public function testGistFunc()
{
}
public function testRandomStringFunc()
{
}
public function testPadFilter()
{
}
public function testArrayFunc()
{
$this->assertSame('this is my text',
$this->twig_ext->regexReplace('<p>this is my text</p>', '(<\/?p>)', ''));
$this->assertSame('<i>this is my text</i>',
$this->twig_ext->regexReplace('<p>this is my text</p>', ['(<p>)','(<\/p>)'], ['<i>','</i>']));
}
public function testArrayKeyValue()
{
$this->assertSame(['meat' => 'steak'],
$this->twig_ext->arrayKeyValueFunc('meat', 'steak'));
$this->assertSame(['fruit' => 'apple', 'meat' => 'steak'],
$this->twig_ext->arrayKeyValueFunc('meat', 'steak', ['fruit' => 'apple']));
}
public function stringFunc()
{
}
public function testRangeFunc()
{
$hundred = [];
for($i = 0; $i <= 100; $i++) { $hundred[] = $i; }
$this->assertSame([0], $this->twig_ext->rangeFunc(0, 0));
$this->assertSame([0, 1, 2], $this->twig_ext->rangeFunc(0, 2));
$this->assertSame([0, 5, 10, 15], $this->twig_ext->rangeFunc(0, 16, 5));
// default (min 0, max 100, step 1)
$this->assertSame($hundred, $this->twig_ext->rangeFunc());
// 95 items, starting from 5, (min 5, max 100, step 1)
$this->assertSame(array_slice($hundred, 5), $this->twig_ext->rangeFunc(5));
// reversed range
$this->assertSame(array_reverse($hundred), $this->twig_ext->rangeFunc(100, 0));
$this->assertSame([4, 2, 0], $this->twig_ext->rangeFunc(4, 0, 2));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,333 @@
<?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()
{
$grav = Fixtures::get('grav');
$this->grav = $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('en', Utils::substrToString('english', 'glish'));
$this->assertEquals('english', Utils::substrToString('english', 'test'));
$this->assertNotEquals('en', Utils::substrToString('english', 'lish'));
}
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->assertInternalType('array', $dateFormats);
$this->assertContainsOnly('string', $dateFormats);
$default_format = $this->grav['config']->get('system.pages.dateformat.default');
if ($default_format !== null) {
$this->assertArrayHasKey($default_format, $dateFormats);
}
}
public function testTruncate()
{
$this->assertEquals('engli' . '&hellip;', Utils::truncate('english', 5));
$this->assertEquals('english', Utils::truncate('english'));
$this->assertEquals('This is a string to truncate', Utils::truncate('This is a string to truncate'));
$this->assertEquals('Th' . '&hellip;', Utils::truncate('This is a string to truncate', 2));
$this->assertEquals('engli' . '...', Utils::truncate('english', 5, true, " ", "..."));
$this->assertEquals('english', Utils::truncate('english'));
$this->assertEquals('This is a string to truncate', Utils::truncate('This is a string to truncate'));
$this->assertEquals('This' . '&hellip;', Utils::truncate('This is a string to truncate', 3, true));
$this->assertEquals('<input' . '&hellip;', Utils::truncate('<input type="file" id="file" multiple />', 6, true));
}
public function testSafeTruncate()
{
$this->assertEquals('This' . '&hellip;', Utils::safeTruncate('This is a string to truncate', 1));
$this->assertEquals('This' . '&hellip;', Utils::safeTruncate('This is a string to truncate', 4));
$this->assertEquals('This is' . '&hellip;', Utils::safeTruncate('This is a string to truncate', 5));
}
public function testTruncateHtml()
{
$this->assertEquals('<p>T...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 1));
$this->assertEquals('<p>This...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 4));
$this->assertEquals('<p>This is a...</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 10));
$this->assertEquals('<p>This is a string to truncate</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 100));
$this->assertEquals('<input type="file" id="file" multiple />', Utils::truncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<ol><li>item 1 <i>so...</i></li></ol>', Utils::truncateHtml('<ol><li>item 1 <i>something</i></li><li>item 2 <strong>bold</strong></li></ol>', 10));
$this->assertEquals("<p>This is a string.</p>\n<p>It splits two lines.</p>", Utils::truncateHtml("<p>This is a string.</p>\n<p>It splits two lines.</p>", 100));
}
public function testSafeTruncateHtml()
{
$this->assertEquals('<p>This...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 1));
$this->assertEquals('<p>This is...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 2));
$this->assertEquals('<p>This is a string to...</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 5));
$this->assertEquals('<p>This is a string to truncate</p>', Utils::safeTruncateHtml('<p>This is a string to truncate</p>', 20));
$this->assertEquals('<input type="file" id="file" multiple />', Utils::safeTruncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<ol><li>item 1 <i>something</i></li><li>item 2...</li></ol>', Utils::safeTruncateHtml('<ol><li>item 1 <i>something</i></li><li>item 2 <strong>bold</strong></li></ol>', 5));
}
public function testGenerateRandomString()
{
$this->assertNotEquals(Utils::generateRandomString(), Utils::generateRandomString());
$this->assertNotEquals(Utils::generateRandomString(20), Utils::generateRandomString(20));
}
public function download()
{
}
public function testGetMimeByExtension()
{
$this->assertEquals('application/octet-stream', Utils::getMimeByExtension(''));
$this->assertEquals('text/html', Utils::getMimeByExtension('html'));
$this->assertEquals('application/json', Utils::getMimeByExtension('json'));
$this->assertEquals('application/atom+xml', Utils::getMimeByExtension('atom'));
$this->assertEquals('application/rss+xml', Utils::getMimeByExtension('rss'));
$this->assertEquals('image/jpeg', Utils::getMimeByExtension('jpg'));
$this->assertEquals('image/png', Utils::getMimeByExtension('png'));
$this->assertEquals('text/plain', Utils::getMimeByExtension('txt'));
$this->assertEquals('application/msword', Utils::getMimeByExtension('doc'));
$this->assertEquals('application/octet-stream', Utils::getMimeByExtension('foo'));
$this->assertEquals('foo/bar', Utils::getMimeByExtension('foo', 'foo/bar'));
$this->assertEquals('text/html', Utils::getMimeByExtension('foo', 'text/html'));
}
public function testGetExtensionByMime()
{
$this->assertEquals('html', Utils::getExtensionByMime('*/*'));
$this->assertEquals('html', Utils::getExtensionByMime('text/*'));
$this->assertEquals('html', Utils::getExtensionByMime('text/html'));
$this->assertEquals('json', Utils::getExtensionByMime('application/json'));
$this->assertEquals('atom', Utils::getExtensionByMime('application/atom+xml'));
$this->assertEquals('rss', Utils::getExtensionByMime('application/rss+xml'));
$this->assertEquals('jpg', Utils::getExtensionByMime('image/jpeg'));
$this->assertEquals('png', Utils::getExtensionByMime('image/png'));
$this->assertEquals('txt', Utils::getExtensionByMime('text/plain'));
$this->assertEquals('doc', Utils::getExtensionByMime('application/msword'));
$this->assertEquals('html', Utils::getExtensionByMime('foo/bar'));
$this->assertEquals('baz', Utils::getExtensionByMime('foo/bar', 'baz'));
}
public function testNormalizePath()
{
$this->assertEquals('/test', Utils::normalizePath('/test'));
$this->assertEquals('test', Utils::normalizePath('test'));
$this->assertEquals('test', Utils::normalizePath('../test'));
$this->assertEquals('/test', Utils::normalizePath('/../test'));
$this->assertEquals('/test2', Utils::normalizePath('/test/../test2'));
$this->assertEquals('/test/test2', Utils::normalizePath('/test/./test2'));
}
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->assertInternalType('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->assertArrayNotHasKey('test', $array);
$this->assertArrayHasKey('test2', $array);
$this->assertEquals('test2', $array['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('test2Value', Utils::resolve($array, 'test.test2'));
}
public function testGetDotNotation()
{
$array = [
'test' => [
'test2' => 'test2Value',
'test3' => [
'test4' => 'test4Value'
]
]
];
$this->assertEquals('test2Value', Utils::getDotNotation($array, 'test.test2'));
$this->assertEquals('test4Value', Utils::getDotNotation($array, 'test.test3.test4'));
$this->assertEquals('defaultValue', Utils::getDotNotation($array, 'test.non_existent', 'defaultValue'));
}
public function testSetDotNotation()
{
$array = [
'test' => [
'test2' => 'test2Value',
'test3' => [
'test4' => 'test4Value'
]
]
];
$new = [
'test1' => 'test1Value'
];
Utils::setDotNotation($array, 'test.test3.test4' , $new);
$this->assertEquals('test1Value', $array['test']['test3']['test4']['test1']);
}
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->assertInternalType('string', Utils::getNonce('test-action'));
$this->assertInternalType('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'));
}
}

View File

@@ -0,0 +1,28 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
/**
* Class InstallCommandTest
*/
class InstallCommandTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var InstallCommand */
protected $installCommand;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->installCommand = new InstallCommand();
}
protected function _after()
{
}
}

View File

@@ -0,0 +1,4 @@
<?php
// Here you can initialize variables that will be available to your tests
define('GRAV_CLI', true);