New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for post title block render function #42435
base: trunk
Are you sure you want to change the base?
Add unit test for post title block render function #42435
Conversation
@draganescu Can you please review this PR ? |
waiting for PR review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the test and the test passes and it's a great addition. Thank you 👏🏻
Thank you @draganescu. @Mamaduka can we merge this PR ? |
public static function wpSetUpBeforeClass() { | ||
self::$post = self::factory()->post->create_and_get( array( 'post_title' => 'Post title block Unit Test' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static function wpSetUpBeforeClass() { | |
self::$post = self::factory()->post->create_and_get( array( 'post_title' => 'Post title block Unit Test' ) ); | |
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | |
self::$post = $factory->post->create_and_get( array( 'post_title' => 'Post title block Unit Test' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review @spacedmonkey. I have updated the code according to your suggestion.
waiting for PR review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find my notes below.
Thanks.
@anton-vlasenko Feedback addressed. Can you please review again. |
… add-test-for-post-title-block-render
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test files should be named using camelCase.
Could the test file be renamed to renderBlockCorePostTitle.php
?
<?php | ||
/** | ||
* Post Title rendering tests. | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
* @covers ::gutenberg_render_block_core_post_title | ||
*/ | ||
|
||
/** | ||
* Tests for the Post Title block. | ||
* | ||
* @group blocks | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this a single docblock for simplicity.
<?php | |
/** | |
* Post Title rendering tests. | |
* | |
* @package WordPress | |
* @subpackage Blocks | |
* @covers ::gutenberg_render_block_core_post_title | |
*/ | |
/** | |
* Tests for the Post Title block. | |
* | |
* @group blocks | |
*/ | |
<?php | |
/** | |
* Tests for the gutenberg_render_block_core_post_title() function. | |
* | |
* @package WordPress | |
* @subpackage Blocks | |
* | |
* @group blocks | |
* | |
* @covers ::gutenberg_render_block_core_post_title | |
*/ |
/** | ||
* Test gutenberg_render_block_core_post_title() method. | ||
* | ||
* @covers ::gutenberg_render_block_core_post_title | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to use the @Covers tag for individual test methods if you have it defined in the header.
/** | |
* Test gutenberg_render_block_core_post_title() method. | |
* | |
* @covers ::gutenberg_render_block_core_post_title | |
*/ | |
/** | |
* Test gutenberg_render_block_core_post_title() method. | |
*/ |
* | ||
* @group blocks | ||
*/ | ||
class Tests_Blocks_GutenbergRenderBlockCorePostTitle extends WP_UnitTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class Tests_Blocks_GutenbergRenderBlockCorePostTitle extends WP_UnitTestCase { | |
class Tests_Blocks_RenderBlockCorePostTitle extends WP_UnitTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the standards you mentioned above, shouldn't we use the function name which is gutenberg_render_block_core_post_title()
in title case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong preference on this one.
It's up to you.
If the code is going to be merged into WordPress Core at some point, I'd suggest aligning it with WordPress Core standards to ease the backporting efforts (and increase the chances of acceptance).
Is this the new standards that we are going to follow from now on for test file name? because all other files are named in kebab-case. |
No, this is not a new standard, but I agree, it might seem new. There are (mostly) old tests that don't follow this naming convention, and the newer ones that adhere to it, e.g.: https://github.com/WordPress/wordpress-develop/tree/trunk/tests/phpunit/tests/option |
@anton-vlasenko To follow the standard for file name of unit tests, It required to update phpunit config file first. |
… add-test-for-post-title-block-render
I have updated phpunit config temporary until we change all filenames to camel case as per wordpress core standard. And Addressed all feedback provided by reviewer. |
@anton-vlasenko can you please review this PR? |
What?
Added unit test for Post title core block render function.