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 / test-requirements.php

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

129 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class TestRequirements
4 *
5 * @package micropackage/requirements
6 */
7
8 namespace Micropackage\Requirements\Test;
9
10 use Micropackage\Requirements\Requirements;
11
12 /**
13 * Requirements test case.
14 */
15 class TestRequirements extends \WP_UnitTestCase {
16
17 public function test_should_return_no_checks_if_not_set() {
18 $requirements = new Requirements( 'Test' );
19 $this->assertSame( [], $requirements->get() );
20 }
21
22 public function test_should_setup_checks_from_constructor() {
23
24 $req = [
25 'check1' => 'val1',
26 'check2' => 'val2',
27 ];
28
29 $requirements = new Requirements( 'Test', $req );
30
31 $this->assertSame( $req, $requirements->get() );
32
33 }
34
35 public function test_should_add_1_check_and_return_requirements() {
36
37 $expected = [
38 'check1' => uniqid(),
39 ];
40
41 $requirements = new Requirements( 'Test' );
42
43 $returned = $requirements->add( 'check1', $expected['check1'] );
44
45 $this->assertSame( $requirements, $returned );
46 $this->assertSame( $expected, $requirements->get() );
47
48 }
49
50 public function test_should_add_2_checks_and_return_requirements() {
51
52 $expected = [
53 'check1' => uniqid(),
54 'check2' => 'val2',
55 ];
56
57 $requirements = new Requirements( 'Test' );
58
59 $returned = $requirements->add( 'check1', $expected['check1'] )
60 ->add( 'check2', $expected['check2'] );
61
62 $this->assertSame( $requirements, $returned );
63 $this->assertSame( $expected, $requirements->get() );
64
65 }
66
67 /**
68 * @expectedException Exception
69 */
70 public function test_should_throw_exception_if_check_already_added() {
71
72 $requirements = new Requirements( 'Test' );
73
74 $requirements->add( 'check', true )
75 ->add( 'check', true );
76
77 }
78
79 /**
80 * @expectedException Exception
81 */
82 public function test_register_checker_should_throw_exception_if_object_checker_does_not_implement_interface() {
83 $requirements = new Requirements( 'Test' );
84 $requirements->register_checker( new \stdClass() );
85 }
86
87 /**
88 * @expectedException Exception
89 */
90 public function test_register_checker_should_throw_exception_if_string_checker_does_not_implement_interface() {
91 $requirements = new Requirements( 'Test' );
92 $requirements->register_checker( 'stdClass' );
93 }
94
95 /**
96 * @expectedException Exception
97 */
98 public function test_register_checker_should_throw_exception_if_checker_already_registered() {
99 $requirements = new Requirements( 'Test', [], false );
100 $requirements->register_checker( 'Micropackage\Requirements\Checker\PHP' );
101 $requirements->register_checker( 'Micropackage\Requirements\Checker\PHP' );
102 }
103
104 public function test_register_checker_should_register_checker_and_return_requirements() {
105 $requirements = new Requirements( 'Test', [], false );
106 $returned = $requirements->register_checker( 'Micropackage\Requirements\Checker\PHP' );
107 $this->assertTrue( $requirements->has_checker( 'php' ) );
108 $this->assertSame( $requirements, $returned );
109 }
110
111 public function test_has_checker_should_return_false_if_checker_not_registered() {
112 $requirements = new Requirements( 'Test', [], false );
113 $this->assertFalse( $requirements->has_checker( 'nope' ) );
114 }
115
116 public function test_get_checker_should_return_false_if_checker_not_registered() {
117 $requirements = new Requirements( 'Test', [], false );
118 $this->assertFalse( $requirements->get_checker( 'nope' ) );
119 }
120
121 public function test_get_checker_should_return_checker_instance() {
122 $class_name = 'Micropackage\Requirements\Checker\PHP';
123 $requirements = new Requirements( 'Test', [], false );
124 $requirements->register_checker( $class_name );
125 $this->assertInstanceOf( $class_name, $requirements->get_checker( 'php' ) );
126 }
127
128 }
129