|
10 | 10 | use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService; |
11 | 11 | use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\TargetAudience; |
12 | 12 | use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest; |
| 13 | +use ReflectionClass; |
| 14 | +use WP_Post; |
13 | 15 |
|
14 | 16 | /** |
15 | 17 | * Class CouponChannelVisibilityMetaBoxTest |
@@ -78,4 +80,57 @@ public function data_provider_is_connected(): array { |
78 | 80 | 'not_connected' => [ false ], |
79 | 81 | ]; |
80 | 82 | } |
| 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 | + } |
81 | 136 | } |
0 commit comments