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

added unit test cases for filter functions #55

Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions lib/compat/wordpress-6.7/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@
* @return array The updated array of comment types.
*/
if ( ! function_exists( 'update_get_avatar_comment_type' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) {
function update_get_avatar_comment_type( $comment_type ) {
$comment_type[] = 'block_comment';
return $comment_type;
}
add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type', 10, 1 );
function update_get_avatar_comment_type( $comment_type ) {

Check failure on line 152 in lib/compat/wordpress-6.7/rest-api.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
$comment_type[] = 'block_comment';
return $comment_type;

Check failure on line 155 in lib/compat/wordpress-6.7/rest-api.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
}

Check failure on line 156 in lib/compat/wordpress-6.7/rest-api.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Function closing brace must go on the next line following the body; found 1 blank lines before brace
add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type', 10, 1 );
}

/**
Expand All @@ -169,7 +169,7 @@
if ( ! function_exists( 'update_comment_type_filter_dropdown' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) {
function update_comment_type_filter_dropdown() {
return array(
'comment' => __( 'Comments' ),

Check warning on line 172 in lib/compat/wordpress-6.7/rest-api.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 7 space(s) between "'comment'" and double arrow, but found 1.
'block_comment' => __( 'Block Comments' ),
);
}
Expand Down
1 change: 1 addition & 0 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function fail_if_died( $message ) {
'gutenberg-form-blocks' => 1,
'gutenberg-block-experiments' => 1,
'gutenberg-media-processing' => 1,
'gutenberg-block-comment' => 1,
),
);

Expand Down
62 changes: 62 additions & 0 deletions phpunit/class-block-comment-filter-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* This class contains unit tests for the block comment filter functions.
*
* @package Gutenberg
*/
class Tests_blockCommentFilter extends WP_UnitTestCase {

/**

Check failure on line 10 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
* Tests that `update_comment_type_in_rest_api_6_7` updates comment type correctly.

Check failure on line 11 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
*/

Check failure on line 12 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
public function test_update_comment_type_in_rest_api_6_7() {

Check failure on line 13 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
// Mock request and prepared comment

Check failure on line 14 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
$request = new WP_REST_Request(WP_REST_Server::READABLE);

Check failure on line 15 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 15 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces after opening parenthesis; 0 found
$request->set_param('comment_type', 'block_comment');
$request->set_param('comment_approved', '1');

$prepared_comment = array(
'comment_type' => '',
'comment_approved' => '0',
);

// Call the function
$updated_comment = update_comment_type_in_rest_api_6_7($prepared_comment, $request);

// Assertions
$this->assertEquals('block_comment', $updated_comment['comment_type']);
$this->assertEquals('1', $updated_comment['comment_approved']);
}

/**

Check warning on line 32 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found precision alignment of 1 spaces.
* Tests that `update_get_avatar_comment_type` adds 'block_comment' to the array.
*/
public function test_update_get_avatar_comment_type() {

// Mock comment types
$comment_types = array('comment', 'pingback');

// Call the function
$updated_comment_types = update_get_avatar_comment_type($comment_types);

// Assertions
$this->assertContains('block_comment', $updated_comment_types);
}

/**
* Tests that `update_comment_type_filter_dropdown` returns the correct options.
*/
public function test_update_comment_type_filter_dropdown() {

// Call the function
$dropdown_options = update_comment_type_filter_dropdown();

// Assertions
$this->assertArrayHasKey('comment', $dropdown_options);
$this->assertArrayHasKey('block_comment', $dropdown_options);
$this->assertEquals(__('Comments'), $dropdown_options['comment']);

Check warning on line 58 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Missing $domain parameter in function call to __(). If this text string is supposed to use a WP Core translation, use the "default" text domain.
$this->assertEquals(__('Block Comments'), $dropdown_options['block_comment']);

Check warning on line 59 in phpunit/class-block-comment-filter-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Missing $domain parameter in function call to __(). If this text string is supposed to use a WP Core translation, use the "default" text domain.
}

}
Loading