First commit for release 1.2.0-RC1

This commit is contained in:
Abel Hoogeveen 2019-02-17 15:49:35 +01:00
parent 480d0ecd3d
commit 786e4eb9c8
No known key found for this signature in database
GPG Key ID: 96C2234920BF4292
14 changed files with 237 additions and 133 deletions

2
.gitattributes vendored
View File

@ -1,4 +1,4 @@
.gitattributes export-ignore .gitattributes export-ignore
.gitignore export-ignore .gitignore export-ignore
.gitlab-ci.yml export-ignore .gitlab-ci.yml export-ignore
tests/ export-ignore test/ export-ignore

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ composer.phar
.idea/ .idea/
build/ build/
test/temp/ test/temp/
vendor/ vendor/

82
.gitlab-ci.yml Normal file
View File

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

12
.travis.yml Normal file
View File

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

View File

@ -13,16 +13,15 @@
} }
], ],
"require": { "require": {
"php": ">=7.1.0" "php": ">=7.1.0",
"fuzeworks/core": "1.2.0-RC2"
}, },
"require-dev": { "require-dev": {
"fuzeworks/core": "dev-development",
"ext-json": "*", "ext-json": "*",
"smarty/smarty": "~3.1", "smarty/smarty": "~3.1",
"latte/latte": "~2.4", "latte/latte": "~2.4",
"phpunit/phpunit": "^7", "phpunit/phpunit": "^7",
"mikey179/vfsStream": "1.6.5", "mikey179/vfsStream": "1.6.5"
"tracy/tracy": "2.4.*"
}, },
"suggest": { "suggest": {
"smarty/smarty": "Template Engine that is natively supported by FuzeWorks.", "smarty/smarty": "Template Engine that is natively supported by FuzeWorks.",

View File

@ -59,14 +59,14 @@ class LayoutDisplayEvent extends Event
public $file; 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->contents = $contents;
$this->file = $file; $this->file = $file;
$this->directory = $directory; $this->directories = $directories;
} }
} }

View File

@ -83,4 +83,15 @@ class LayoutLoadEvent extends Event
$this->engine = $engine; $this->engine = $engine;
$this->assigned_variables = $assigned_variables; $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;
}
} }

View File

@ -50,6 +50,7 @@ use FuzeWorks\Exception\EventException;
*/ */
class Layout class Layout
{ {
use ComponentPathsTrait;
/** /**
* @var Factory * @var Factory
@ -57,18 +58,18 @@ class Layout
protected $factory; protected $factory;
/** /**
* The file to be loaded by the layout manager. * The file which the current template is loaded from
* *
* @var null|string * @var null|string
*/ */
public $file = null; 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. * All assigned currently assigned to the template.
@ -101,7 +102,7 @@ class Layout
/** /**
* The currently selected template engine. * The currently selected template engine.
* *
* @var string name of engine * @var TemplateEngine
*/ */
protected $current_engine; protected $current_engine;
@ -111,7 +112,6 @@ class Layout
public function init() public function init()
{ {
$this->factory = Factory::getInstance(); $this->factory = Factory::getInstance();
$this->directory = Core::$appDirs[0] . DS .'Layout';
} }
/** /**
@ -122,19 +122,18 @@ class Layout
* You can also provide no particular engine, and the manager will decide what template to load. * You can also provide no particular engine, and the manager will decide what template to load.
* Remember that doing so will result in a LayoutException when multiple compatible files are found. * Remember that doing so will result in a LayoutException when multiple compatible files are found.
* *
* @param string $file File to load * @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 * @return mixed
* @throws LayoutException On error * @throws LayoutException On error
* @throws EventException * @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, $directories);
$contents = $this->get($file, $directory); $event = Events::fireEvent('layoutDisplayEvent', $contents, $file, $directories);
$event = Events::fireEvent('layoutDisplayEvent', $contents, $file, $directory);
if (!$event->isCancelled()) if (!$event->isCancelled())
echo $event->contents; echo $event->contents;
@ -150,32 +149,29 @@ class Layout
* Remember that doing so will result in a LayoutException when multiple compatible files are found. * Remember that doing so will result in a LayoutException when multiple compatible files are found.
* *
* @param string $file File to load * @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 * @return string The output of the template
* @throws LayoutException On error * @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."'");
Logger::newLevel("Loading template file '".$file."' in '".$directory."'");
// Determine what directories should be checked
$directories = (empty($directories) ? $this->componentPaths : [3 => $directories]);
// First load the template engines // First load the template engines
$this->loadTemplateEngines(); $this->loadTemplateEngines();
// First retrieve the filePath // First retrieve the filePath
if (is_null($this->current_engine)) { 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 { } 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 // 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 // @TODO: Implement csrfTokenName and csrfHash from security under layoutLoadEvent
// Select an engine if one is not already selected // Select an engine if one is not already selected
@ -196,11 +192,10 @@ class Layout
} }
// The event has been cancelled // The event has been cancelled
if ($event->isCancelled()) { if ($event->isCancelled())
return 'cancelled'; return 'cancelled';
}
// And refetch the data from the event // And re-fetch the data from the event
$this->current_engine = $event->engine; $this->current_engine = $event->engine;
$this->assigned_variables = $event->assigned_variables; $this->assigned_variables = $event->assigned_variables;
@ -217,16 +212,15 @@ class Layout
/** /**
* Retrieve a Template Engine from a File Extension. * 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 * @return TemplateEngine
* @throws LayoutException * @throws LayoutException
*/ */
public function getEngineFromExtension($extension): TemplateEngine 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)]]; return $this->engines[ $this->file_extensions[strtolower($extension)]];
}
throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1); throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1);
} }
@ -248,29 +242,23 @@ class Layout
* *
* It will detect whether the file exists and choose a file according to the provided extensions * 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 $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. * @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 * @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 // @TODO Malformed strings pass. Write better function
if (strpbrk($directory, "\\/?%*:|\"<>") === TRUE || strpbrk($string, "\\/?%*:|\"<>") === TRUE) if (strpbrk($string, "\\/?%*:|\"<>") === TRUE)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
throw new LayoutException('Could not get file. Invalid file string', 1); throw new LayoutException('Could not get file. Invalid file string', 1);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
if (!file_exists($directory)) {
throw new LayoutException('Could not get file. Directory does not exist', 1);
}
// Set the file name and location // Set the file name and location
$layoutSelector = explode('/', $string); $layoutSelector = explode('/', $string);
if (count($layoutSelector) == 1) { if (count($layoutSelector) == 1) {
@ -291,27 +279,35 @@ class Layout
$layoutSelector = implode(DS, $layoutSelector); $layoutSelector = implode(DS, $layoutSelector);
} }
// Then try and select a file // Iterate over componentPaths
$fileSelected = false; for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++)
$selectedFile = null; {
foreach ($extensions as $extension) { if (!isset($directories[$i]))
$file = $directory.$layoutSelector.'.'.strtolower($extension); continue;
$file = preg_replace('#/+#', '/', $file);
if (file_exists($file) && !$fileSelected) { foreach ($directories[$i] as $directory)
$selectedFile = $file; {
$fileSelected = true; // Then try and select a file
Logger::log("Found matching file: '".$file."'"); $fileSelected = false;
} elseif (file_exists($file) && $fileSelected) { $selectedFile = null;
throw new LayoutException('Could not select template. Multiple valid extensions detected. Can not choose.', 1); foreach ($extensions as $extension) {
$file = $directory.DS.$layoutSelector.'.'.strtolower($extension);
$file = preg_replace('#/+#', '/', $file);
if (file_exists($file) && !$fileSelected) {
$selectedFile = $file;
$fileSelected = true;
Logger::log("Found matching file: '".$file."'");
} elseif (file_exists($file) && $fileSelected) {
throw new LayoutException('Could not select template. Multiple valid extensions detected. Can not choose.', 1);
}
}
if ($fileSelected)
return ['file' => $selectedFile, 'directory' => $directory];
} }
} }
// And choose what to output throw new LayoutException('Could not select template. No matching file found.');
if (!$fileSelected) {
throw new LayoutException('Could not select template. No matching file found.');
}
return $selectedFile;
} }
/** /**
@ -321,15 +317,16 @@ class Layout
* It will detect whether the file exists and choose a file according to the provided extensions * 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 $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. * @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
* *
* @throws LayoutException On error * @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); $arr = $this->getFileFromString($string, $directories, $extensions);
$this->directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : $this->directory).DS); $this->file = $arr['file'];
$this->directory = $arr['directory'];
} }
/** /**
@ -401,9 +398,8 @@ class Layout
public function getTitle() public function getTitle()
{ {
if (!isset($this->assigned_variables['title'])) if (!isset($this->assigned_variables['title']))
{
return false; return false;
}
return $this->assigned_variables['title']; return $this->assigned_variables['title'];
} }
@ -454,7 +450,7 @@ class Layout
* @return bool true on success * @return bool true on success
* @throws LayoutException * @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 // First check if the engine already exists
if (isset($this->engines[$engineName])) if (isset($this->engines[$engineName]))
@ -522,9 +518,8 @@ class Layout
*/ */
public function reset() public function reset()
{ {
if (!is_null($this->current_engine)) { if (!is_null($this->current_engine))
$this->current_engine->reset(); $this->current_engine->reset();
}
// Unload the engines // Unload the engines
$this->engines = array(); $this->engines = array();
@ -533,7 +528,6 @@ class Layout
$this->current_engine = null; $this->current_engine = null;
$this->assigned_variables = array(); $this->assigned_variables = array();
$this->directory = Core::$appDirs[0]. DS . 'Layout';
Logger::log('Reset the layout manager to its default state'); Logger::log('Reset the layout manager to its default state');
} }
} }

View File

@ -47,6 +47,11 @@ namespace FuzeWorks;
class LayoutComponent implements iComponent class LayoutComponent implements iComponent
{ {
public function getName(): string
{
return 'LayoutComponent';
}
public function getClasses(): array public function getClasses(): array
{ {
return [ return [
@ -54,4 +59,12 @@ class LayoutComponent implements iComponent
'languages' => '\FuzeWorks\Languages' 'languages' => '\FuzeWorks\Languages'
]; ];
} }
public function onAddComponent(Configurator $configurator)
{
}
public function onCreateContainer(Factory $container)
{
}
} }

View File

@ -46,7 +46,6 @@ $container = require('bootstrap.php');
require_once 'layout/LayoutTestAbstract.php'; require_once 'layout/LayoutTestAbstract.php';
// Reset error and exception handlers // Reset error and exception handlers
ob_start();
restore_error_handler(); restore_error_handler();
restore_exception_handler(); restore_exception_handler();

View File

@ -34,14 +34,11 @@
* @version Version 1.2.0 * @version Version 1.2.0
*/ */
use org\bovigo\vfs\vfsStream;
require_once(dirname(__DIR__) . '/vendor/autoload.php'); require_once(dirname(__DIR__) . '/vendor/autoload.php');
$configurator = new FuzeWorks\Configurator(); $configurator = new FuzeWorks\Configurator();
// Implement all directories // Implement all directories
$configurator->addDirectory(dirname(__FILE__) . '/application');
$configurator->setTempDirectory(dirname(__FILE__) . '/temp'); $configurator->setTempDirectory(dirname(__FILE__) . '/temp');
$configurator->setLogDirectory(dirname(__FILE__) . '/temp'); $configurator->setLogDirectory(dirname(__FILE__) . '/temp');
@ -54,7 +51,6 @@ $configurator->addComponent(new \FuzeWorks\LayoutComponent());
// Create container // Create container
$container = $configurator->createContainer(); $container = $configurator->createContainer();
$container->init();
// And return the result // And return the result
return $container; return $container;

View File

@ -37,7 +37,7 @@
use FuzeWorks\Factory; use FuzeWorks\Factory;
use FuzeWorks\Layout; use FuzeWorks\Layout;
use FuzeWorks\Events; use FuzeWorks\Events;
use FuzeWorks\EventPriority; use FuzeWorks\Priority;
/** /**
* Class LayoutTest. * Class LayoutTest.
@ -77,13 +77,14 @@ class LayoutTest extends LayoutTestAbstract
// Prepare container // Prepare container
$configurator = new \FuzeWorks\Configurator(); $configurator = new \FuzeWorks\Configurator();
$configurator->addComponent($component); $configurator->addComponent($component);
$configurator->addDirectory(dirname(__DIR__) . '/application'); $configurator->setTempDirectory(dirname(__DIR__) . '/temp');
$configurator->setLogDirectory(dirname(__DIR__) . '/temp');
// Create container // Create container
$container = $configurator->createContainer(); $container = $configurator->createContainer();
// Init container // Init container;
$container = $container->init();
$this->assertTrue(property_exists($container, 'layouts')); $this->assertTrue(property_exists($container, 'layouts'));
$this->assertInstanceOf('FuzeWorks\Layout', $container->layouts); $this->assertInstanceOf('FuzeWorks\Layout', $container->layouts);
} }
@ -103,8 +104,8 @@ class LayoutTest extends LayoutTestAbstract
// Directory test // Directory test
$directory = 'test'.DS.'templates'.DS.'testFileAndDirectory'; $directory = 'test'.DS.'templates'.DS.'testFileAndDirectory';
$this->layout->setDirectory($directory); $this->layout->addComponentPath($directory);
$this->assertEquals($directory, $this->layout->getDirectory()); $this->assertEquals([$directory], $this->layout->getComponentPaths());
} }
/** /**
@ -128,20 +129,20 @@ class LayoutTest extends LayoutTestAbstract
// Extensions to be used in this test // Extensions to be used in this test
$extensions = array('php', 'json'); $extensions = array('php', 'json');
// Prepare variables
$directories = [3 => ['test'.DS.'templates'.DS.'testGetFilePath']];
// Basic path // 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.'layout.test.php', $this->layout->getFile());
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS, $this->layout->getDirectory());
// Alternate file extension // 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.'layout.JSON.json', $this->layout->getFile());
$this->assertEquals('test'.DS.'templates'.DS.'testGetFilePath'.DS, $this->layout->getDirectory());
// Complex deeper path // 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.'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 to be used in this test
$extensions = array('php', 'json'); $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() public function testMissingDirectory()
{ {
// Directory that does not exist // 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() 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() 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() public function testLayoutGet()
{ {
// Directory of these tests // 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() public function testLayoutGetRepeat()
{ {
$directory = 'test'.DS.'templates'.DS.'testLayoutGetRepeat'.DS; $directories = ['test'.DS.'templates'.DS.'testLayoutGetRepeat'];
$this->assertEquals('First Data', $this->layout->get('first', $directory)); $this->assertEquals('First Data', $this->layout->get('first', $directories));
$this->assertEquals('Second Data', $this->layout->get('second', $directory)); $this->assertEquals('Second Data', $this->layout->get('second', $directories));
} }
/** /**
@ -216,11 +217,11 @@ class LayoutTest extends LayoutTestAbstract
*/ */
public function testLayoutGetCancelledEvent() public function testLayoutGetCancelledEvent()
{ {
$directory = 'test'.DS.'templates'.DS.'testLayoutGetCancelledEvent'; $directories = ['test'.DS.'templates'.DS.'testLayoutGetCancelledEvent'];
Events::addListener(function($event){ Events::addListener(function($event){
$event->setCancelled(true); $event->setCancelled(true);
}, 'layoutLoadEvent', EventPriority::NORMAL); }, 'layoutLoadEvent', Priority::NORMAL);
$this->assertEquals('cancelled', $this->layout->get('test', $directory)); $this->assertEquals('cancelled', $this->layout->get('test', $directories));
} }
/** /**
@ -230,11 +231,11 @@ class LayoutTest extends LayoutTestAbstract
*/ */
public function testLayoutGetEventWrongFile() public function testLayoutGetEventWrongFile()
{ {
$directory = 'test'.DS.'templates'.DS.'testLayoutGetEventWrongFile'; $directories = ['test'.DS.'templates'.DS.'testLayoutGetEventWrongFile'];
Events::addListener(function($event){ Events::addListener(function($event){
$event->file = 'does_not_exist'; $event->file = 'does_not_exist';
}, 'layoutLoadEvent', EventPriority::NORMAL); }, 'layoutLoadEvent', Priority::NORMAL);
$this->layout->get('test', $directory); $this->layout->get('test', $directories);
} }
/** /**
@ -244,13 +245,13 @@ class LayoutTest extends LayoutTestAbstract
public function testLayoutDisplayEventAndDisplay() public function testLayoutDisplayEventAndDisplay()
{ {
// Directory of these tests // Directory of these tests
$directory = 'test'.DS.'templates'.DS.'testLayoutGet'.DS; $directories = ['test'.DS.'templates'.DS.'testLayoutGet'];
Events::addListener(function($event){ Events::addListener(function($event){
$this->assertEquals('Retrieved Data', $event->contents); $this->assertEquals('Retrieved Data', $event->contents);
}, 'layoutDisplayEvent', EventPriority::NORMAL); }, 'layoutDisplayEvent', Priority::NORMAL);
ob_start(); ob_start();
$this->layout->display('test', $directory); $this->layout->display('test', $directories);
$this->assertEquals('Retrieved Data', ob_get_contents()); $this->assertEquals('Retrieved Data', ob_get_contents());
ob_end_clean(); ob_end_clean();
} }
@ -262,20 +263,20 @@ class LayoutTest extends LayoutTestAbstract
*/ */
public function testReset() public function testReset()
{ {
$this->layout->setDirectories([3=>['test'.DS.'templates'.DS.'testLayoutGet']]);
// First the the variables // First the the variables
$this->layout->setTitle('Test Title'); $this->layout->setTitle('Test Title');
$this->layout->setDirectory('test'.DS.'templates'.DS.'testLayoutGet');
// Test if they are actually set // Test if they are actually set
$this->assertEquals('Test Title', $this->layout->getTitle()); $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 // Reset the layout system
$this->layout->reset(); $this->layout->reset();
// Test for default values // Test for default values
$this->assertFalse($this->layout->getTitle()); $this->assertEquals(['test'.DS.'templates'.DS.'testLayoutGet'], $this->layout->getComponentPaths());
$this->assertTrue(strpos($this->layout->getDirectory(), 'application' . DS . 'Layout') !== false);
} }
/** /**
@ -326,7 +327,7 @@ class LayoutTest extends LayoutTestAbstract
Events::addListener(function($event){ Events::addListener(function($event){
$this->assertInstanceOf('\FuzeWorks\Event\NotifierEvent', $event); $this->assertInstanceOf('\FuzeWorks\Event\NotifierEvent', $event);
throw new \FuzeWorks\Exception\EventException('Forcing failure in loadTemplateEngines()'); throw new \FuzeWorks\Exception\EventException('Forcing failure in loadTemplateEngines()');
}, 'layoutLoadEngineEvent', EventPriority::NORMAL); }, 'layoutLoadEngineEvent', Priority::NORMAL);
$this->layout->loadTemplateEngines(); $this->layout->loadTemplateEngines();
} }
@ -350,7 +351,7 @@ class LayoutTest extends LayoutTestAbstract
$this->layout->registerEngine($mock, 'Custom', array('test')); $this->layout->registerEngine($mock, 'Custom', array('test'));
// And run the engine // 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() public function testEnginesLoadLayout()
{ {
// Directory of these tests // Directory of these tests
$directory = 'test'.DS.'templates'.DS.'testEngines'.DS; $directories = ['test'.DS.'templates'.DS.'testEngines'];
// First the PHP Engine // 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(); $this->layout->reset();
// Then the JSON Engine // 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(); $this->layout->reset();
// And the Smarty Engine // 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() public function testEngineVariables()
{ {
// Directory of these tests // Directory of these tests
$directory = 'test'.DS.'templates'.DS.'testEngineVariables'.DS; $directories = ['test'.DS.'templates'.DS.'testEngineVariables'];
// First the PHP Engine // First the PHP Engine
$this->layout->assign('key', 'value'); $this->layout->assign('key', 'value');
$this->assertEquals('value', $this->layout->get('php', $directory)); $this->assertEquals('value', $this->layout->get('php', $directories));
$this->layout->reset(); $this->layout->reset();
// Then the JSON Engine // Then the JSON Engine
$this->layout->assign('key', 'value'); $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(); $this->layout->reset();
// And the Smarty Engine // And the Smarty Engine
$this->layout->assign('key', 'value'); $this->layout->assign('key', 'value');
$this->assertEquals('value', $this->layout->get('smarty', $directory)); $this->assertEquals('value', $this->layout->get('smarty', $directories));
} }
} }

View File

@ -61,8 +61,5 @@ abstract class LayoutTestAbstract extends TestCase
// Re-enable events, in case they have been disabled // Re-enable events, in case they have been disabled
Events::enable(); Events::enable();
// Reset the HTTP status code
Core::$http_status_code = 200;
} }
} }

View File

@ -27,7 +27,7 @@
<directory suffix=".php">../</directory> <directory suffix=".php">../</directory>
<exclude> <exclude>
<directory suffix=".php">../vendor/</directory> <directory suffix=".php">../vendor/</directory>
<directory suffix=".php">../tests/</directory> <directory suffix=".php">../test/</directory>
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>