Skip to content

Commit 559d6ef

Browse files
committed
Added unit tests.
1 parent 38c2ffd commit 559d6ef

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/Unit/Admin/MetaBox/CouponChannelVisibilityMetaBoxTest.php

Lines changed: 56 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,58 @@ 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+
$this->assertArrayNotHasKey( 'is_setup_complete', $context );
100+
}
101+
102+
/**
103+
* @dataProvider data_provider_is_channel_supported
104+
*
105+
* @param bool $is_supported
106+
*/
107+
public function test_get_view_context_includes_is_channel_supported( bool $is_supported ): void {
108+
$post = $this->createMock( WP_Post::class );
109+
110+
$this->merchant_center
111+
->method( 'is_promotion_supported_country' )
112+
->willReturn( $is_supported );
113+
114+
// Use Reflection to access protected method.
115+
$reflection = new ReflectionClass( $this->coupon_channel_visibility_meta_box );
116+
$method = $reflection->getMethod( 'get_view_context' );
117+
$method->setAccessible( true );
118+
119+
$context = $method->invoke( $this->coupon_channel_visibility_meta_box, $post, [] );
120+
121+
$this->assertIsArray( $context );
122+
$this->assertArrayHasKey( 'is_channel_supported', $context );
123+
$this->assertSame( $is_supported, $context['is_channel_supported'] );
124+
}
125+
126+
/**
127+
* Data provider for test_get_view_context_includes_is_channel_supported.
128+
*
129+
* @return array
130+
*/
131+
public function data_provider_is_channel_supported(): array {
132+
return [
133+
'supported' => [ true ],
134+
'not_supported' => [ false ],
135+
];
136+
}
81137
}

0 commit comments

Comments
 (0)