Completed
Push — try/capabilities ( eb7fe7...7f65a9 )
by
unknown
40:05 queued 32:52
created

test_capability_has_details()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Automattic\Jetpack;
4
5
use Automattic\Jetpack\Capabilities;
6
use phpmock\functions\FunctionProvider;
7
// use phpmock\Mock;
8
// use phpmock\MockBuilder;
9
// use PHPUnit\Framework\TestCase;
10
11
// just for fun...
12
const JETPACK_BUSINESS_PLAN_SLUG = 'jetpack_business';
13
14
class Test_Jetpack_Capabilities extends \WP_UnitTestCase {
15
	var $builder;
16
17
	public function setUp() {
18
		$this->builder = new Capabilities\Builder();
19
	}
20
21
	public function tearDown() {
22
		// Mock::disableAll();
23
		// \Mockery::close();
24
	}
25
26
	public function test_get_capability() {
27
28
		$capability = $this->builder
29
			->create_capability( 'jetpack.backup.restore' )
30
			->require_wp_role( 'administrator' )
31
			->require_wp_capability( 'administrator' )
32
			// ->require_minimum_jetpack_plan( JETPACK_BUSINESS_PLAN_SLUG )
33
			->get_capability();
34
35
		// no admin privilege
36
		$this->assertFalse( $capability->test() );
37
38
		$this->setUserRole( 'administrator' );
39
40
		// has admin privilege
41
		$this->assertTrue( $capability->test() );
42
	}
43
44
	public function test_capability_has_details() {
45
46
	}
47
48
	/**
49
	 * Utility functions
50
	 */
51
	private function setUserRole( $role ) {
52
		$user = wp_get_current_user(); // new \WP_User( $user_id );
53
		$user->set_role( $role );
54
	}
55
56
	// public function test_jitm_disabled_by_filter() {
57
	// 	$this->mock_filters( array(
58
	// 		array( 'jetpack_just_in_time_msgs', false, false ),
59
	// 	) );
60
61
	// 	$jitm = new JITM();
62
	// 	$this->assertFalse( $jitm->register() );
63
64
	// 	$this->clear_mock_filters();
65
	// }
66
67
	// public function test_jitm_enabled_by_default() {
68
	// 	$this->mock_filters( array(
69
	// 		array( 'jetpack_just_in_time_msgs', false, true ),
70
	// 	) );
71
72
	// 	$jitm = new JITM();
73
	// 	$this->assertTrue( $jitm->register() );
74
75
	// 	$this->clear_mock_filters();
76
	// }
77
78
	// /**
79
	//  * This is an example of a test which uses Mockery to tests a class static method.
80
	//  *
81
	//  * It requires the runInSeparateProcess tag so that the class isn't already autoloaded.
82
	//  *
83
	//  * @runInSeparateProcess
84
	//  */
85
	// public function test_prepare_jitms_enqueues_assets() {
86
	// 	$mockAssets = \Mockery::mock('alias:Automattic\Jetpack\Assets');
87
88
	// 	// mock the static method and return a dummy value
89
	// 	$mockAssets
90
	// 		->shouldReceive('get_file_url_for_environment')
91
	// 		->andReturn('the_file_url');
92
93
	// 	$jitm = new JITM();
94
	// 	$screen = (object) array( 'id' => 'jetpack_foo' ); // fake screen object
95
	// 	$jitm->prepare_jitms( $screen );
96
97
	// 	// this should enqueue a jetpack-jitm-new script
98
	// 	do_action( 'admin_enqueue_scripts' );
99
100
	// 	// assert our script was enqueued with the right value
101
	// 	$script = $this->get_enqueued_script( 'jetpack-jitm-new' );
102
103
	// 	$this->assertEquals( 'the_file_url', $script['src'] );
104
	// }
105
106
	// /*
107
	// public function test_prepare_jitms_does_not_show_on_some_screens() {
108
	// 	$jitm = new JITM();
109
	// 	$screen = new \stdClass();
110
	// 	$screen->id = 'jetpack_page_stats';
111
	// 	$jitm->prepare_jitms( $screen );
112
	// }
113
	// */
114
115
	// protected function mock_filters( $filters ) {
116
	// 	$this->mocked_filters = $filters;
117
	// 	$builder = new MockBuilder();
118
	// 	$builder->setNamespace( __NAMESPACE__ )
119
	// 		->setName( 'apply_filters' )
120
	// 		->setFunction(
121
	// 			function() {
122
	// 				$current_args = func_get_args();
123
	// 				foreach ( $this->mocked_filters as $filter ) {
124
	// 					if ( array_slice( $filter, 0, -1 ) === $current_args ) {
125
	// 						return array_pop( $filter );
126
	// 					}
127
	// 				}
128
	// 			}
129
	// 		);
130
	// 	$this->apply_filters_mock = $builder->build();
131
	// 	$this->apply_filters_mock->enable();
132
	// }
133
134
	// protected function clear_mock_filters() {
135
	// 	$this->apply_filters_mock->disable();
136
	// 	unset( $this->mocked_filters );
137
	// }
138
139
	// protected function mock_add_action() {
140
	// 	$builder = new MockBuilder();
141
	// 	$builder->setNamespace( __NAMESPACE__ )
142
	// 		->setName( 'add_action' )
143
	// 		->setFunction( function( $name, $callable ) {
144
	// 			global $actions;
145
146
	// 			if ( is_null( $actions ) ) {
147
	// 				$actions = array();
148
	// 			}
149
150
	// 			// don't worry about precedence for now
151
	// 			if ( ! isset( $actions[$name] ) ) {
152
	// 				$actions[$name] = array();
153
	// 			}
154
155
	// 			$actions[$name][] = $callable;
156
	// 		} );
157
	// 	$builder->build()->enable();
158
	// }
159
160
	// protected function mock_do_action() {
161
	// 	$builder = new MockBuilder();
162
	// 	$builder->setNamespace( __NAMESPACE__ )
163
	// 		->setName( 'do_action' )
164
	// 		->setFunction( function() {
165
	// 			global $actions;
166
	// 			$args = func_get_args();
167
	// 			$name = array_shift( $args );
168
169
	// 			if ( is_null( $actions ) ) {
170
	// 				$actions = array();
171
	// 			}
172
173
	// 			// don't worry about precedence for now
174
	// 			if ( ! isset( $actions[$name] ) ) {
175
	// 				$actions[$name] = array();
176
	// 			}
177
178
	// 			foreach( $actions[$name] as $callable ) {
179
	// 				call_user_func_array( $callable, $args );
180
	// 			}
181
	// 		} );
182
	// 	$builder->build()->enable();
183
	// }
184
185
	// protected function mock_wp_enqueue_script() {
186
	// 	$builder = new MockBuilder();
187
	// 	$builder->setNamespace( __NAMESPACE__ )
188
	// 		->setName( 'wp_enqueue_script' )
189
	// 		->setFunction( function( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) {
190
	// 			global $wp_scripts;
191
192
	// 			if ( is_null( $wp_scripts ) ) {
193
	// 				$wp_scripts = array();
194
	// 			}
195
196
	// 			$wp_scripts[$handle] = compact( 'src', 'deps', 'ver', 'in_footer' );
197
	// 		} );
198
	// 	$builder->build()->enable();
199
	// }
200
201
	// protected function get_enqueued_script( $handle ) {
202
	// 	global $wp_scripts;
203
	// 	return isset( $wp_scripts[$handle] ) ? $wp_scripts[$handle] : null;
204
	// }
205
206
	// protected function clear_added_actions() {
207
	// 	global $actions;
208
	// 	$actions = array();
209
	// }
210
211
	// protected function clear_enqueued_scripts() {
212
	// 	global $wp_scripts;
213
	// 	$wp_scripts = array();
214
	// }
215
216
	// protected function mock_empty_function( $name ) {
217
	// 	$builder = new MockBuilder();
218
	// 	$builder->setNamespace( __NAMESPACE__ )
219
	// 		->setName( $name )
220
	// 		->setFunction( function() use ( $name ) {
221
	// 			// echo "Called $name with " . print_r( func_get_args(),1 ) . "\n";
222
	// 		} );
223
	// 	$builder->build()->enable();
224
	// }
225
}
226