2014-05-14 13:24:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use System\Classes\PluginManager;
|
|
|
|
|
|
|
|
|
|
class PluginManagerTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
|
2019-06-12 16:22:20 +00:00
|
|
|
public function setUp() : void
|
2014-05-14 13:24:20 +00:00
|
|
|
{
|
2015-02-10 06:45:07 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
include_once base_path().'/tests/fixtures/plugins/october/tester/Plugin.php';
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Tests
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
public function testLoadPlugins()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$result = self::callProtectedMethod($manager, 'loadPlugins');
|
|
|
|
|
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertCount(5, $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('October.NoUpdates', $result);
|
|
|
|
|
$this->assertArrayHasKey('October.Sample', $result);
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertArrayHasKey('October.Tester', $result);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertArrayHasKey('Database.Tester', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('TestVendor.Test', $result);
|
2018-12-04 17:22:07 +00:00
|
|
|
$this->assertArrayNotHasKey('TestVendor.Goto', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$this->assertInstanceOf('October\NoUpdates\Plugin', $result['October.NoUpdates']);
|
|
|
|
|
$this->assertInstanceOf('October\Sample\Plugin', $result['October.Sample']);
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertInstanceOf('October\Tester\Plugin', $result['October.Tester']);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertInstanceOf('Database\Tester\Plugin', $result['Database.Tester']);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertInstanceOf('TestVendor\Test\Plugin', $result['TestVendor.Test']);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 17:22:07 +00:00
|
|
|
public function testUnloadablePlugin()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$pluginNamespaces = $manager->getPluginNamespaces();
|
|
|
|
|
$result = $manager->loadPlugin('\\testvendor\\goto', $pluginNamespaces['\\testvendor\\goto']);
|
|
|
|
|
$this->assertNull($result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
public function testGetPluginPath()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = $manager->getPluginPath('October\Tester');
|
2015-01-05 00:46:33 +00:00
|
|
|
$basePath = str_replace('\\', '/', base_path());
|
2015-02-10 06:45:07 +00:00
|
|
|
$this->assertEquals($basePath . '/tests/fixtures/plugins/october/tester', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetPlugins()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$result = $manager->getPlugins();
|
|
|
|
|
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertCount(5, $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('October.NoUpdates', $result);
|
|
|
|
|
$this->assertArrayHasKey('October.Sample', $result);
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertArrayHasKey('October.Tester', $result);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertArrayHasKey('Database.Tester', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('TestVendor.Test', $result);
|
2018-12-04 17:22:07 +00:00
|
|
|
$this->assertArrayNotHasKey('TestVendor.Goto', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$this->assertInstanceOf('October\NoUpdates\Plugin', $result['October.NoUpdates']);
|
|
|
|
|
$this->assertInstanceOf('October\Sample\Plugin', $result['October.Sample']);
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertInstanceOf('October\Tester\Plugin', $result['October.Tester']);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertInstanceOf('Database\Tester\Plugin', $result['Database.Tester']);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertInstanceOf('TestVendor\Test\Plugin', $result['TestVendor.Test']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFindByNamespace()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = $manager->findByNamespace('October\Tester');
|
|
|
|
|
$this->assertInstanceOf('October\Tester\Plugin', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testHasPlugin()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = $manager->hasPlugin('October\Tester');
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
|
|
$result = $manager->hasPlugin('October\XXXXX');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetPluginNamespaces()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$result = $manager->getPluginNamespaces();
|
|
|
|
|
|
2018-12-04 17:22:07 +00:00
|
|
|
$this->assertCount(6, $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('\october\noupdates', $result);
|
|
|
|
|
$this->assertArrayHasKey('\october\sample', $result);
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertArrayHasKey('\october\tester', $result);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertArrayHasKey('\database\tester', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('\testvendor\test', $result);
|
2018-12-04 17:22:07 +00:00
|
|
|
$this->assertArrayHasKey('\testvendor\goto', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
2017-10-08 18:14:17 +00:00
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
public function testGetVendorAndPluginNames()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$vendors = $manager->getVendorAndPluginNames();
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('october', $vendors);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertArrayHasKey('database', $vendors);
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('testvendor', $vendors);
|
2015-09-09 09:28:47 +00:00
|
|
|
$this->assertCount(3, $vendors);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPluginDetails()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$testPlugin = $manager->findByNamespace('October\XXXXX');
|
|
|
|
|
$this->assertNull($testPlugin);
|
|
|
|
|
|
2014-09-20 07:59:19 +00:00
|
|
|
$testPlugin = $manager->findByNamespace('October\Tester');
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertNotNull($testPlugin);
|
|
|
|
|
$pluginDetails = $testPlugin->pluginDetails();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('October Test Plugin', $pluginDetails['name']);
|
|
|
|
|
$this->assertEquals('Test plugin used by unit tests.', $pluginDetails['description']);
|
|
|
|
|
$this->assertEquals('Alexey Bobkov, Samuel Georges', $pluginDetails['author']);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-08 18:14:17 +00:00
|
|
|
public function testUnregisterall()
|
|
|
|
|
{
|
|
|
|
|
$manager = PluginManager::instance();
|
|
|
|
|
$result = $manager->getPlugins();
|
|
|
|
|
$this->assertCount(5, $result);
|
|
|
|
|
|
|
|
|
|
$manager->unregisterAll();
|
|
|
|
|
$this->assertEmpty($manager->getPlugins());
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 11:38:19 +00:00
|
|
|
}
|