Skip to content

Commit 740136e

Browse files
authored
Merge pull request #3289 from woocommerce/fix/GOOWOO-501-php-fatal-error-in-353-on-couponchannelvisibilitymetabox
[GOOWOO-501] PHP Fatal error in 3.5.3 on CouponChannelVisibilityMetaBox - missing is_setup_complete context property
2 parents 7444fc8 + 7bdb0d6 commit 740136e

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

tests/Unit/Admin/MetaBox/CouponChannelVisibilityMetaBoxTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService;
1111
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\TargetAudience;
1212
use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest;
13+
use ReflectionClass;
14+
use WP_Post;
1315

1416
/**
1517
* Class CouponChannelVisibilityMetaBoxTest
@@ -78,4 +80,57 @@ public function data_provider_is_connected(): array {
7880
'not_connected' => [ false ],
7981
];
8082
}
83+
84+
public function test_get_view_context_returns_expected_keys(): void {
85+
$post = $this->createMock( WP_Post::class );
86+
87+
// Use Reflection to access protected method.
88+
$reflection = new ReflectionClass( $this->coupon_channel_visibility_meta_box );
89+
$method = $reflection->getMethod( 'get_view_context' );
90+
$method->setAccessible( true );
91+
92+
$context = $method->invoke( $this->coupon_channel_visibility_meta_box, $post, [] );
93+
94+
$this->assertIsArray( $context );
95+
$this->assertEqualsCanonicalizing(
96+
[ 'field_id', 'coupon_id', 'coupon', 'channel_visibility', 'sync_status', 'issues', 'is_channel_supported', 'get_started_url' ],
97+
array_keys( $context )
98+
);
99+
}
100+
101+
/**
102+
* @dataProvider data_provider_is_channel_supported
103+
*
104+
* @param bool $is_supported
105+
*/
106+
public function test_get_view_context_includes_is_channel_supported( bool $is_supported ): void {
107+
$post = $this->createMock( WP_Post::class );
108+
109+
$this->merchant_center
110+
->method( 'is_promotion_supported_country' )
111+
->willReturn( $is_supported );
112+
113+
// Use Reflection to access protected method.
114+
$reflection = new ReflectionClass( $this->coupon_channel_visibility_meta_box );
115+
$method = $reflection->getMethod( 'get_view_context' );
116+
$method->setAccessible( true );
117+
118+
$context = $method->invoke( $this->coupon_channel_visibility_meta_box, $post, [] );
119+
120+
$this->assertIsArray( $context );
121+
$this->assertArrayHasKey( 'is_channel_supported', $context );
122+
$this->assertSame( $is_supported, $context['is_channel_supported'] );
123+
}
124+
125+
/**
126+
* Data provider for test_get_view_context_includes_is_channel_supported.
127+
*
128+
* @return array
129+
*/
130+
public function data_provider_is_channel_supported(): array {
131+
return [
132+
'supported' => [ true ],
133+
'not_supported' => [ false ],
134+
];
135+
}
81136
}

views/meta-box/coupon_channel_visibility.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
*/
3434
$field_id = $this->field_id;
3535

36-
/**
37-
*
38-
* @var bool
39-
*/
40-
$is_setup_complete = $this->is_setup_complete;
41-
4236
/**
4337
*
4438
* @var bool

0 commit comments

Comments
 (0)