Code Duplication    Length = 31-31 lines in 2 locations

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

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