2016-05-27 11:55:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-10-07 21:02:18 +00:00
|
|
|
* FuzeWorks Framework Core.
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* The FuzeWorks PHP FrameWork
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2019-01-10 22:59:00 +00:00
|
|
|
* Copyright (C) 2013-2019 TechFuze
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @author TechFuze
|
2019-01-10 22:59:00 +00:00
|
|
|
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
2018-10-07 21:02:18 +00:00
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @link http://techfuze.net/fuzeworks
|
|
|
|
* @since Version 0.0.1
|
2016-05-27 11:55:31 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @version Version 1.2.0
|
2016-05-27 11:55:31 +00:00
|
|
|
*/
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
use FuzeWorks\EventPriority;
|
|
|
|
use FuzeWorks\Events;
|
2018-10-07 21:02:18 +00:00
|
|
|
use FuzeWorks\Helpers;
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class HelperTest.
|
|
|
|
*
|
|
|
|
* Helpers testing suite, will test basic loading of Helpers
|
|
|
|
*/
|
|
|
|
class helperTest extends CoreTestAbstract
|
|
|
|
{
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/**
|
|
|
|
* @var Helpers
|
|
|
|
*/
|
2016-05-27 11:55:31 +00:00
|
|
|
protected $helpers;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2018-12-13 22:45:55 +00:00
|
|
|
// Prepare class
|
|
|
|
$this->helpers = new Helpers();
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->helpers->setDirectories(['test' . DS . 'helpers']);
|
2016-05-27 11:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHelpersClass()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('FuzeWorks\Helpers', $this->helpers);
|
|
|
|
}
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
/**
|
|
|
|
* @covers \FuzeWorks\Helpers::load
|
|
|
|
*/
|
2016-05-27 11:55:31 +00:00
|
|
|
public function testLoadHelper()
|
|
|
|
{
|
|
|
|
// First test if the function/helper is not loaded yet
|
|
|
|
$this->assertFalse(function_exists('testHelperFunction'));
|
|
|
|
|
|
|
|
// Test if the helper is properly loaded
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertTrue($this->helpers->load('TestLoadHelper'));
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// Test if the function exists now
|
|
|
|
$this->assertTrue(function_exists('testHelperFunction'));
|
|
|
|
}
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
/**
|
|
|
|
* @depends testLoadHelper
|
|
|
|
* @covers \FuzeWorks\Helpers::load
|
|
|
|
*/
|
|
|
|
public function testLoadHelperWithoutSubdirectory()
|
|
|
|
{
|
|
|
|
// First test if the function/helper is not loaded yet
|
|
|
|
$this->assertFalse(function_exists('testLoadHelperWithoutSubdirectory'));
|
|
|
|
|
|
|
|
// Try and load the helper
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertTrue($this->helpers->load('TestLoadHelperWithoutSubdirectory'));
|
2018-12-13 22:45:55 +00:00
|
|
|
|
|
|
|
// Then test if the function/helper is loaded
|
|
|
|
$this->assertTrue(function_exists('testLoadHelperWithoutSubdirectory'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadHelper
|
|
|
|
* @covers \FuzeWorks\Helpers::load
|
|
|
|
*/
|
|
|
|
public function testReloadHelper()
|
|
|
|
{
|
|
|
|
// First test if the function/helper is not loaded yet
|
|
|
|
$this->assertFalse(function_exists('testReloadHelper'));
|
|
|
|
|
|
|
|
// Try and load the helper
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertTrue($this->helpers->load('TestReloadHelper'));
|
2018-12-13 22:45:55 +00:00
|
|
|
|
|
|
|
// Then test if the function/helper is loaded
|
|
|
|
$this->assertTrue(function_exists('testReloadHelper'));
|
|
|
|
|
|
|
|
// Try and reload the helper
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertFalse($this->helpers->load('TestReloadHelper'));
|
2018-12-13 22:45:55 +00:00
|
|
|
|
|
|
|
// Test that the function still exists
|
|
|
|
$this->assertTrue(function_exists('testReloadHelper'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadHelper
|
|
|
|
* @covers \FuzeWorks\Helpers::load
|
|
|
|
*/
|
|
|
|
public function testCancelLoadHelper()
|
|
|
|
{
|
|
|
|
// First test if the function/helper is not loaded yet
|
|
|
|
$this->assertFalse(function_exists('testCancelLoadHelper'));
|
|
|
|
|
|
|
|
// Prepare listener
|
|
|
|
Events::addListener(function($event) {
|
|
|
|
$event->setCancelled(true);
|
|
|
|
|
|
|
|
}, 'helperLoadEvent', EventPriority::NORMAL);
|
|
|
|
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertFalse($this->helpers->load('TestCancelLoadHelper'));
|
2018-12-13 22:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadHelper
|
|
|
|
* @covers \FuzeWorks\Helpers::get
|
|
|
|
*/
|
|
|
|
public function testGetHelper()
|
|
|
|
{
|
|
|
|
// First test if the function/helper is not loaded yet
|
|
|
|
$this->assertFalse(function_exists('testGetHelper'));
|
|
|
|
|
|
|
|
// Test if the helper is properly loaded
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertTrue($this->helpers->get('TestGetHelper'));
|
2018-12-13 22:45:55 +00:00
|
|
|
|
|
|
|
// Test if the function exists now
|
|
|
|
$this->assertTrue(function_exists('testGetHelper'));
|
|
|
|
}
|
|
|
|
|
2016-05-27 11:55:31 +00:00
|
|
|
/**
|
2016-07-11 10:44:13 +00:00
|
|
|
* @expectedException FuzeWorks\Exception\HelperException
|
2018-12-13 22:45:55 +00:00
|
|
|
* @covers \FuzeWorks\Helpers::load
|
2016-05-27 11:55:31 +00:00
|
|
|
*/
|
|
|
|
public function testAddHelperPathFail()
|
|
|
|
{
|
|
|
|
// First test if the function is not loaded yet
|
|
|
|
$this->assertFalse(function_exists('testAddHelperPathFunction'));
|
|
|
|
|
|
|
|
// Now test if the helper can be loaded (hint: it can not)
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->helpers->load('TestAddHelperPathFail');
|
2016-05-27 11:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testAddHelperPathFail
|
2018-12-13 22:45:55 +00:00
|
|
|
* @covers \FuzeWorks\Helpers::addHelperPath
|
|
|
|
* @covers \FuzeWorks\Helpers::getHelperPaths
|
2016-05-27 11:55:31 +00:00
|
|
|
*/
|
|
|
|
public function testAddHelperPath()
|
|
|
|
{
|
|
|
|
// Add the helperPath
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->helpers->addHelperPath('test'.DS.'helpers'.DS.'TestAddHelperPath');
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// And try to load it again
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertTrue($this->helpers->load('TestAddHelperPath'));
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// And test if the function is loaded
|
|
|
|
$this->assertTrue(function_exists('testAddHelperPathFunction'));
|
|
|
|
}
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
/**
|
|
|
|
* @covers \FuzeWorks\Helpers::removeHelperPath
|
|
|
|
* @covers \FuzeWorks\Helpers::getHelperPaths
|
|
|
|
*/
|
2016-05-27 11:55:31 +00:00
|
|
|
public function testRemoveHelperPath()
|
|
|
|
{
|
|
|
|
// Test if the path does NOT exist
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveHelperPath', $this->helpers->getHelperPaths()));
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// Add it
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->helpers->addHelperPath('test'.DS.'helpers'.DS.'TestRemoveHelperPath');
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// Assert if it's there
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertTrue(in_array('test'.DS.'helpers'.DS.'TestRemoveHelperPath', $this->helpers->getHelperPaths()));
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// Remove it
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->helpers->removeHelperPath('test'.DS.'helpers'.DS.'TestRemoveHelperPath');
|
2016-05-27 11:55:31 +00:00
|
|
|
|
|
|
|
// And test if it's gone again
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveHelperPath', $this->helpers->getHelperPaths()));
|
2016-05-27 11:55:31 +00:00
|
|
|
}
|
2018-10-07 21:02:18 +00:00
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
/**
|
|
|
|
* @covers \FuzeWorks\Helpers::setDirectories
|
|
|
|
* @covers \FuzeWorks\Helpers::getHelperPaths
|
|
|
|
*/
|
2018-10-07 21:02:18 +00:00
|
|
|
public function testSetDirectories()
|
|
|
|
{
|
|
|
|
// Add the directory
|
2018-12-23 18:21:31 +00:00
|
|
|
$directory = 'test' . DS . 'helpers';
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->helpers->setDirectories([$directory]);
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
// Assert expectations
|
2018-12-23 18:21:31 +00:00
|
|
|
$expected = array_merge(\FuzeWorks\Core::$appDirs, ['test' . DS . 'helpers', $directory]);
|
2018-12-13 22:45:55 +00:00
|
|
|
$this->assertEquals($expected, $this->helpers->getHelperPaths());
|
2018-10-07 21:02:18 +00:00
|
|
|
}
|
2016-05-27 11:55:31 +00:00
|
|
|
}
|