Passed
Push — master ( 75f1be...abbf77 )
by Lucien
01:58
created

PluginToolsTest::testGetPluginByTitle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
dl 12
loc 12
rs 9.4285
c 6
b 0
f 0
cc 3
eloc 9
nc 3
nop 0
1
<?php
2
3
use TwinDigital\WPTools\PluginTools;
4
5
/**
6
 * Class PluginToolsTest
7
 */
8
class PluginToolsTest extends 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...
9
10
  /**
11
   * Plugins that come pre-installed with WordPress.
12
   *
13
   * @var array $preinstalledPlugins
14
   */
15
  public $preinstalledPlugins = [
16
    'Akismet Anti-Spam',
17
    'Hello Dolly',
18
  ];
19
20
  public function setUp() {
21
    parent::setUp();
22
  }
23
24
  /**
25
   * Tests if the plugin_list is loaded.
26
   *
27
   * @covers \TwinDigital\WPTools\PluginTools::loadPluginList()
28
   * @return void
29
   */
30
  public function testLoadPluginList() {
31
    PluginTools::$loadedPlugins = [];
32
    PluginTools::loadPluginList();
33
    $this->assertNotCount(0, PluginTools::$loadedPlugins, 'Pluginlist is empty, probably failed loading the list of plugins.');
34
  }
35
36
  /**
37
   * Tests if the plugin_list is loaded.
38
   *
39
   * @covers \TwinDigital\WPTools\PluginTools::refreshLoadedPlugins()
40
   * @return void
41
   */
42
  public function testRefreshLoadedPlugins() {
43
    PluginTools::$loadedPlugins = [];
44
    PluginTools::refreshLoadedPlugins();
45
    $this->assertNotCount(0, PluginTools::$loadedPlugins, 'Pluginlist is empty, probably failed loading the list of plugins.');
46
  }
47
48
  /**
49
   * Tests if getting a plugin by name is working as it should.
50
   *
51
   * @covers \TwinDigital\WPTools\PluginTools::getPluginByTitle()
52
   * @return void
53
   */
54 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...
55
    PluginTools::refreshLoadedPlugins();
56
    $this->assertEmpty(PluginTools::getPluginByTitle('Non-existing-plugin'), 'Found a plugin that is non-existing? Oops');
57
    $pluginDetails = null;
58
    foreach ($this->preinstalledPlugins as $plugin) {
59
      $pluginDetails = PluginTools::getPluginByTitle($plugin);
60
      if ($pluginDetails !== false) {
61
        break;
62
      }
63
    }
64
    $this->assertNotEmpty($pluginDetails);
65
    $this->assertNotCount(0, $pluginDetails);
66
  }
67
68
  /**
69
   * Tests if getting a plugin by name is working as it should.
70
   *
71
   * @covers \TwinDigital\WPTools\PluginTools::getPluginByTitleCaseInsensitive()
72
   * @return void
73
   */
74 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...
75
    PluginTools::refreshLoadedPlugins();
76
    $this->assertEmpty(PluginTools::getPluginByTitleCaseInsensitive(strtolower('Non-existing-plugin')), 'Found a plugin that is non-existing? Oops');
77
    $pluginDetails = null;
78
    foreach ($this->preinstalledPlugins as $plugin) {
79
      $pluginDetails = PluginTools::getPluginByTitleCaseInsensitive(strtolower($plugin));
80
      if ($pluginDetails !== false) {
81
        break;
82
      }
83
    }
84
    $this->assertNotEmpty($pluginDetails);
85
    $this->assertNotCount(0, $pluginDetails);
86
  }
87
88
  public function testIsPluginActive() {
89
    $this->assertFalse(PluginTools::isPluginActive('Non-existing-plugin'));
90
    $this->assertFalse(PluginTools::isPluginActive('Hello Dolly'));
91
  }
92
}
93