Merge branch 'rc120-release' into 'master'
Release 1.2.0-RC1 See merge request fuzeworks/Layout!1
This commit is contained in:
commit
c417068e95
|
@ -1,4 +1,4 @@
|
|||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.gitlab-ci.yml export-ignore
|
||||
tests/ export-ignore
|
||||
test/ export-ignore
|
|
@ -0,0 +1,82 @@
|
|||
before_script:
|
||||
# Install dependencies
|
||||
- set -xe
|
||||
- apt-get update -yqq
|
||||
- apt-get install git zip unzip -yqq
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
build:composer:
|
||||
image: php:7.2
|
||||
stage: build
|
||||
script:
|
||||
- curl -sS https://getcomposer.org/installer | php
|
||||
- php composer.phar install
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:7.1:
|
||||
stage: test
|
||||
image: php:7.1
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor
|
||||
|
||||
test:7.2:
|
||||
stage: test
|
||||
image: php:7.2
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:7.3:
|
||||
stage: test
|
||||
image: php:7.3
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:coverage:
|
||||
stage: test
|
||||
image: php:7.2
|
||||
script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
release:
|
||||
stage: deploy
|
||||
image: php:7.2
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
artifacts:
|
||||
name: "${CI_BUILD_NAME}_${CI_BUILD_REF_NAME}"
|
||||
paths:
|
||||
- build/
|
||||
expire_in: 3 weeks
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
|
@ -0,0 +1,12 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
|
||||
script:
|
||||
- php vendor/bin/phpunit -v -c test/phpunit.xml --coverage-text
|
||||
|
||||
before_script:
|
||||
- composer install
|
|
@ -13,16 +13,15 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
"php": ">=7.1.0",
|
||||
"fuzeworks/core": "1.2.0-RC2"
|
||||
},
|
||||
"require-dev": {
|
||||
"fuzeworks/core": "dev-development",
|
||||
"ext-json": "*",
|
||||
"smarty/smarty": "~3.1",
|
||||
"latte/latte": "~2.4",
|
||||
"phpunit/phpunit": "^7",
|
||||
"mikey179/vfsStream": "1.6.5",
|
||||
"tracy/tracy": "2.4.*"
|
||||
"mikey179/vfsStream": "1.6.5"
|
||||
},
|
||||
"suggest": {
|
||||
"smarty/smarty": "Template Engine that is natively supported by FuzeWorks.",
|
||||
|
|
|
@ -59,14 +59,14 @@ class LayoutDisplayEvent extends Event
|
|||
public $file;
|
||||
|
||||
/**
|
||||
* @var string directory. Directory that the layout file resides in.
|
||||
* @var array directories. Directories that the layout file might resides in.
|
||||
*/
|
||||
public $directory;
|
||||
public $directories;
|
||||
|
||||
public function init(string $contents, string $file, string $directory)
|
||||
public function init(string $contents, string $file, array $directories)
|
||||
{
|
||||
$this->contents = $contents;
|
||||
$this->file = $file;
|
||||
$this->directory = $directory;
|
||||
$this->directories = $directories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,4 +83,15 @@ class LayoutLoadEvent extends Event
|
|||
$this->engine = $engine;
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a variable for the template.
|
||||
*
|
||||
* @param string $key Key of the variable
|
||||
* @param mixed $value Value of the variable
|
||||
*/
|
||||
public function assign($key, $value)
|
||||
{
|
||||
$this->assigned_variables[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ use FuzeWorks\Exception\EventException;
|
|||
*/
|
||||
class Layout
|
||||
{
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
|
@ -57,18 +58,18 @@ class Layout
|
|||
protected $factory;
|
||||
|
||||
/**
|
||||
* The file to be loaded by the layout manager.
|
||||
* The file which the current template is loaded from
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $file = null;
|
||||
|
||||
/**
|
||||
* The directory of the file to be loaded by the layout manager.
|
||||
* The directory where the current template is loaded from
|
||||
*
|
||||
* @var string
|
||||
* @var null|string
|
||||
*/
|
||||
public $directory;
|
||||
public $directory = null;
|
||||
|
||||
/**
|
||||
* All assigned currently assigned to the template.
|
||||
|
@ -101,7 +102,7 @@ class Layout
|
|||
/**
|
||||
* The currently selected template engine.
|
||||
*
|
||||
* @var string name of engine
|
||||
* @var TemplateEngine
|
||||
*/
|
||||
protected $current_engine;
|
||||
|
||||
|
@ -111,7 +112,6 @@ class Layout
|
|||
public function init()
|
||||
{
|
||||
$this->factory = Factory::getInstance();
|
||||
$this->directory = Core::$appDirs[0] . DS .'Layout';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,18 +123,17 @@ class Layout
|
|||
* Remember that doing so will result in a LayoutException when multiple compatible files are found.
|
||||
*
|
||||
* @param string $file File to load
|
||||
* @param string $directory Directory to load it from
|
||||
* @param array $directories Directories to load it from, uses componentPaths if none provided
|
||||
*
|
||||
* @return mixed
|
||||
* @throws LayoutException On error
|
||||
* @throws EventException
|
||||
* @throws Exception\ConfigException
|
||||
*/
|
||||
public function display($file, $directory = null)
|
||||
public function display(string $file, array $directories = []): bool
|
||||
{
|
||||
$directory = (is_null($directory) ? $this->directory : $directory);
|
||||
$contents = $this->get($file, $directory);
|
||||
|
||||
$event = Events::fireEvent('layoutDisplayEvent', $contents, $file, $directory);
|
||||
$contents = $this->get($file, $directories);
|
||||
$event = Events::fireEvent('layoutDisplayEvent', $contents, $file, $directories);
|
||||
if (!$event->isCancelled())
|
||||
echo $event->contents;
|
||||
|
||||
|
@ -150,32 +149,29 @@ class Layout
|
|||
* Remember that doing so will result in a LayoutException when multiple compatible files are found.
|
||||
*
|
||||
* @param string $file File to load
|
||||
* @param string $directory Directory to load it from
|
||||
* @param array $directories Directory to load it from
|
||||
*
|
||||
* @return string The output of the template
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public function get($file, $directory = null): string
|
||||
public function get(string $file, array $directories = []): string
|
||||
{
|
||||
$directory = (is_null($directory) ? $this->directory : $directory);
|
||||
Logger::newLevel("Loading template file '".$file."' in '".$directory."'");
|
||||
Logger::newLevel("Loading template file '".$file."'");
|
||||
|
||||
// Determine what directories should be checked
|
||||
$directories = (empty($directories) ? $this->componentPaths : [3 => $directories]);
|
||||
|
||||
// First load the template engines
|
||||
$this->loadTemplateEngines();
|
||||
|
||||
// First retrieve the filePath
|
||||
if (is_null($this->current_engine)) {
|
||||
$this->setFileFromString($file, $directory, array_keys($this->file_extensions));
|
||||
$this->setFileFromString($file, $directories, array_keys($this->file_extensions));
|
||||
} else {
|
||||
$this->setFileFromString($file, $directory, $this->current_engine->getFileExtensions());
|
||||
$this->setFileFromString($file, $directories, $this->current_engine->getFileExtensions());
|
||||
}
|
||||
|
||||
// Then assign some basic variables for the template
|
||||
$main_config = $this->factory->config->get('main');
|
||||
$this->assigned_variables['wwwDir'] = $main_config->base_url;
|
||||
$this->assigned_variables['siteURL'] = $main_config->base_url;
|
||||
$this->assigned_variables['serverName'] = $main_config->server_name;
|
||||
$this->assigned_variables['adminMail'] = $main_config->administrator_mail;
|
||||
// @TODO: Implement csrfTokenName and csrfHash from security under layoutLoadEvent
|
||||
|
||||
// Select an engine if one is not already selected
|
||||
|
@ -196,11 +192,10 @@ class Layout
|
|||
}
|
||||
|
||||
// The event has been cancelled
|
||||
if ($event->isCancelled()) {
|
||||
if ($event->isCancelled())
|
||||
return 'cancelled';
|
||||
}
|
||||
|
||||
// And refetch the data from the event
|
||||
// And re-fetch the data from the event
|
||||
$this->current_engine = $event->engine;
|
||||
$this->assigned_variables = $event->assigned_variables;
|
||||
|
||||
|
@ -217,16 +212,15 @@ class Layout
|
|||
/**
|
||||
* Retrieve a Template Engine from a File Extension.
|
||||
*
|
||||
* @param string $extension File extention to look for
|
||||
* @param string $extension File extension to look for
|
||||
*
|
||||
* @return TemplateEngine
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public function getEngineFromExtension($extension): TemplateEngine
|
||||
{
|
||||
if (isset($this->file_extensions[strtolower($extension)])) {
|
||||
if (isset($this->file_extensions[strtolower($extension)]))
|
||||
return $this->engines[ $this->file_extensions[strtolower($extension)]];
|
||||
}
|
||||
|
||||
throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1);
|
||||
}
|
||||
|
@ -249,28 +243,22 @@ class Layout
|
|||
* It will detect whether the file exists and choose a file according to the provided extensions
|
||||
*
|
||||
* @param string $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param string $directory The directory to search in for the template
|
||||
* @param array $directories The directories to search in for the template
|
||||
* @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
|
||||
*
|
||||
* @return string Filepath of the template
|
||||
* @return array File and directory
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public function getFileFromString($string, $directory, $extensions = array()): string
|
||||
public function getFileFromString(string $string, array $directories, array $extensions = []): array
|
||||
{
|
||||
$directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : $this->directory).DS);
|
||||
|
||||
// @TODO Malformed strings pass. Write better function
|
||||
if (strpbrk($directory, "\\/?%*:|\"<>") === TRUE || strpbrk($string, "\\/?%*:|\"<>") === TRUE)
|
||||
if (strpbrk($string, "\\/?%*:|\"<>") === TRUE)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new LayoutException('Could not get file. Invalid file string', 1);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (!file_exists($directory)) {
|
||||
throw new LayoutException('Could not get file. Directory does not exist', 1);
|
||||
}
|
||||
|
||||
// Set the file name and location
|
||||
$layoutSelector = explode('/', $string);
|
||||
if (count($layoutSelector) == 1) {
|
||||
|
@ -291,11 +279,19 @@ class Layout
|
|||
$layoutSelector = implode(DS, $layoutSelector);
|
||||
}
|
||||
|
||||
// Iterate over componentPaths
|
||||
for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++)
|
||||
{
|
||||
if (!isset($directories[$i]))
|
||||
continue;
|
||||
|
||||
foreach ($directories[$i] as $directory)
|
||||
{
|
||||
// Then try and select a file
|
||||
$fileSelected = false;
|
||||
$selectedFile = null;
|
||||
foreach ($extensions as $extension) {
|
||||
$file = $directory.$layoutSelector.'.'.strtolower($extension);
|
||||
$file = $directory.DS.$layoutSelector.'.'.strtolower($extension);
|
||||
$file = preg_replace('#/+#', '/', $file);
|
||||
if (file_exists($file) && !$fileSelected) {
|
||||
$selectedFile = $file;
|
||||
|
@ -306,12 +302,12 @@ class Layout
|
|||
}
|
||||
}
|
||||
|
||||
// And choose what to output
|
||||
if (!$fileSelected) {
|
||||
throw new LayoutException('Could not select template. No matching file found.');
|
||||
if ($fileSelected)
|
||||
return ['file' => $selectedFile, 'directory' => $directory];
|
||||
}
|
||||
}
|
||||
|
||||
return $selectedFile;
|
||||
throw new LayoutException('Could not select template. No matching file found.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -321,15 +317,16 @@ class Layout
|
|||
* It will detect whether the file exists and choose a file according to the provided extensions
|
||||
*
|
||||
* @param string $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param string $directory The directory to search in for the template
|
||||
* @param array $directories The directory to search in for the template
|
||||
* @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
|
||||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public function setFileFromString($string, $directory, $extensions = array())
|
||||
public function setFileFromString($string, array $directories, $extensions = array())
|
||||
{
|
||||
$this->file = $this->getFileFromString($string, $directory, $extensions);
|
||||
$this->directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : $this->directory).DS);
|
||||
$arr = $this->getFileFromString($string, $directories, $extensions);
|
||||
$this->file = $arr['file'];
|
||||
$this->directory = $arr['directory'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -401,9 +398,8 @@ class Layout
|
|||
public function getTitle()
|
||||
{
|
||||
if (!isset($this->assigned_variables['title']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->assigned_variables['title'];
|
||||
}
|
||||
|
||||
|
@ -454,7 +450,7 @@ class Layout
|
|||
* @return bool true on success
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public function registerEngine(TemplateEngine $engineClass, string $engineName, array $engineFileExtensions = array()): bool
|
||||
public function registerEngine(TemplateEngine $engineClass, string $engineName, array $engineFileExtensions = []): bool
|
||||
{
|
||||
// First check if the engine already exists
|
||||
if (isset($this->engines[$engineName]))
|
||||
|
@ -522,9 +518,8 @@ class Layout
|
|||
*/
|
||||
public function reset()
|
||||
{
|
||||
if (!is_null($this->current_engine)) {
|
||||
if (!is_null($this->current_engine))
|
||||
$this->current_engine->reset();
|
||||
}
|
||||
|
||||
// Unload the engines
|
||||
$this->engines = array();
|
||||
|
@ -533,7 +528,6 @@ class Layout
|
|||
|
||||
$this->current_engine = null;
|
||||
$this->assigned_variables = array();
|
||||
$this->directory = Core::$appDirs[0]. DS . 'Layout';
|
||||
Logger::log('Reset the layout manager to its default state');
|
||||
}
|
||||
}
|
|
@ -47,6 +47,11 @@ namespace FuzeWorks;
|
|||
class LayoutComponent implements iComponent
|
||||
{
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'LayoutComponent';
|
||||
}
|
||||
|
||||
public function getClasses(): array
|
||||
{
|
||||
return [
|
||||
|
@ -54,4 +59,12 @@ class LayoutComponent implements iComponent
|
|||
'languages' => '\FuzeWorks\Languages'
|
||||
];
|
||||
}
|
||||
|
||||
public function onAddComponent(Configurator $configurator)
|
||||
{
|
||||
}
|
||||
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -46,7 +46,6 @@ $container = require('bootstrap.php');
|
|||
require_once 'layout/LayoutTestAbstract.php';
|
||||
|
||||
// Reset error and exception handlers
|
||||
ob_start();
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
|
||||
|
|
|
@ -34,14 +34,11 @@
|
|||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
require_once(dirname(__DIR__) . '/vendor/autoload.php');
|
||||
|
||||
$configurator = new FuzeWorks\Configurator();
|
||||
|
||||
// Implement all directories
|
||||
$configurator->addDirectory(dirname(__FILE__) . '/application');
|
||||
$configurator->setTempDirectory(dirname(__FILE__) . '/temp');
|
||||
$configurator->setLogDirectory(dirname(__FILE__) . '/temp');
|
||||
|
||||
|
@ -54,7 +51,6 @@ $configurator->addComponent(new \FuzeWorks\LayoutComponent());
|
|||
|
||||
// Create container
|
||||
$container = $configurator->createContainer();
|
||||
$container->init();
|
||||
|
||||
// And return the result
|
||||
return $container;
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\Layout;
|
||||
use FuzeWorks\Events;
|
||||
use FuzeWorks\EventPriority;
|
||||
use FuzeWorks\Priority;
|
||||
|
||||
/**
|
||||
* Class LayoutTest.
|
||||
|
@ -77,13 +77,14 @@ class LayoutTest extends LayoutTestAbstract
|
|||
// Prepare container
|
||||
$configurator = new \FuzeWorks\Configurator();
|
||||
$configurator->addComponent($component);
|
||||
$configurator->addDirectory(dirname(__DIR__) . '/application');
|
||||
$configurator->setTempDirectory(dirname(__DIR__) . '/temp');
|
||||
$configurator->setLogDirectory(dirname(__DIR__) . '/temp');
|
||||
|
||||
|
||||
// Create container
|
||||
$container = $configurator->createContainer();
|
||||
|
||||
// Init container
|
||||
$container = $container->init();
|
||||
// Init container;
|
||||
$this->assertTrue(property_exists($container, 'layouts'));
|
||||
$this->assertInstanceOf('FuzeWorks\Layout', $container->layouts);
|
||||
}
|
||||
|
@ -103,8 +104,8 @@ class LayoutTest extends LayoutTestAbstract
|
|||
|
||||
// Directory test
|
||||
$directory = 'test'.DS.'templates'.DS.'testFileAndDirectory';
|
||||
$this->layout->setDirectory($directory);
|
||||
$this->assertEquals($directory, $this->layout->getDirectory());
|
||||
$this->layout->addComponentPath($directory);
|
||||
$this->assertEquals([$directory], $this->layout->getComponentPaths());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,20 +129,20 @@ class LayoutTest extends LayoutTestAbstract
|
|||
// Extensions to be used in this test
|
||||
$extensions = array('php', 'json');
|
||||
|
||||
// Prepare variables
|
||||
$directories = [3 => ['test'.DS.'templates'.DS.'testGetFilePath']];
|
||||
|
||||
// Basic path
|
||||
$this->layout->setFileFromString('test', 'test'.DS.'templates'.DS.'testGetFilePath', $extensions);
|
||||
$this->layout->setFileFromString('test', $directories, $extensions);
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS.'layout.test.php', $this->layout->getFile());
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS, $this->layout->getDirectory());
|
||||
|
||||
// Alternate file extension
|
||||
$this->layout->setFileFromString('JSON', 'test'.DS.'templates'.DS.'testGetFilePath', $extensions);
|
||||
$this->layout->setFileFromString('JSON', $directories, $extensions);
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS.'layout.JSON.json', $this->layout->getFile());
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS, $this->layout->getDirectory());
|
||||
|
||||
// Complex deeper path
|
||||
$this->layout->setFileFromString('Deeper/test', 'test'.DS.'templates'.DS.'testGetFilePath', $extensions);
|
||||
$this->layout->setFileFromString('Deeper/test', $directories, $extensions);
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS.'Deeper'.DS.'layout.test.php', $this->layout->getFile());
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS, $this->layout->getDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +156,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
// Extensions to be used in this test
|
||||
$extensions = array('php', 'json');
|
||||
|
||||
$this->layout->setFileFromString('test?\/<>', 'test|?/*<>', $extensions);
|
||||
$this->layout->setFileFromString('test?\/<>', [3=>['test|?/*<>']], $extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,7 +167,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
public function testMissingDirectory()
|
||||
{
|
||||
// Directory that does not exist
|
||||
$this->layout->setFileFromString('test', 'test'.DS.'templates'.DS.'doesNotExist'.DS, array('php'));
|
||||
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'doesNotExist']], array('php'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +177,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
public function testMissingFile()
|
||||
{
|
||||
$this->layout->setFileFromString('test', 'test'.DS.'templates'.DS.'testMissingFile'.DS, array('php'));
|
||||
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'testMissingFile']], array('php'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +187,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
public function testUnknownFileExtension()
|
||||
{
|
||||
$this->layout->setFileFromString('test', 'test'.DS.'templates'.DS.'testUnknownFileExtension'.DS, array('php'));
|
||||
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'testUnknownFileExtension']], array('php'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,9 +196,9 @@ class LayoutTest extends LayoutTestAbstract
|
|||
public function testLayoutGet()
|
||||
{
|
||||
// Directory of these tests
|
||||
$directory = 'test'.DS.'templates'.DS.'testLayoutGet'.DS;
|
||||
$directories = ['test'.DS.'templates'.DS.'testLayoutGet'];
|
||||
|
||||
$this->assertEquals('Retrieved Data', $this->layout->get('test', $directory));
|
||||
$this->assertEquals('Retrieved Data', $this->layout->get('test', $directories));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,9 +206,9 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
public function testLayoutGetRepeat()
|
||||
{
|
||||
$directory = 'test'.DS.'templates'.DS.'testLayoutGetRepeat'.DS;
|
||||
$this->assertEquals('First Data', $this->layout->get('first', $directory));
|
||||
$this->assertEquals('Second Data', $this->layout->get('second', $directory));
|
||||
$directories = ['test'.DS.'templates'.DS.'testLayoutGetRepeat'];
|
||||
$this->assertEquals('First Data', $this->layout->get('first', $directories));
|
||||
$this->assertEquals('Second Data', $this->layout->get('second', $directories));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,11 +217,11 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
public function testLayoutGetCancelledEvent()
|
||||
{
|
||||
$directory = 'test'.DS.'templates'.DS.'testLayoutGetCancelledEvent';
|
||||
$directories = ['test'.DS.'templates'.DS.'testLayoutGetCancelledEvent'];
|
||||
Events::addListener(function($event){
|
||||
$event->setCancelled(true);
|
||||
}, 'layoutLoadEvent', EventPriority::NORMAL);
|
||||
$this->assertEquals('cancelled', $this->layout->get('test', $directory));
|
||||
}, 'layoutLoadEvent', Priority::NORMAL);
|
||||
$this->assertEquals('cancelled', $this->layout->get('test', $directories));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,11 +231,11 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
public function testLayoutGetEventWrongFile()
|
||||
{
|
||||
$directory = 'test'.DS.'templates'.DS.'testLayoutGetEventWrongFile';
|
||||
$directories = ['test'.DS.'templates'.DS.'testLayoutGetEventWrongFile'];
|
||||
Events::addListener(function($event){
|
||||
$event->file = 'does_not_exist';
|
||||
}, 'layoutLoadEvent', EventPriority::NORMAL);
|
||||
$this->layout->get('test', $directory);
|
||||
}, 'layoutLoadEvent', Priority::NORMAL);
|
||||
$this->layout->get('test', $directories);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,13 +245,13 @@ class LayoutTest extends LayoutTestAbstract
|
|||
public function testLayoutDisplayEventAndDisplay()
|
||||
{
|
||||
// Directory of these tests
|
||||
$directory = 'test'.DS.'templates'.DS.'testLayoutGet'.DS;
|
||||
$directories = ['test'.DS.'templates'.DS.'testLayoutGet'];
|
||||
Events::addListener(function($event){
|
||||
$this->assertEquals('Retrieved Data', $event->contents);
|
||||
}, 'layoutDisplayEvent', EventPriority::NORMAL);
|
||||
}, 'layoutDisplayEvent', Priority::NORMAL);
|
||||
|
||||
ob_start();
|
||||
$this->layout->display('test', $directory);
|
||||
$this->layout->display('test', $directories);
|
||||
$this->assertEquals('Retrieved Data', ob_get_contents());
|
||||
ob_end_clean();
|
||||
}
|
||||
|
@ -262,20 +263,20 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
public function testReset()
|
||||
{
|
||||
$this->layout->setDirectories([3=>['test'.DS.'templates'.DS.'testLayoutGet']]);
|
||||
|
||||
// First the the variables
|
||||
$this->layout->setTitle('Test Title');
|
||||
$this->layout->setDirectory('test'.DS.'templates'.DS.'testLayoutGet');
|
||||
|
||||
// Test if they are actually set
|
||||
$this->assertEquals('Test Title', $this->layout->getTitle());
|
||||
$this->assertEquals('test'.DS.'templates'.DS.'testLayoutGet', $this->layout->getDirectory());
|
||||
$this->assertEquals(['test'.DS.'templates'.DS.'testLayoutGet'], $this->layout->getComponentPaths());
|
||||
|
||||
// Reset the layout system
|
||||
$this->layout->reset();
|
||||
|
||||
// Test for default values
|
||||
$this->assertFalse($this->layout->getTitle());
|
||||
$this->assertTrue(strpos($this->layout->getDirectory(), 'application' . DS . 'Layout') !== false);
|
||||
$this->assertEquals(['test'.DS.'templates'.DS.'testLayoutGet'], $this->layout->getComponentPaths());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -326,7 +327,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
Events::addListener(function($event){
|
||||
$this->assertInstanceOf('\FuzeWorks\Event\NotifierEvent', $event);
|
||||
throw new \FuzeWorks\Exception\EventException('Forcing failure in loadTemplateEngines()');
|
||||
}, 'layoutLoadEngineEvent', EventPriority::NORMAL);
|
||||
}, 'layoutLoadEngineEvent', Priority::NORMAL);
|
||||
|
||||
$this->layout->loadTemplateEngines();
|
||||
}
|
||||
|
@ -350,7 +351,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
$this->layout->registerEngine($mock, 'Custom', array('test'));
|
||||
|
||||
// And run the engine
|
||||
$this->assertEquals('output', $this->layout->get('test', 'test'.DS.'templates'.DS.'testCustomEngine'));
|
||||
$this->assertEquals('output', $this->layout->get('test', ['test'.DS.'templates'.DS.'testCustomEngine']));
|
||||
}
|
||||
|
||||
|
||||
|
@ -442,18 +443,18 @@ class LayoutTest extends LayoutTestAbstract
|
|||
public function testEnginesLoadLayout()
|
||||
{
|
||||
// Directory of these tests
|
||||
$directory = 'test'.DS.'templates'.DS.'testEngines'.DS;
|
||||
$directories = ['test'.DS.'templates'.DS.'testEngines'];
|
||||
|
||||
// First the PHP Engine
|
||||
$this->assertEquals('PHP Template Check', $this->layout->get('php', $directory));
|
||||
$this->assertEquals('PHP Template Check', $this->layout->get('php', $directories));
|
||||
$this->layout->reset();
|
||||
|
||||
// Then the JSON Engine
|
||||
$this->assertEquals('JSON Template Check', json_decode($this->layout->get('json', $directory), true)[0]);
|
||||
$this->assertEquals('JSON Template Check', json_decode($this->layout->get('json', $directories), true)[0]);
|
||||
$this->layout->reset();
|
||||
|
||||
// And the Smarty Engine
|
||||
$this->assertEquals('Smarty Template Check', $this->layout->get('smarty', $directory));
|
||||
$this->assertEquals('Smarty Template Check', $this->layout->get('smarty', $directories));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -462,21 +463,21 @@ class LayoutTest extends LayoutTestAbstract
|
|||
public function testEngineVariables()
|
||||
{
|
||||
// Directory of these tests
|
||||
$directory = 'test'.DS.'templates'.DS.'testEngineVariables'.DS;
|
||||
$directories = ['test'.DS.'templates'.DS.'testEngineVariables'];
|
||||
|
||||
// First the PHP Engine
|
||||
$this->layout->assign('key', 'value');
|
||||
$this->assertEquals('value', $this->layout->get('php', $directory));
|
||||
$this->assertEquals('value', $this->layout->get('php', $directories));
|
||||
$this->layout->reset();
|
||||
|
||||
// Then the JSON Engine
|
||||
$this->layout->assign('key', 'value');
|
||||
$this->assertEquals('value', json_decode($this->layout->get('json', $directory), true)['data']['key']);
|
||||
$this->assertEquals('value', json_decode($this->layout->get('json', $directories), true)['data']['key']);
|
||||
$this->layout->reset();
|
||||
|
||||
// And the Smarty Engine
|
||||
$this->layout->assign('key', 'value');
|
||||
$this->assertEquals('value', $this->layout->get('smarty', $directory));
|
||||
$this->assertEquals('value', $this->layout->get('smarty', $directories));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,5 @@ abstract class LayoutTestAbstract extends TestCase
|
|||
|
||||
// Re-enable events, in case they have been disabled
|
||||
Events::enable();
|
||||
|
||||
// Reset the HTTP status code
|
||||
Core::$http_status_code = 200;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<directory suffix=".php">../</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">../vendor/</directory>
|
||||
<directory suffix=".php">../tests/</directory>
|
||||
<directory suffix=".php">../test/</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
|
Loading…
Reference in New Issue