Skip to content

Commit

Permalink
chore : test tracks attribute and fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ta5r committed Sep 25, 2024
1 parent 39aa666 commit 569ddac
Showing 1 changed file with 98 additions and 18 deletions.
116 changes: 98 additions & 18 deletions tests/unit/CoreVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
namespace WPGraphQL\ContentBlocks\Unit;

final class CoreVideoTest extends PluginTestCase {
/**
* The instance of the class being tested.
*
* @var \WPGraphQL\ContentBlocks\CoreVideo
*/
public $instance;

/**
* The post ID.
*
* @var int
*/
public $post_id;

public function setUp(): void {
Expand All @@ -14,19 +25,7 @@ public function setUp(): void {
$this->post_id = wp_insert_post(
[
'post_title' => 'Post Title',
'post_content' => preg_replace(
'/\s+/',
' ',
trim(
'
<!-- wp:video {"id":1636,"align":"wide","lock":{"move":true,"remove":true},"className":"test-css-class"} -->
<figure id="test-anchor" class="wp-block-video" style="margin-top:var(--wp--preset--spacing--50);margin-right:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50);margin-left:var(--wp--preset--spacing--50)">
<video autoplay loop muted poster="http://mysite.local/wp-content/uploads/2023/05/pexels-egor-komarov-14420089-scaled.jpg" preload="auto" src="http://mysite.local/wp-content/uploads/2023/07/pexels_videos_1860684-1440p.mp4" playsinline></video>
<figcaption class="wp-element-caption">Sample caption</figcaption></figure>
<!-- /wp:video -->
'
)
),
'post_content' => '',
'post_status' => 'publish',
]
);
Expand All @@ -43,8 +42,8 @@ public function tearDown(): void {
\WPGraphQL::clear_schema();
}

public function test_retrieve_core_video_attributes() {
$query = '
public function query(): string {
return '
fragment CoreVideoBlockFragment on CoreVideo {
attributes {
align
Expand All @@ -65,7 +64,7 @@ className
id
}
}
query GetPosts {
posts(first: 1) {
nodes {
Expand All @@ -78,6 +77,25 @@ className
}
}
';
}

public function test_retrieve_core_video_attributes() {
$block_content = '
<!-- wp:video {"id":1636,"align":"wide","lock":{"move":true,"remove":true},"className":"test-css-class"} -->
<figure id="test-anchor" class="wp-block-video" style="margin-top:var(--wp--preset--spacing--50);margin-right:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50);margin-left:var(--wp--preset--spacing--50)">
<video autoplay loop muted poster="http://mysite.local/wp-content/uploads/2023/05/pexels-egor-komarov-14420089-scaled.jpg" preload="auto" src="http://mysite.local/wp-content/uploads/2023/07/pexels_videos_1860684-1440p.mp4" playsinline></video>
<figcaption class="wp-element-caption">Sample caption</figcaption></figure>
<!-- /wp:video -->';

// Update the post content with the block content.
wp_update_post(
[
'ID' => $this->post_id,
'post_content' => $block_content,
]
);

$query = $this->query();
$actual = graphql( [ 'query' => $query ] );
$node = $actual['data']['posts']['nodes'][0];

Expand All @@ -90,7 +108,7 @@ className
$this->assertEquals(
[
'align' => 'wide',
'anchor' => 'test-anchor',
'anchor' => 'test-anchor',
'autoplay' => null, // @todo : 'autoplay' should be true.
'tracks' => [],
'muted' => null, // @todo : 'muted' should be true.
Expand All @@ -102,11 +120,73 @@ className
'playsInline' => null, // @todo : 'playsInline' should be true.
'controls' => true,
'loop' => null, // @todo : 'loop' should be true.
'lock' => wp_json_encode( [ 'move' => true, 'remove' => true ] ),
'lock' => wp_json_encode(
[
'move' => true,
'remove' => true,
]
),
'poster' => 'http://mysite.local/wp-content/uploads/2023/05/pexels-egor-komarov-14420089-scaled.jpg',
'id' => 1636.0,
],
$node['editorBlocks'][0]['attributes']
);
}

/**
* Test to retrieve core video 'tracks' attribute.
*/
public function test_retrieve_core_video_tracks_attribute() {
$block_content = '
<!-- wp:video {"id":1636,"tracks":[{"src":"https://example.com/subtitles.vtt","kind":"subtitles","label":"English","srclang":"en"}],"lock":{"move":true,"remove":true}} -->
<figure class="wp-block-video">
<video src="http://mysite.local/wp-content/uploads/2023/07/pexels_videos_1860684-1440p.mp4" playsinline></video>
</figure>
<!-- /wp:video -->';

// Update the post content with the block content.
wp_update_post(
[
'ID' => $this->post_id,
'post_content' => $block_content,
]
);

$query = '
fragment CoreVideoBlockFragment on CoreVideo {
attributes {
tracks
}
}
query GetPosts {
posts(first: 1) {
nodes {
databaseId
editorBlocks {
name
...CoreVideoBlockFragment
}
}
}
}';

$actual = graphql( [ 'query' => $query ] );

$node = $actual['data']['posts']['nodes'][0];

$tracks = $node['editorBlocks'][0]['attributes']['tracks'];
$tracks_data = json_decode( $tracks[0], true );

$this->assertCount( 1, $tracks );
$this->assertEquals(
[
'src' => 'https://example.com/subtitles.vtt',
'kind' => 'subtitles',
'label' => 'English',
'srclang' => 'en',
],
$tracks_data
);
}
}

0 comments on commit 569ddac

Please sign in to comment.