PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.3.48
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.3.48
1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 All 181 releases
disco / vendor / micropackage / requirements / tests / Checker / test-plugins.php

test-plugins.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.3.48, at vendor/micropackage/requirements/tests/Checker/test-plugins.php

124 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class TestPlugins
4 *
5 * @package micropackage/requirements
6 */
7
8 namespace Micropackage\Requirements\Test\Checker;
9
10 use phpmock\Mock;
11 use phpmock\MockBuilder;
12 use Micropackage\Requirements\Requirements;
13 use Micropackage\Requirements\Checker\Plugins as TestedChecker;
14
15 /**
16 * Plugins checker test case.
17 */
18 class TestPlugins extends \WP_UnitTestCase {
19
20 use \phpmock\phpunit\PHPMock;
21
22 public function setUp() {
23 parent::setUp();
24 $this->checker = new TestedChecker();
25 }
26
27 public function tearDown() {
28 parent::tearDown();
29 Mock::disableAll();
30 }
31
32 public function bad_params() {
33 return [
34 [ '5.3' ],
35 [ 1 ],
36 [ true ],
37 ];
38 }
39
40 public function test_get_name_should_return_valid_name() {
41 $this->assertSame( 'plugins', $this->checker->get_name() );
42 }
43
44 /**
45 * @dataProvider bad_params
46 * @expectedException Exception
47 */
48 public function test_check_should_throw_exception_if_passed_not_array( $param ) {
49 $this->checker->check( $param );
50 }
51
52 public function test_check_should_pass_if_one_required_plugin_is_active() {
53
54 $wp_get_active_and_valid_plugins = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'wp_get_active_and_valid_plugins' );
55 $wp_get_active_and_valid_plugins->expects( $this->once() )->willReturn( [
56 WP_PLUGIN_DIR . '/plugin-one/plugin-one.php',
57 WP_PLUGIN_DIR . '/plugin-two/plugin-two.php',
58 ] );
59
60 $this->checker->check( [
61 [ 'file' => 'plugin-one/plugin-one.php', 'name' => 'Plugin One' ],
62 ] );
63
64 $this->assertEmpty( $this->checker->get_errors() );
65
66 }
67
68 public function test_check_should_pass_if_all_required_plugins_are_active() {
69
70 $wp_get_active_and_valid_plugins = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'wp_get_active_and_valid_plugins' );
71 $wp_get_active_and_valid_plugins->expects( $this->once() )->willReturn( [
72 WP_PLUGIN_DIR . '/plugin-one/plugin-one.php',
73 WP_PLUGIN_DIR . '/plugin-two/plugin-two.php',
74 ] );
75
76 $this->checker->check( [
77 [ 'file' => 'plugin-one/plugin-one.php', 'name' => 'Plugin One' ],
78 [ 'file' => 'plugin-two/plugin-two.php', 'name' => 'Plugin Two' ],
79 ] );
80
81 $this->assertEmpty( $this->checker->get_errors() );
82
83 }
84
85 public function test_check_should_fail_if_at_least_one_required_plugin_is_not_active() {
86
87 $wp_get_active_and_valid_plugins = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'wp_get_active_and_valid_plugins' );
88 $wp_get_active_and_valid_plugins->expects( $this->once() )->willReturn( [
89 WP_PLUGIN_DIR . '/plugin-one/plugin-one.php',
90 ] );
91
92 $this->checker->check( [
93 [ 'file' => 'plugin-two/plugin-two.php', 'name' => 'Plugin Two' ],
94 ] );
95
96 $errors = $this->checker->get_errors();
97
98 $this->assertNotEmpty( $errors );
99 $this->assertCount( 1, $errors );
100 $this->assertContains( 'Plugin Two', $errors[0] );
101
102 }
103
104 public function test_check_should_fail_if_two_required_plugins_are_not_active() {
105
106 $wp_get_active_and_valid_plugins = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'wp_get_active_and_valid_plugins' );
107 $wp_get_active_and_valid_plugins->expects( $this->once() )->willReturn( [] );
108
109 $this->checker->check( [
110 [ 'file' => 'plugin-one/plugin-one.php', 'name' => 'Plugin One' ],
111 [ 'file' => 'plugin-two/plugin-two.php', 'name' => 'Plugin Two' ],
112 ] );
113
114 $errors = $this->checker->get_errors();
115
116 $this->assertNotEmpty( $errors );
117 $this->assertCount( 2, $errors );
118 $this->assertContains( 'Plugin One', $errors[0] );
119 $this->assertContains( 'Plugin Two', $errors[1] );
120
121 }
122
123 }
124