2018-02-20 20:57:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-10-07 21:02:18 +00:00
|
|
|
* FuzeWorks Framework Core.
|
2018-02-20 20:57:12 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* The FuzeWorks PHP FrameWork
|
2018-02-20 20:57:12 +00:00
|
|
|
*
|
2019-01-10 22:59:00 +00:00
|
|
|
* Copyright (C) 2013-2019 TechFuze
|
2018-02-20 20:57:12 +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:
|
2018-02-20 20:57:12 +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.
|
2018-02-20 20:57:12 +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.
|
2018-02-20 20:57:12 +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
|
2018-02-20 20:57:12 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @link http://techfuze.net/fuzeworks
|
|
|
|
* @since Version 1.1.4
|
2018-02-20 20:57:12 +00:00
|
|
|
*
|
2018-10-07 21:02:18 +00:00
|
|
|
* @version Version 1.2.0
|
2018-02-20 20:57:12 +00:00
|
|
|
*/
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
use FuzeWorks\Core;
|
2018-02-20 20:57:12 +00:00
|
|
|
use FuzeWorks\Factory;
|
|
|
|
use FuzeWorks\Plugins;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PluginsTest.
|
|
|
|
*
|
|
|
|
* Plugins testing suite, will test basic loading of and management of Plugins
|
|
|
|
*/
|
|
|
|
class pluginTest extends CoreTestAbstract
|
|
|
|
{
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/**
|
|
|
|
* @var FuzeWorks\Plugins
|
|
|
|
*/
|
2018-02-20 20:57:12 +00:00
|
|
|
protected $plugins;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->plugins = new Plugins();
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->plugins->addPluginPath('test'.DS.'plugins');
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->plugins->loadHeadersFromPluginPaths();
|
2018-02-20 20:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPluginsClass()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('FuzeWorks\Plugins', $this->plugins);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGetPluginsClass
|
|
|
|
*/
|
|
|
|
public function testLoadPlugin()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('\Application\Plugin\TestLoadPlugin', $this->plugins->get('testLoadPlugin'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
*/
|
|
|
|
public function testReloadPlugin()
|
|
|
|
{
|
|
|
|
$this->assertSame($this->plugins->get('testReloadPlugin'), $this->plugins->get('testReloadPlugin'));
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
*/
|
|
|
|
public function testLoadHeader()
|
|
|
|
{
|
|
|
|
// Load the header object
|
2019-01-11 22:16:45 +00:00
|
|
|
require_once('test' . DS . 'plugins' . DS . 'TestLoadHeader'.DS.'loadHeader'.DS.'header.php');
|
2018-10-07 21:02:18 +00:00
|
|
|
$header = new Plugins\TestLoadHeaderHeader();
|
|
|
|
|
|
|
|
// Register the header object
|
|
|
|
$this->plugins->addPlugin($header);
|
|
|
|
|
|
|
|
// Assert the plugin
|
|
|
|
$this->assertInstanceOf('Application\Plugin\Plug', $this->plugins->get('Plug'));
|
|
|
|
}
|
|
|
|
|
2018-02-20 20:57:12 +00:00
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testMissingHeader()
|
|
|
|
{
|
|
|
|
$this->plugins->get('testMissingHeader');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
*/
|
|
|
|
public function testGetPluginMethod()
|
|
|
|
{
|
|
|
|
$this->assertEquals('test_string', $this->plugins->get('testGetPluginMethod'));
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
*/
|
|
|
|
public function testGetPluginWithClassFile()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf('OtherPlug', $this->plugins->get('TestGetPluginWithClassFile'));
|
|
|
|
}
|
|
|
|
|
2018-02-20 20:57:12 +00:00
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testMissingPlugin()
|
|
|
|
{
|
|
|
|
$this->plugins->get('testMissingPlugin');
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
/**
|
|
|
|
* @depends testMissingPlugin
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testLoadHeaderNotIPluginHeader()
|
|
|
|
{
|
|
|
|
// Attempt to load all headers
|
|
|
|
$this->plugins->loadHeadersFromPluginPaths();
|
|
|
|
|
|
|
|
$this->plugins->get('TestLoadHeaderNotIPluginHeader');
|
|
|
|
}
|
|
|
|
|
2018-02-20 20:57:12 +00:00
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testInvalidClass()
|
|
|
|
{
|
|
|
|
$this->plugins->get('testInvalidClass');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testGetMissingName()
|
|
|
|
{
|
|
|
|
$this->plugins->get('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testDisabledPlugin()
|
|
|
|
{
|
|
|
|
Factory::getInstance()->config->plugins->disabled_plugins = array('TestDisabledPlugin');
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->plugins->loadHeadersFromPluginPaths();
|
2018-02-20 20:57:12 +00:00
|
|
|
$this->plugins->get('testDisabledPlugin');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoadPlugin
|
|
|
|
* @expectedException FuzeWorks\Exception\PluginException
|
|
|
|
*/
|
|
|
|
public function testRunInvalidDirectory()
|
|
|
|
{
|
|
|
|
$this->plugins->addPluginPath('exists_not');
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->plugins->loadHeadersFromPluginPaths();
|
2018-02-20 20:57:12 +00:00
|
|
|
$this->plugins->get('testRunInvalidDirectory');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddPluginPath()
|
|
|
|
{
|
|
|
|
// Add the pluginPath
|
2019-01-11 22:16:45 +00:00
|
|
|
$this->plugins->addPluginPath('test'.DS.'plugins'.DS.'TestAddPluginPath');
|
2018-02-20 20:57:12 +00:00
|
|
|
|
|
|
|
// And try to load it again
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->plugins->loadHeadersFromPluginPaths();
|
2018-02-20 21:25:10 +00:00
|
|
|
$this->assertInstanceOf('Application\Plugin\ActualPlugin', $this->plugins->get('ActualPlugin'));
|
2018-02-20 20:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testAddPluginPath
|
|
|
|
*/
|
|
|
|
public function testRemovePluginPath()
|
|
|
|
{
|
|
|
|
// Test if the path does NOT exist
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths()));
|
2018-02-20 20:57:12 +00:00
|
|
|
|
|
|
|
// Add it
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->plugins->addPluginPath('test'.DS.'plugins'.DS.'testRemovePluginPath');
|
2018-02-20 20:57:12 +00:00
|
|
|
|
|
|
|
// Assert if it's there
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->assertTrue(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths()));
|
2018-02-20 20:57:12 +00:00
|
|
|
|
|
|
|
// Remove it
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->plugins->removePluginPath('test'.DS.'plugins'.DS.'testRemovePluginPath');
|
2018-02-20 20:57:12 +00:00
|
|
|
|
|
|
|
// And test if it's gone again
|
2018-12-23 18:21:31 +00:00
|
|
|
$this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths()));
|
2018-02-20 20:57:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-07 21:02:18 +00:00
|
|
|
public function testSetDirectories()
|
|
|
|
{
|
|
|
|
// Add the directory
|
2018-12-13 22:45:55 +00:00
|
|
|
$appDir = Core::$appDirs[0];
|
2018-12-23 18:21:31 +00:00
|
|
|
$directory = 'test' . DS . 'helpers';
|
|
|
|
$expected = [$appDir, 'test'.DS.'plugins', $directory];
|
2018-10-07 21:02:18 +00:00
|
|
|
$this->plugins->setDirectories([$directory]);
|
|
|
|
|
2018-12-13 22:45:55 +00:00
|
|
|
$this->assertEquals($expected, $this->plugins->getPluginPaths());
|
2018-10-07 21:02:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 20:57:12 +00:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
$factory = Factory::getInstance();
|
|
|
|
$factory->config->plugins->revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|