Skip to content
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

Open
wants to merge 18 commits into
base: trunk
Choose a base branch
from

Conversation

akasunil
Copy link
Contributor

What?

Added unit test for Post title core block render function.

@akasunil
Copy link
Contributor Author

@draganescu Can you please review this PR ?

@ntsekouras ntsekouras added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Jul 15, 2022
@akasunil
Copy link
Contributor Author

waiting for PR review

draganescu
draganescu previously approved these changes Nov 10, 2022
Copy link
Contributor

@draganescu draganescu left a 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 👏🏻

@akasunil
Copy link
Contributor Author

Thank you @draganescu. @Mamaduka can we merge this PR ?

Comment on lines 32 to 33
public static function wpSetUpBeforeClass() {
self::$post = self::factory()->post->create_and_get( array( 'post_title' => 'Post title block Unit Test' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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' ) );

Copy link
Contributor Author

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.

@akasunil
Copy link
Contributor Author

akasunil commented Jan 2, 2023

waiting for PR review

Copy link
Contributor

@anton-vlasenko anton-vlasenko left a 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.

phpunit/blocks/render-block-post-title-test.php Outdated Show resolved Hide resolved
phpunit/blocks/render-block-post-title-test.php Outdated Show resolved Hide resolved
phpunit/blocks/render-block-post-title-test.php Outdated Show resolved Hide resolved
@draganescu draganescu changed the title Add Unitest for post title block render function Add unit test for post title block render function Jan 6, 2023
@akasunil akasunil requested review from anton-vlasenko and removed request for TimothyBJacobs January 28, 2023 15:57
@akasunil
Copy link
Contributor Author

@anton-vlasenko Feedback addressed. Can you please review again.

Copy link

github-actions bot commented Feb 26, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: akasunil <sunil25393@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Co-authored-by: spacedmonkey <spacedmonkey@git.wordpress.org>
Co-authored-by: anton-vlasenko <antonvlasenko@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@anton-vlasenko anton-vlasenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#test-classes:

Test files should be named using camelCase.

Could the test file be renamed to renderBlockCorePostTitle.php?

Comment on lines 1 to 14
<?php
/**
* Post Title rendering tests.
*
* @package WordPress
* @subpackage Blocks
* @covers ::gutenberg_render_block_core_post_title
*/

/**
* Tests for the Post Title block.
*
* @group blocks
*/
Copy link
Contributor

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.

Suggested change
<?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
*/

Comment on lines 84 to 88
/**
* Test gutenberg_render_block_core_post_title() method.
*
* @covers ::gutenberg_render_block_core_post_title
*/
Copy link
Contributor

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.

Suggested change
/**
* 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Tests_Blocks_GutenbergRenderBlockCorePostTitle extends WP_UnitTestCase {
class Tests_Blocks_RenderBlockCorePostTitle extends WP_UnitTestCase {

Copy link
Contributor Author

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?

Copy link
Contributor

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).

@akasunil
Copy link
Contributor Author

akasunil commented Mar 2, 2024

Could the test file be renamed to renderBlockCorePostTitle.php?

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.

@anton-vlasenko
Copy link
Contributor

anton-vlasenko commented Mar 4, 2024

Could the test file be renamed to renderBlockCorePostTitle.php?

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

@akasunil
Copy link
Contributor Author

akasunil commented Mar 8, 2024

@anton-vlasenko To follow the standard for file name of unit tests, It required to update phpunit config file first.

@akasunil akasunil marked this pull request as draft April 19, 2024 08:55
@akasunil akasunil marked this pull request as ready for review April 28, 2024 08:21
@akasunil
Copy link
Contributor Author

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.

@akasunil
Copy link
Contributor Author

@anton-vlasenko can you please review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants