/
BasePluginTest.php
156 lines (135 loc) · 4.84 KB
/
BasePluginTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.6.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Core;
use Cake\Console\CommandCollection;
use Cake\Core\BasePlugin;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Core\PluginApplicationInterface;
use Cake\Event\EventManager;
use Cake\Http\MiddlewareQueue;
use Cake\TestSuite\TestCase;
use Company\TestPluginThree\Plugin as TestPluginThree;
use TestPlugin\Plugin as TestPlugin;
/**
* BasePluginTest class
*/
class BasePluginTest extends TestCase
{
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
Plugin::unload();
}
/**
* testConfigForRoutesAndBootstrap
*
* @return void
*/
public function testConfigForRoutesAndBootstrap()
{
$plugin = new BasePlugin([
'bootstrap' => false,
'routes' => false
]);
$this->assertFalse($plugin->isEnabled('routes'));
$this->assertFalse($plugin->isEnabled('bootstrap'));
$this->assertTrue($plugin->isEnabled('console'));
$this->assertTrue($plugin->isEnabled('middleware'));
}
public function testGetName()
{
$plugin = new TestPlugin();
$this->assertSame('TestPlugin', $plugin->getName());
$plugin = new TestPluginThree();
$this->assertSame('Company/TestPluginThree', $plugin->getName());
}
public function testGetNameOption()
{
$plugin = new TestPlugin(['name' => 'Elephants']);
$this->assertSame('Elephants', $plugin->getName());
}
public function testMiddleware()
{
$plugin = new BasePlugin();
$middleware = new MiddlewareQueue();
$this->assertSame($middleware, $plugin->middleware($middleware));
}
public function testConsoleNoop()
{
$plugin = new BasePlugin();
$commands = new CommandCollection();
$this->assertSame($commands, $plugin->console($commands));
}
public function testConsoleFind()
{
$plugin = new TestPlugin();
Plugin::getCollection()->add($plugin);
$result = $plugin->console(new CommandCollection());
$this->assertTrue($result->has('widget'), 'Should have plugin command added');
$this->assertTrue($result->has('test_plugin.widget'), 'Should have long plugin name');
$this->assertTrue($result->has('example'), 'Should have plugin shell added');
$this->assertTrue($result->has('test_plugin.example'), 'Should have long plugin name');
}
public function testBootstrap()
{
$app = $this->createMock(PluginApplicationInterface::class);
$plugin = new TestPlugin();
$this->assertFalse(Configure::check('PluginTest.test_plugin.bootstrap'));
$this->assertNull($plugin->bootstrap($app));
$this->assertTrue(Configure::check('PluginTest.test_plugin.bootstrap'));
}
public function testConstructorArguments()
{
$plugin = new BasePlugin([
'routes' => false,
'bootstrap' => false,
'console' => false,
'middleware' => false
]);
$this->assertFalse($plugin->isEnabled('routes'));
$this->assertFalse($plugin->isEnabled('bootstrap'));
$this->assertFalse($plugin->isEnabled('console'));
$this->assertFalse($plugin->isEnabled('middleware'));
}
public function testGetPathBaseClass()
{
$plugin = new BasePlugin();
$expected = CAKE . 'Core' . DS;
$this->assertSame($expected, $plugin->getPath());
$this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
$this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
}
public function testGetPathOptionValue()
{
$plugin = new BasePlugin(['path' => '/some/path']);
$expected = '/some/path';
$this->assertSame($expected, $plugin->getPath());
$this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
$this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
}
public function testGetPathSubclass()
{
$plugin = new TestPlugin();
$expected = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS;
$this->assertSame($expected, $plugin->getPath());
$this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
$this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
}
}