Completed
Push — master ( abbf77...28136f )
by Lucien
01:41
created

testGetPluginByTitleCaseInsensitive()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 0
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 PluginToolsTest
9
 */
10
class PluginToolsTest extends WP_UnitTestCase {
11
12
  /**
13
   * Plugins that come pre-installed with WordPress.
14
   *
15
   * @var array $preinstalledPlugins
16
   */
17
  public $preinstalledPlugins = [
18
    'Akismet Anti-Spam',
19
    'Hello Dolly',
20
  ];
21
22
  /**
23
   * Comment
24
   * @return void
25
   */
26
  public function setUp() {
27
    parent::setUp();
28
  }
29
30
  /**
31
   * Tests if the plugin_list is loaded.
32
   *
33
   * @covers \TwinDigital\WPTools\PluginTools::loadPluginList()
34
   * @return void
35
   */
36
  public function testLoadPluginList() {
37
    PluginTools::$loadedPlugins = [];
38
    PluginTools::loadPluginList();
39
    $this->assertNotCount(0, PluginTools::$loadedPlugins, 'Pluginlist is empty, probably failed loading the list of plugins.');
40
  }
41
42
  /**
43
   * Tests if the plugin_list is loaded.
44
   *
45
   * @covers \TwinDigital\WPTools\PluginTools::refreshLoadedPlugins()
46
   * @return void
47
   */
48
  public function testRefreshLoadedPlugins() {
49
    PluginTools::$loadedPlugins = [];
50
    PluginTools::refreshLoadedPlugins();
51
    $this->assertNotCount(0, PluginTools::$loadedPlugins, 'Pluginlist is empty, probably failed loading the list of plugins.');
52
  }
53
54
  /**
55
   * Tests if getting a plugin by name is working as it should.
56
   *
57
   * @covers \TwinDigital\WPTools\PluginTools::getPluginByTitle()
58
   * @return void
59
   */
60 View Code Duplication
  public function testGetPluginByTitle() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    PluginTools::refreshLoadedPlugins();
62
    $this->assertEmpty(PluginTools::getPluginByTitle('Non-existing-plugin'), 'Found a plugin that is non-existing? Oops');
63
    $pluginDetails = null;
64
    foreach ($this->preinstalledPlugins as $plugin) {
65
      $pluginDetails = PluginTools::getPluginByTitle($plugin);
66
      if ($pluginDetails !== false) {
67
        break;
68
      }
69
    }
70
    $this->assertNotEmpty($pluginDetails);
71
    $this->assertNotCount(0, $pluginDetails);
72
  }
73
74
  /**
75
   * Tests if getting a plugin by name is working as it should.
76
   *
77
   * @covers \TwinDigital\WPTools\PluginTools::getPluginByTitleCaseInsensitive()
78
   * @return void
79
   */
80 View Code Duplication
  public function testGetPluginByTitleCaseInsensitive() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    PluginTools::refreshLoadedPlugins();
82
    $this->assertEmpty(PluginTools::getPluginByTitleCaseInsensitive(strtolower('Non-existing-plugin')), 'Found a plugin that is non-existing? Oops');
83
    $pluginDetails = null;
84
    foreach ($this->preinstalledPlugins as $plugin) {
85
      $pluginDetails = PluginTools::getPluginByTitleCaseInsensitive(strtolower($plugin));
86
      if ($pluginDetails !== false) {
87
        break;
88
      }
89
    }
90
    $this->assertNotEmpty($pluginDetails);
91
    $this->assertNotCount(0, $pluginDetails);
92
  }
93
94
  /**
95
   * Test wether a plugin is active.
96
   * @return void
97
   */
98
  public function testIsPluginActive() {
99
    $this->assertFalse(PluginTools::isPluginActive('Non-existing-plugin'));
100
    $this->assertFalse(PluginTools::isPluginActive('Hello Dolly'));
101
  }
102
}
103