Skip to content

Commit

Permalink
fix blog card
Browse files Browse the repository at this point in the history
expectedは埋め込みサイトのレスポンスによって変わるので複数用意
  • Loading branch information
shimotmk committed Aug 30, 2023
1 parent 569352a commit 16d996a
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions test/phpunit/pro/test-blog-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function test_vk_blocks_blog_card_render_callback(){
</div>
',
),
// 外部リンク
// 外部リンク expectedは埋め込みサイトのレスポンスによって変わるので複数用意
array(
'content' => '
<!-- wp:vk-blocks/blog-card {"url":"https://vektor-inc.co.jp/"} -->
Expand All @@ -94,7 +94,8 @@ public function test_vk_blocks_blog_card_render_callback(){
<!-- wp:vk-blocks/blog-card-site-title /-->
</div>
<!-- /wp:vk-blocks/blog-card -->',
'expected' => '
'expected' => array(
'can_embed' =>'
<div %s>
<h5 class="wp-block-vk-blocks-blog-card-title"><a href="https://vektor-inc.co.jp/" target="_self" >株式会社ベクトル | WordPressテーマ・プラグイン開発のクリエイティブカンパニー</a></h5>
<figure class="wp-block-vk-blocks-blog-card-featured-image"><a href="https://vektor-inc.co.jp/" target="_self" ><img src=\'https://www.vektor-inc.co.jp/wp-content/uploads/2020/04/vecktor-inc_ogp2020.png\' style="object-fit:cover;" /></a></figure>
Expand All @@ -103,7 +104,8 @@ public function test_vk_blocks_blog_card_render_callback(){
<p class="wp-block-vk-blocks-blog-card-site-title"><a href="https://vektor-inc.co.jp" target="_self" >株式会社ベクトル</a></p>
</div>
',
'cannot_embed' => '<div %s>https://vektor-inc.co.jp/</div>',
'cannot_embed' => '<div %s>https://vektor-inc.co.jp/</div>',
),
),
// 外部リンク 埋め込み不可
array(
Expand All @@ -130,31 +132,24 @@ public function test_vk_blocks_blog_card_render_callback(){
} else {
$get_block_wrapper_attributes = 'class="wp-block-vk-blocks-blog-card"';
}
$correct = sprintf($test['expected'], $get_block_wrapper_attributes);
if (!empty($test['cannot_embed'])) {
$cannot_embed_correct = sprintf($test['cannot_embed'], $get_block_wrapper_attributes);
if ( is_array($test['expected']) ) {
$correct = array();
$correct[1] = sprintf($test['expected']['can_embed'], $get_block_wrapper_attributes);
$correct[2] = sprintf($test['expected']['cannot_embed'], $get_block_wrapper_attributes);
} else {
$correct = sprintf($test['expected'], $get_block_wrapper_attributes);
}

// print PHP_EOL;
// print '$test[content][1] :';
// var_dump($test['content']);
// print PHP_EOL;
// print '$render_block_content :' . $render_block_content;
// print PHP_EOL;
// print '$test[expected] :' . $test['expected'];
// print PHP_EOL;
// print PHP_EOL;
// print 'get_block_wrapper_attributes() :';
// var_dump(get_block_wrapper_attributes());
// print PHP_EOL;
// print PHP_EOL;
// print 'correct :';
// var_dump($correct);
// print PHP_EOL;

$blog_card_data = VK_Blocks_Blog_Card::vk_get_blog_card_data('https://www.vektor-inc.co.jp/');
if (!empty($test['cannot_embed']) && !empty($blog_card_data['cannot_embed'])) {
$this->assertSame( $cannot_embed_correct, $render_block_content );
if ( is_array($correct) ) {
$this->assertContains($render_block_content, $correct);
} else {
$this->assertSame( $correct, $render_block_content );
}
Expand Down

0 comments on commit 16d996a

Please sign in to comment.