1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use TwinDigital\WPTools\PluginRequirements; |
4
|
|
|
use TwinDigital\WPTools\PluginTools; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class PluginToolsTest |
8
|
|
|
*/ |
9
|
|
|
class PluginRequirementsTest extends WP_UnitTestCase { |
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Plugins that come pre-installed with WordPress. |
13
|
|
|
* |
14
|
|
|
* @var array $preinstalledPlugins |
15
|
|
|
*/ |
16
|
|
|
public $preinstalledPlugins = [ |
17
|
|
|
'Akismet Anti-Spam', |
18
|
|
|
'Hello Dolly', |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test adding a plugin-requirement. |
23
|
|
|
* @covers \TwinDigital\WPTools\PluginRequirements::checkPluginInstalled() |
24
|
|
|
* @covers \TwinDigital\WPTools\PluginRequirements::checkRequiredPlugins() |
25
|
|
|
* @covers \TwinDigital\WPTools\PluginRequirements::addPluginRequirement() |
26
|
|
|
* @covers \TwinDigital\WPTools\PluginRequirements::removePluginRequirement() |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function testPluginRequirements() { |
30
|
|
|
PluginTools::refreshLoadedPlugins(); |
31
|
|
|
// Add plugin to requirements-list, first time should be true, second time false because requirement already in list. |
32
|
|
|
$this->assertTrue( |
33
|
|
|
PluginRequirements::addPluginRequirement( |
34
|
|
|
'Hello Dolly', |
35
|
|
|
'0.0.0', |
36
|
|
|
'0.0.0', |
37
|
|
|
true |
38
|
|
|
), |
39
|
|
|
'Could not add fake requirements' |
40
|
|
|
); |
41
|
|
|
$this->assertFalse( |
42
|
|
|
PluginRequirements::addPluginRequirement( |
43
|
|
|
'Hello Dolly', |
44
|
|
|
'0.0.0', |
45
|
|
|
'0.0.0', |
46
|
|
|
true |
47
|
|
|
), |
48
|
|
|
'Check for existing requirement failed' |
49
|
|
|
); |
50
|
|
|
$this->assertTrue( |
51
|
|
|
PluginRequirements::addPluginRequirement( |
52
|
|
|
'WPTools', |
53
|
|
|
'0.0.0', |
54
|
|
|
'0.0.0', |
55
|
|
|
true |
56
|
|
|
), |
57
|
|
|
'Could not add fake requirements' |
58
|
|
|
); |
59
|
|
|
// Testing requiredPlugins should be false, since we set fake version-numbers. |
60
|
|
|
$this->assertFalse( |
61
|
|
|
PluginRequirements::checkRequiredPlugins(), |
62
|
|
|
'Requirement should not be met unless version number of Hello Dolly is 0.0.0' |
63
|
|
|
); |
64
|
|
|
$this->assertTrue(PluginRequirements::removePluginRequirement('WPTools')); |
65
|
|
|
|
66
|
|
|
$this->assertTrue(PluginRequirements::removePluginRequirement('Hello Dolly')); |
67
|
|
|
$this->assertFalse(PluginRequirements::removePluginRequirement('Hello Dolly')); |
68
|
|
|
$this->assertTrue(PluginRequirements::checkRequiredPlugins()); |
69
|
|
|
activate_plugin('hello-dolly/hello.php'); |
70
|
|
|
PluginTools::refreshLoadedPlugins(); |
71
|
|
|
$this->assertTrue( |
72
|
|
|
PluginRequirements::addPluginRequirement( |
73
|
|
|
'Hello Dolly', |
74
|
|
|
'0.0.0', |
75
|
|
|
'999.999.999', |
76
|
|
|
false |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
$this->assertTrue(PluginRequirements::checkRequiredPlugins(), 'Hello Dolly should not be active yet.'); |
80
|
|
|
$this->assertTrue(PluginRequirements::removePluginRequirement('Hello Dolly')); |
81
|
|
|
$this->assertTrue( |
82
|
|
|
PluginRequirements::addPluginRequirement( |
83
|
|
|
'Hello Dolly', |
84
|
|
|
'0.0.0', |
85
|
|
|
'999.999.999', |
86
|
|
|
true |
87
|
|
|
) |
88
|
|
|
); |
89
|
|
|
$this->assertFalse(PluginRequirements::checkRequiredPlugins(), 'Hello Dolly should not be active yet.'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths