mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Add additional test cases for PluginManager (#4427)
- Add dependency tests - Add tests that check wrong casing in requirements - Clean up current tests - Provides test case for https://github.com/octobercms/october/pull/4337
This commit is contained in:
parent
7f29cbe13c
commit
5b80ad2501
@ -13,9 +13,10 @@
|
||||
|
||||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||
<!--
|
||||
Migration files do not need a namespace defined
|
||||
Migration files and tests do not need a namespace defined
|
||||
-->
|
||||
<exclude-pattern>*/database/migrations/*\.php</exclude-pattern>
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<file>bootstrap/</file>
|
||||
|
16
tests/fixtures/plugins/dependencytest/dependency/Plugin.php
vendored
Normal file
16
tests/fixtures/plugins/dependencytest/dependency/Plugin.php
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
<?php namespace DependencyTest\Dependency;
|
||||
|
||||
use System\Classes\PluginBase;
|
||||
|
||||
class Plugin extends PluginBase
|
||||
{
|
||||
public function pluginDetails()
|
||||
{
|
||||
return [
|
||||
'name' => 'Dependency Test - Dependency',
|
||||
'description' => 'This is a test plugin that will act as a dependency for the other test plugins in this
|
||||
namespace.',
|
||||
'author' => 'Ben Thomson'
|
||||
];
|
||||
}
|
||||
}
|
1
tests/fixtures/plugins/dependencytest/dependency/updates/version.yaml
vendored
Normal file
1
tests/fixtures/plugins/dependencytest/dependency/updates/version.yaml
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.0.1: Initial version of the plugin
|
19
tests/fixtures/plugins/dependencytest/found/Plugin.php
vendored
Normal file
19
tests/fixtures/plugins/dependencytest/found/Plugin.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php namespace DependencyTest\Found;
|
||||
|
||||
use System\Classes\PluginBase;
|
||||
|
||||
class Plugin extends PluginBase
|
||||
{
|
||||
public $require = [
|
||||
'DependencyTest.Dependency'
|
||||
];
|
||||
|
||||
public function pluginDetails()
|
||||
{
|
||||
return [
|
||||
'name' => 'Dependency Test - Found',
|
||||
'description' => 'This is a test plugin with a dependency that exists.',
|
||||
'author' => 'Ben Thomson'
|
||||
];
|
||||
}
|
||||
}
|
1
tests/fixtures/plugins/dependencytest/found/updates/version.yaml
vendored
Normal file
1
tests/fixtures/plugins/dependencytest/found/updates/version.yaml
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.0.1: Initial version of the plugin
|
19
tests/fixtures/plugins/dependencytest/notfound/Plugin.php
vendored
Normal file
19
tests/fixtures/plugins/dependencytest/notfound/Plugin.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php namespace DependencyTest\NotFound;
|
||||
|
||||
use System\Classes\PluginBase;
|
||||
|
||||
class Plugin extends PluginBase
|
||||
{
|
||||
public $require = [
|
||||
'DependencyTest.Missing'
|
||||
];
|
||||
|
||||
public function pluginDetails()
|
||||
{
|
||||
return [
|
||||
'name' => 'Dependency Test - Not Found',
|
||||
'description' => 'This is a test plugin with a dependency that does not exist.',
|
||||
'author' => 'Ben Thomson'
|
||||
];
|
||||
}
|
||||
}
|
1
tests/fixtures/plugins/dependencytest/notfound/updates/version.yaml
vendored
Normal file
1
tests/fixtures/plugins/dependencytest/notfound/updates/version.yaml
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.0.1: Initial version of the plugin
|
19
tests/fixtures/plugins/dependencytest/wrongcase/Plugin.php
vendored
Normal file
19
tests/fixtures/plugins/dependencytest/wrongcase/Plugin.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php namespace DependencyTest\WrongCase;
|
||||
|
||||
use System\Classes\PluginBase;
|
||||
|
||||
class Plugin extends PluginBase
|
||||
{
|
||||
public $require = [
|
||||
'Dependencytest.dependency'
|
||||
];
|
||||
|
||||
public function pluginDetails()
|
||||
{
|
||||
return [
|
||||
'name' => 'Dependency Test - Wrong Case',
|
||||
'description' => 'This is a test plugin with a dependency that exists, but is using the wrong letter case.',
|
||||
'author' => 'Ben Thomson'
|
||||
];
|
||||
}
|
||||
}
|
1
tests/fixtures/plugins/dependencytest/wrongcase/updates/version.yaml
vendored
Normal file
1
tests/fixtures/plugins/dependencytest/wrongcase/updates/version.yaml
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.0.1: Initial version of the plugin
|
@ -1,15 +1,20 @@
|
||||
<?php
|
||||
|
||||
use System\Classes\PluginManager;
|
||||
|
||||
class PluginManagerTest extends TestCase
|
||||
{
|
||||
public $manager;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
include_once base_path().'/tests/fixtures/plugins/october/tester/Plugin.php';
|
||||
$manager = PluginManager::instance();
|
||||
self::callProtectedMethod($manager, 'loadDisabled');
|
||||
$manager->loadPlugins();
|
||||
self::callProtectedMethod($manager, 'loadDependencies');
|
||||
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
//
|
||||
@ -18,15 +23,19 @@ class PluginManagerTest extends TestCase
|
||||
|
||||
public function testLoadPlugins()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = self::callProtectedMethod($manager, 'loadPlugins');
|
||||
$result = $this->manager->loadPlugins();
|
||||
|
||||
$this->assertCount(5, $result);
|
||||
$this->assertCount(9, $result);
|
||||
$this->assertArrayHasKey('October.NoUpdates', $result);
|
||||
$this->assertArrayHasKey('October.Sample', $result);
|
||||
$this->assertArrayHasKey('October.Tester', $result);
|
||||
$this->assertArrayHasKey('Database.Tester', $result);
|
||||
$this->assertArrayHasKey('TestVendor.Test', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.Found', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.NotFound', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.WrongCase', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.Dependency', $result);
|
||||
|
||||
$this->assertArrayNotHasKey('TestVendor.Goto', $result);
|
||||
|
||||
$this->assertInstanceOf('October\NoUpdates\Plugin', $result['October.NoUpdates']);
|
||||
@ -34,35 +43,41 @@ class PluginManagerTest extends TestCase
|
||||
$this->assertInstanceOf('October\Tester\Plugin', $result['October.Tester']);
|
||||
$this->assertInstanceOf('Database\Tester\Plugin', $result['Database.Tester']);
|
||||
$this->assertInstanceOf('TestVendor\Test\Plugin', $result['TestVendor.Test']);
|
||||
$this->assertInstanceOf('DependencyTest\Found\Plugin', $result['DependencyTest.Found']);
|
||||
$this->assertInstanceOf('DependencyTest\NotFound\Plugin', $result['DependencyTest.NotFound']);
|
||||
$this->assertInstanceOf('DependencyTest\WrongCase\Plugin', $result['DependencyTest.WrongCase']);
|
||||
$this->assertInstanceOf('DependencyTest\Dependency\Plugin', $result['DependencyTest.Dependency']);
|
||||
}
|
||||
|
||||
public function testUnloadablePlugin()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$pluginNamespaces = $manager->getPluginNamespaces();
|
||||
$result = $manager->loadPlugin('\\testvendor\\goto', $pluginNamespaces['\\testvendor\\goto']);
|
||||
$pluginNamespaces = $this->manager->getPluginNamespaces();
|
||||
$result = $this->manager->loadPlugin('\\testvendor\\goto', $pluginNamespaces['\\testvendor\\goto']);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testGetPluginPath()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = $manager->getPluginPath('October\Tester');
|
||||
$result = $this->manager->getPluginPath('October\Tester');
|
||||
$basePath = str_replace('\\', '/', base_path());
|
||||
$this->assertEquals($basePath . '/tests/fixtures/plugins/october/tester', $result);
|
||||
}
|
||||
|
||||
public function testGetPlugins()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = $manager->getPlugins();
|
||||
$result = $this->manager->getPlugins();
|
||||
|
||||
$this->assertCount(5, $result);
|
||||
$this->assertCount(8, $result);
|
||||
$this->assertArrayHasKey('October.NoUpdates', $result);
|
||||
$this->assertArrayHasKey('October.Sample', $result);
|
||||
$this->assertArrayHasKey('October.Tester', $result);
|
||||
$this->assertArrayHasKey('Database.Tester', $result);
|
||||
$this->assertArrayHasKey('TestVendor.Test', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.Found', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.WrongCase', $result);
|
||||
$this->assertArrayHasKey('DependencyTest.Dependency', $result);
|
||||
|
||||
$this->assertArrayNotHasKey('DependencyTest.NotFound', $result);
|
||||
$this->assertArrayNotHasKey('TestVendor.Goto', $result);
|
||||
|
||||
$this->assertInstanceOf('October\NoUpdates\Plugin', $result['October.NoUpdates']);
|
||||
@ -70,57 +85,91 @@ class PluginManagerTest extends TestCase
|
||||
$this->assertInstanceOf('October\Tester\Plugin', $result['October.Tester']);
|
||||
$this->assertInstanceOf('Database\Tester\Plugin', $result['Database.Tester']);
|
||||
$this->assertInstanceOf('TestVendor\Test\Plugin', $result['TestVendor.Test']);
|
||||
$this->assertInstanceOf('DependencyTest\Found\Plugin', $result['DependencyTest.Found']);
|
||||
$this->assertInstanceOf('DependencyTest\WrongCase\Plugin', $result['DependencyTest.WrongCase']);
|
||||
$this->assertInstanceOf('DependencyTest\Dependency\Plugin', $result['DependencyTest.Dependency']);
|
||||
}
|
||||
|
||||
public function testFindByNamespace()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = $manager->findByNamespace('October\Tester');
|
||||
$result = $this->manager->findByNamespace('October\Tester');
|
||||
$this->assertInstanceOf('October\Tester\Plugin', $result);
|
||||
}
|
||||
|
||||
public function testHasPlugin()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = $manager->hasPlugin('October\Tester');
|
||||
$result = $this->manager->hasPlugin('October\Tester');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $manager->hasPlugin('October\XXXXX');
|
||||
$result = $this->manager->hasPlugin('DependencyTest.Found');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->manager->hasPlugin('DependencyTest\WrongCase');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->manager->hasPlugin('DependencyTest\NotFound');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->manager->hasPlugin('October\XXXXX');
|
||||
$this->assertFalse($result);
|
||||
|
||||
/**
|
||||
* Test case for https://github.com/octobercms/october/pull/4337
|
||||
*/
|
||||
$result = $this->manager->hasPlugin('dependencyTest\Wrongcase');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->manager->hasPlugin('dependencyTest.Wrongcase');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testGetPluginNamespaces()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = $manager->getPluginNamespaces();
|
||||
$result = $this->manager->getPluginNamespaces();
|
||||
|
||||
$this->assertCount(6, $result);
|
||||
$this->assertCount(10, $result);
|
||||
$this->assertArrayHasKey('\october\noupdates', $result);
|
||||
$this->assertArrayHasKey('\october\sample', $result);
|
||||
$this->assertArrayHasKey('\october\tester', $result);
|
||||
$this->assertArrayHasKey('\database\tester', $result);
|
||||
$this->assertArrayHasKey('\testvendor\test', $result);
|
||||
$this->assertArrayHasKey('\testvendor\goto', $result);
|
||||
$this->assertArrayHasKey('\dependencytest\found', $result);
|
||||
$this->assertArrayHasKey('\dependencytest\notfound', $result);
|
||||
$this->assertArrayHasKey('\dependencytest\wrongcase', $result);
|
||||
$this->assertArrayHasKey('\dependencytest\dependency', $result);
|
||||
}
|
||||
|
||||
public function testGetVendorAndPluginNames()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$vendors = $manager->getVendorAndPluginNames();
|
||||
$vendors = $this->manager->getVendorAndPluginNames();
|
||||
|
||||
$this->assertCount(4, $vendors);
|
||||
$this->assertArrayHasKey('october', $vendors);
|
||||
$this->assertArrayHasKey('noupdates', $vendors['october']);
|
||||
$this->assertArrayHasKey('sample', $vendors['october']);
|
||||
$this->assertArrayHasKey('tester', $vendors['october']);
|
||||
|
||||
$this->assertArrayHasKey('database', $vendors);
|
||||
$this->assertArrayHasKey('tester', $vendors['database']);
|
||||
|
||||
$this->assertArrayHasKey('testvendor', $vendors);
|
||||
$this->assertCount(3, $vendors);
|
||||
$this->assertArrayHasKey('test', $vendors['testvendor']);
|
||||
$this->assertArrayHasKey('goto', $vendors['testvendor']);
|
||||
|
||||
$this->assertArrayHasKey('dependencytest', $vendors);
|
||||
$this->assertArrayHasKey('found', $vendors['dependencytest']);
|
||||
$this->assertArrayHasKey('notfound', $vendors['dependencytest']);
|
||||
$this->assertArrayHasKey('wrongcase', $vendors['dependencytest']);
|
||||
$this->assertArrayHasKey('dependency', $vendors['dependencytest']);
|
||||
}
|
||||
|
||||
public function testPluginDetails()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$testPlugin = $manager->findByNamespace('October\XXXXX');
|
||||
$testPlugin = $this->manager->findByNamespace('October\XXXXX');
|
||||
$this->assertNull($testPlugin);
|
||||
|
||||
$testPlugin = $manager->findByNamespace('October\Tester');
|
||||
$testPlugin = $this->manager->findByNamespace('October\Tester');
|
||||
$this->assertNotNull($testPlugin);
|
||||
$pluginDetails = $testPlugin->pluginDetails();
|
||||
|
||||
@ -131,12 +180,37 @@ class PluginManagerTest extends TestCase
|
||||
|
||||
public function testUnregisterall()
|
||||
{
|
||||
$manager = PluginManager::instance();
|
||||
$result = $manager->getPlugins();
|
||||
$this->assertCount(5, $result);
|
||||
$result = $this->manager->getPlugins();
|
||||
$this->assertCount(8, $result);
|
||||
|
||||
$manager->unregisterAll();
|
||||
$this->assertEmpty($manager->getPlugins());
|
||||
$this->manager->unregisterAll();
|
||||
$this->assertEmpty($this->manager->getPlugins());
|
||||
}
|
||||
|
||||
public function testGetDependencies()
|
||||
{
|
||||
$result = $this->manager->getDependencies('DependencyTest.Found');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertContains('DependencyTest.Dependency', $result);
|
||||
|
||||
$result = $this->manager->getDependencies('DependencyTest.WrongCase');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertContains('Dependencytest.dependency', $result);
|
||||
|
||||
$result = $this->manager->getDependencies('DependencyTest.NotFound');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertContains('DependencyTest.Missing', $result);
|
||||
}
|
||||
|
||||
public function testIsDisabled()
|
||||
{
|
||||
$result = $this->manager->isDisabled('DependencyTest.Found');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->manager->isDisabled('DependencyTest.WrongCase');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->manager->isDisabled('DependencyTest.NotFound');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user