mediatheque
This commit is contained in:
Executable
+2
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// This is global bootstrap for autoloading
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Helper;
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
class Unit extends \Codeception\Module
|
||||
{
|
||||
|
||||
}
|
||||
+26
@@ -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
|
||||
*/
|
||||
}
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for unit (internal) tests.
|
||||
|
||||
class_name: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- \Helper\Unit
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Grav\Plugin;
|
||||
|
||||
require_once __DIR__ . '/../../cookieconsent.php';
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
use Grav\Common\Assets;
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Twig\Twig;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class CookieconsentPluginTest
|
||||
*/
|
||||
class CookieconsentPluginTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var Grav
|
||||
*/
|
||||
protected $grav;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var Twig
|
||||
*/
|
||||
protected $twig;
|
||||
|
||||
/**
|
||||
* @var \Twig\Environment
|
||||
*/
|
||||
protected $twigEngine;
|
||||
|
||||
/**
|
||||
* @var Assets
|
||||
*/
|
||||
protected $assets;
|
||||
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->grav = Stub::make(Grav::class);
|
||||
$this->config = Stub::make(Config::class);
|
||||
$this->eventDispatcher = Stub::makeEmpty(EventDispatcherInterface::class);
|
||||
$this->twigEngine = Stub::makeEmpty(\Twig\Environment::class);
|
||||
$this->twig = Stub::make(Twig::class);
|
||||
$this->assets = Stub::make(Assets::class);
|
||||
}
|
||||
|
||||
|
||||
public function testGetSubscribedEvents()
|
||||
{
|
||||
$expectedResult = [
|
||||
'onPluginsInitialized' => ['onPluginsInitialized', 0]
|
||||
];
|
||||
|
||||
$actualResult = CookieconsentPlugin::getSubscribedEvents();
|
||||
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
|
||||
public function testOnPluginsInitialized()
|
||||
{
|
||||
$this->grav['events'] = $this->eventDispatcher;
|
||||
|
||||
$plugin = new CookieconsentPlugin('Cookie Consent', $this->grav, $this->config);
|
||||
$plugin->onPluginsInitialized();
|
||||
}
|
||||
|
||||
public function testOnTwigTemplatePaths()
|
||||
{
|
||||
$this->grav['twig'] = $this->twig;
|
||||
|
||||
$plugin = new CookieconsentPlugin('Cookie Consent', $this->grav, $this->config);
|
||||
$plugin->onTwigTemplatePaths();
|
||||
|
||||
$this->assertCount(1, $this->twig->twig_paths);
|
||||
$this->assertContains('/templates', $this->twig->twig_paths[0]);
|
||||
}
|
||||
|
||||
public function testOnTwigSiteVariables()
|
||||
{
|
||||
$this->grav['twig'] = $this->twig;
|
||||
$this->twig->twig = $this->twigEngine;
|
||||
|
||||
$this->config = Stub::make(Config::class,
|
||||
[
|
||||
'get' => function($key) {
|
||||
if ($key == 'plugins.cookieconsent.cdn') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$this->assets = Stub::make(Assets::class,
|
||||
[
|
||||
'addCss' => function($asset) {
|
||||
$this->assertEquals('//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.6/cookieconsent.min.css', $asset);
|
||||
},
|
||||
'addJs' => function($asset) {
|
||||
$this->assertEquals('//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.6/cookieconsent.min.js', $asset);
|
||||
}
|
||||
]
|
||||
);
|
||||
$this->grav['assets'] = $this->assets;
|
||||
|
||||
$plugin = new CookieconsentPlugin('Cookie Consent', $this->grav, $this->config);
|
||||
$plugin->onTwigSiteVariables();
|
||||
}
|
||||
|
||||
public function testOnTwigSiteVariablesWithDisabledCdn()
|
||||
{
|
||||
$this->grav['twig'] = $this->twig;
|
||||
$this->twig->twig = $this->twigEngine;
|
||||
|
||||
$this->config = Stub::make(Config::class,
|
||||
[
|
||||
'get' => function($key) {
|
||||
if ($key == 'plugins.cookieconsent.cdn') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
]
|
||||
);
|
||||
$this->assets = Stub::make(Assets::class,
|
||||
[
|
||||
'addCss' => function($asset) {
|
||||
$this->assertEquals('plugin://cookieconsent/assets/cookieconsent.min.css', $asset);
|
||||
},
|
||||
'addJs' => function($asset) {
|
||||
$this->assertEquals('plugin://cookieconsent/assets/cookieconsent.min.js', $asset);
|
||||
}
|
||||
]
|
||||
);
|
||||
$this->grav['assets'] = $this->assets;
|
||||
|
||||
|
||||
$plugin = new CookieconsentPlugin('Cookie Consent', $this->grav, $this->config);
|
||||
$plugin->onTwigSiteVariables();
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will be available to your tests
|
||||
Reference in New Issue
Block a user