Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/Unit/fbproductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,48 @@ public function test_prepare_product_with_video_field() {
$this->assertEquals($expected_video_urls, $product_data['video']);
}

public function test_set_product_video_urls() {
// Prepare attachment IDs
$attachment_ids = '123,456';

// Mock get_video_urls_from_attachment_ids function
$this->fb_product = $this->getMockBuilder(WC_Facebook_Product::class)
->setConstructorArgs([$this->product])
->setMethods(['get_video_urls_from_attachment_ids'])
->getMock();

$this->fb_product->method('get_video_urls_from_attachment_ids')
->willReturnCallback(function($id) {
switch ($id) {
case '123':
return 'http://example.com/video1.mp4';
case '456':
return 'http://example.com/video2.mp4';
default:
return '';
}
});

// Set the video URLs in post meta
$video_urls = array_filter(array_map([$this->fb_product, 'get_video_urls_from_attachment_ids'], explode(',', $attachment_ids)));
update_post_meta( $this->fb_product->get_id(), WC_Facebook_Product::FB_PRODUCT_VIDEO, $video_urls );

// Get the saved video URLs from post meta
$saved_video_urls = get_post_meta( $this->product->get_id(), WC_Facebook_Product::FB_PRODUCT_VIDEO, true );

// Assert that the saved video URLs match the expected values
$this->assertEquals( $saved_video_urls, $video_urls);

// Assert that the saved video URLs are an array
$this->assertIsArray($saved_video_urls);

// Assert that the saved video URLs have the correct count
$this->assertCount(2, $saved_video_urls);

// Assert that the saved video URLs do not contain any empty strings
$this->assertNotContains('', $saved_video_urls);
}

public function test_prepare_product_with_mixed_fields() {
// Set only facebook description
$fb_description = 'Facebook specific description';
Expand Down