2016-06-02 18:13:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-10-07 21:02:18 +00:00
|
|
|
* FuzeWorks Framework Core.
|
2016-06-02 18:13:08 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* The FuzeWorks PHP FrameWork
|
2016-06-02 18:13:08 +00:00
|
|
|
*
|
2019-01-10 22:59:00 +00:00
|
|
|
* Copyright (C) 2013-2019 TechFuze
|
2016-06-02 18:13:08 +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-06-02 18:13:08 +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-06-02 18:13:08 +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-06-02 18:13:08 +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-06-02 18:13:08 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @link http://techfuze.net/fuzeworks
|
|
|
|
* @since Version 0.0.1
|
2016-06-02 18:13:08 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @version Version 1.2.0
|
2016-06-02 18:13:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
use FuzeWorks\Core;
|
2016-06-02 18:13:08 +00:00
|
|
|
use FuzeWorks\Factory;
|
2018-10-07 21:02:18 +00:00
|
|
|
use FuzeWorks\Libraries;
|
2016-06-02 18:13:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class LibraryTest.
|
|
|
|
*
|
|
|
|
* Libraries testing suite, will test basic loading of and management of Libraries
|
|
|
|
*/
|
|
|
|
class libraryTest extends CoreTestAbstract
|
|
|
|
{
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/**
|
|
|
|
* @var Libraries
|
|
|
|
*/
|
2016-06-02 18:13:08 +00:00
|
|
|
protected $libraries;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2018-12-13 22:45:55 +00:00
|
|
|
// Load new libraries class
|
|
|
|
$this->libraries = new Libraries();
|
2016-06-02 18:13:08 +00:00
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
// And then set all paths
|
2019-01-21 16:19:09 +00:00
|
|
|
$this->libraries->setDirectories([3 => ['test'.DS.'libraries']]);
|
2016-06-02 18:13:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
public function testLibrariesClass()
|
2016-06-02 18:13:08 +00:00
|
|
|
{
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->assertInstanceOf('FuzeWorks\Libraries', $this->libraries);
|
2016-06-02 18:13:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/* ---------------------------------- Load library from directories ------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLibrariesClass
|
|
|
|
*/
|
|
|
|
public function testGetLibraryFromDirectory()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('Application\Library\TestGetLibraryFromDirectory', $this->libraries->get('TestGetLibraryFromDirectory'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGetLibraryFromDirectory
|
|
|
|
*/
|
|
|
|
public function testGetLibraryFromSubdirectory()
|
|
|
|
{
|
|
|
|
// Add test directory path
|
2019-01-18 10:00:22 +00:00
|
|
|
$this->libraries->addComponentPath('test'.DS.'libraries'.DS.'TestGetLibraryFromSubdirectory');
|
2018-10-07 21:02:18 +00:00
|
|
|
|
|
|
|
$this->assertInstanceOf('Application\Library\TestGetLibraryFromSubdirectory', $this->libraries->get('TestGetLibraryFromSubdirectory'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGetLibraryFromDirectory
|
|
|
|
*/
|
|
|
|
public function testGetLibraryFromAltDirectory()
|
|
|
|
{
|
|
|
|
// Simple test of loading a library and checking if it exists
|
|
|
|
$this->assertInstanceOf('Application\Library\TestGetLibraryFromAltDirectory',
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->libraries->get('TestGetLibraryFromAltDirectory', [], ['test'.DS.'libraries'.DS.'TestGetLibraryFromAltDirectory']));
|
2018-10-07 21:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException FuzeWorks\Exception\LibraryException
|
|
|
|
*/
|
|
|
|
public function testGetLibraryFail()
|
|
|
|
{
|
|
|
|
$this->libraries->get('FailLoadLibrary');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException FuzeWorks\Exception\LibraryException
|
|
|
|
*/
|
|
|
|
public function testGetLibraryNoName()
|
|
|
|
{
|
|
|
|
$this->libraries->get('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException FuzeWorks\Exception\LibraryException
|
|
|
|
*/
|
|
|
|
public function testGetLibraryNoClass()
|
|
|
|
{
|
2018-12-13 22:45:55 +00:00
|
|
|
$this->libraries->get('TestGetLibraryNoClass');
|
2018-10-07 21:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLibraryParametersFromConfig()
|
|
|
|
{
|
|
|
|
// Prepare the config file
|
|
|
|
$libraryName = 'TestGetLibraryParametersFromConfig';
|
2019-01-11 22:16:45 +00:00
|
|
|
$libraryDir = 'test'.DS.'libraries'.DS.'TestGetLibraryParametersFromConfig';
|
2019-01-21 16:19:09 +00:00
|
|
|
Factory::getInstance()->config->getConfig(strtolower($libraryName), [$libraryDir]);
|
2018-10-07 21:02:18 +00:00
|
|
|
|
|
|
|
// Load the library
|
2018-12-13 22:45:55 +00:00
|
|
|
$lib = $this->libraries->get('TestGetLibraryParametersFromConfig');
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->assertInstanceOf('Application\Library\TestGetLibraryParametersFromConfig', $lib);
|
|
|
|
|
|
|
|
// And check the parameters
|
|
|
|
$this->assertEquals(5, $lib->parameters['provided']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------- Add libraries --------------------------------------------- */
|
|
|
|
|
|
|
|
public function testAddLibraryObject()
|
|
|
|
{
|
|
|
|
$this->libraries->addLibraryObject('TestAddLibraryObject', 5);
|
|
|
|
|
|
|
|
$this->assertEquals(5, $this->libraries->get('TestAddLibraryObject'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddLibraryClass()
|
|
|
|
{
|
2019-01-11 22:16:45 +00:00
|
|
|
require_once('test'.DS.'libraries'.DS.'TestAddLibraryClass'.DS.'TestAddLibraryClass.php');
|
2018-10-07 21:02:18 +00:00
|
|
|
|
|
|
|
$this->libraries->addLibraryClass('LibraryClass', '\Custom\Spaces\TestAddLibraryClass');
|
|
|
|
|
|
|
|
$this->assertInstanceOf('\Custom\Spaces\TestAddLibraryClass', $this->libraries->get('LibraryClass'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testAddLibraryClass
|
|
|
|
* @expectedException \FuzeWorks\Exception\LibraryException
|
|
|
|
*/
|
|
|
|
public function testAddLibraryClassFail()
|
|
|
|
{
|
|
|
|
$this->libraries->addLibraryClass('LibraryClassFail', '\Case\Not\Exist');
|
|
|
|
}
|
|
|
|
|
2016-06-02 18:13:08 +00:00
|
|
|
public function tearDown()
|
|
|
|
{
|
2019-01-16 19:18:46 +00:00
|
|
|
Factory::getInstance()->config->getConfig('error')->revert();
|
2016-06-02 18:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|