Passed
Push — master ( 7037c7...876caa )
by Lucien
08:15 queued 11s
created

PluginRequirementsTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 50
c 0
b 0
f 0
dl 0
loc 84
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testPluginRequirements() 0 63 1
1
<?php
2
3
namespace TwinDigital\WPTools;
4
5
use WP_UnitTestCase;
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * Class PluginRequirementsTest
9
 */
10
class PluginRequirementsTest extends WP_UnitTestCase
11
{
12
13
    /**
14
     * Plugins that come pre-installed with WordPress.
15
     *
16
     * @var array $preinstalledPlugins
17
     */
18
    public $preinstalledPlugins = [
19
        'Akismet Anti-Spam',
20
        'Hello Dolly',
21
    ];
22
23
    /**
24
     * Test adding a plugin-requirement.
25
     * @covers \TwinDigital\WPTools\PluginRequirements::checkPluginInstalled()
26
     * @covers \TwinDigital\WPTools\PluginRequirements::checkRequiredPlugins()
27
     * @covers \TwinDigital\WPTools\PluginRequirements::addPluginRequirement()
28
     * @covers \TwinDigital\WPTools\PluginRequirements::removePluginRequirement()
29
     * @return void
30
     */
31
    public function testPluginRequirements()
32
    {
33
        PluginTools::refreshLoadedPlugins();
34
        // Add plugin to requirements-list, first time should be true,
35
        // second time false because requirement already in list.
36
        $this->assertTrue(
37
            PluginRequirements::addPluginRequirement(
38
                'Hello Dolly',
39
                '0.0.0',
40
                '0.0.0',
41
                true
42
            ),
43
            'Could not add fake requirements'
44
        );
45
        $this->assertFalse(
46
            PluginRequirements::addPluginRequirement(
47
                'Hello Dolly',
48
                '0.0.0',
49
                '0.0.0',
50
                true
51
            ),
52
            'Check for existing requirement failed'
53
        );
54
        $this->assertTrue(
55
            PluginRequirements::addPluginRequirement(
56
                'WPTools',
57
                '0.0.0',
58
                '0.0.0',
59
                true
60
            ),
61
            'Could not add fake requirements'
62
        );
63
        // Testing requiredPlugins should be false, since we set fake version-numbers.
64
        $this->assertFalse(
65
            PluginRequirements::checkRequiredPlugins(),
66
            'Requirement should not be met unless version number of Hello Dolly is 0.0.0'
67
        );
68
        $this->assertTrue(PluginRequirements::removePluginRequirement('WPTools'));
69
70
        $this->assertTrue(PluginRequirements::removePluginRequirement('Hello Dolly'));
71
        $this->assertFalse(PluginRequirements::removePluginRequirement('Hello Dolly'));
72
        $this->assertTrue(PluginRequirements::checkRequiredPlugins());
73
        activate_plugin('hello-dolly/hello.php');
74
        PluginTools::refreshLoadedPlugins();
75
        $this->assertTrue(
76
            PluginRequirements::addPluginRequirement(
77
                'Hello Dolly',
78
                '0.0.0',
79
                '999.999.999',
80
                false
81
            )
82
        );
83
        $this->assertTrue(PluginRequirements::checkRequiredPlugins(), 'Hello Dolly should not be active yet.');
84
        $this->assertTrue(PluginRequirements::removePluginRequirement('Hello Dolly'));
85
        $this->assertTrue(
86
            PluginRequirements::addPluginRequirement(
87
                'Hello Dolly',
88
                '0.0.0',
89
                '999.999.999',
90
                true
91
            )
92
        );
93
        $this->assertFalse(PluginRequirements::checkRequiredPlugins(), 'Hello Dolly should not be active yet.');
94
    }
95
}
96