Code Duplication    Length = 31-31 lines in 2 locations

packages/capabilities/tests/php/test_Capabilities.php 2 locations

@@ 89-119 (lines=31) @@
86
	}
87
}
88
89
class Test_Jetpack_Capabilities_Jetpack_Plan extends Test_Jetpack_Capabilities_Base {
90
	public function test_jetpack_plan_rule() {
91
		$capability = $this->builder
92
			->create( 'jetpack.backup.restore' )
93
			->require_minimum_jetpack_plan( 'a_nice_plan' )
94
			->get();
95
96
		// expected plan
97
		$this->mockJetpackPlan( 'a_nice_plan' );
98
99
		$this->assertTrue( $capability->check()->granted() );
100
101
		// unexpected plan
102
		$this->mockJetpackPlan( 'some_other_plan' );
103
104
		$this->assertFalse( $capability->check()->granted() );
105
	}
106
107
	private function mockJetpackPlan( $product_slug ) {
108
		$this->current_product_slug = $product_slug;
109
110
		$mockPlan = \Mockery::mock('alias:Jetpack_Plan');
111
112
		// mock the static method Jetpack_Plan::get and return the instance prop
113
		$mockPlan
114
			->shouldReceive('get')
115
			->andReturnUsing( function() {
116
				return [ 'product_slug' => $this->current_product_slug ];
117
			} );
118
	}
119
}
120
121
class Test_Jetpack_Capabilities_Jetpack_Plan_Supports extends Test_Jetpack_Capabilities_Base {
122
	public function test_jetpack_plan_supports_rule() {
@@ 121-151 (lines=31) @@
118
	}
119
}
120
121
class Test_Jetpack_Capabilities_Jetpack_Plan_Supports extends Test_Jetpack_Capabilities_Base {
122
	public function test_jetpack_plan_supports_rule() {
123
		$capability = $this->builder
124
			->create( 'memberships' )
125
			->require_jetpack_plan_supports( 'recurring-payments' )
126
			->get();
127
128
		// expected supports
129
		$this->mockJetpackPlanSupports( 'recurring-payments' );
130
131
		$this->assertTrue( $capability->check()->granted() );
132
133
		// unexpected supports (clears previous value)
134
		$this->mockJetpackPlanSupports( 'not-recurring-payments' );
135
136
		$this->assertFalse( $capability->check()->granted() );
137
	}
138
139
	private function mockJetpackPlanSupports( $supports_slug ) {
140
		$this->current_supports_slug = $supports_slug;
141
142
		$mockPlan = \Mockery::mock('alias:Jetpack_Plan');
143
144
		// mock the static method Jetpack_Plan::supports and return the instance prop
145
		$mockPlan
146
			->shouldReceive('supports')
147
			->andReturnUsing( function( $slug ) {
148
				return $slug === $this->current_supports_slug;
149
			} );
150
	}
151
}
152
153
class Test_Jetpack_Capabilities_WP_Role extends Test_Jetpack_Capabilities_Base {
154
	public function test_check_role() {