From 4e62497442cd30ae2591aa2f6d043d002a82c5f1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 13 Feb 2023 19:11:15 +0000 Subject: [PATCH] Tests: Move `wp_comments_personal_data_exporter()` tests to their own file. This aims to make the tests more discoverable and easier to expand. Follow-up to [42987], [55319]. See #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@55321 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/comment.php | 131 ------------------ .../wpCommentsPersonalDataExporter.php | 129 +++++++++++++++++ 2 files changed, 129 insertions(+), 131 deletions(-) create mode 100644 tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index b65452a730..641b055ad4 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -1236,135 +1236,4 @@ class Tests_Comment extends WP_UnitTestCase { $this->assertSame( '1', $comment->comment_approved ); } - - /** - * Testing the `wp_comments_personal_data_exporter()` function. - * - * @group privacy - * @ticket 43440 - * - * @covers ::wp_comments_personal_data_exporter - */ - public function test_wp_comments_personal_data_exporter() { - $args = array( - 'comment_post_ID' => self::$post_id, - 'comment_author' => 'Comment Author', - 'comment_author_email' => 'personal@local.host', - 'comment_author_url' => 'https://local.host/', - 'comment_author_IP' => '192.168.0.1', - 'comment_agent' => 'SOME_AGENT', - 'comment_date' => '2018-03-28 20:05:00', - 'comment_content' => 'Comment', - ); - - $comment_id = self::factory()->comment->create( $args ); - - $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); - $expected = $args; - - $this->assertTrue( $actual['done'] ); - - // Number of exported comments. - $this->assertCount( 1, $actual['data'] ); - - // Number of exported comment properties. - $this->assertCount( 8, $actual['data'][0]['data'] ); - - // Exported group. - $this->assertSame( 'comments', $actual['data'][0]['group_id'] ); - $this->assertSame( 'Comments', $actual['data'][0]['group_label'] ); - - // Exported comment properties. - $this->assertSame( $expected['comment_author'], $actual['data'][0]['data'][0]['value'] ); - $this->assertSame( $expected['comment_author_email'], $actual['data'][0]['data'][1]['value'] ); - $this->assertSame( $expected['comment_author_url'], $actual['data'][0]['data'][2]['value'] ); - $this->assertSame( $expected['comment_author_IP'], $actual['data'][0]['data'][3]['value'] ); - $this->assertSame( $expected['comment_agent'], $actual['data'][0]['data'][4]['value'] ); - $this->assertSame( $expected['comment_date'], $actual['data'][0]['data'][5]['value'] ); - $this->assertSame( $expected['comment_content'], $actual['data'][0]['data'][6]['value'] ); - $this->assertSame( esc_html( get_comment_link( $comment_id ) ), strip_tags( $actual['data'][0]['data'][7]['value'] ) ); - } - - /** - * Testing the `wp_comments_personal_data_exporter()` function for no comments found. - * - * @group privacy - * @ticket 43440 - * - * @covers ::wp_comments_personal_data_exporter - */ - public function test_wp_comments_personal_data_exporter_no_comments_found() { - - $actual = wp_comments_personal_data_exporter( 'nocommentsfound@local.host' ); - - $expected = array( - 'data' => array(), - 'done' => true, - ); - - $this->assertSame( $expected, $actual ); - } - - /** - * Testing the `wp_comments_personal_data_exporter()` function for an empty comment property. - * - * @group privacy - * @ticket 43440 - * - * @covers ::wp_comments_personal_data_exporter - */ - public function test_wp_comments_personal_data_exporter_empty_comment_prop() { - $args = array( - 'comment_post_ID' => self::$post_id, - 'comment_author' => 'Comment Author', - 'comment_author_email' => 'personal@local.host', - 'comment_author_url' => 'https://local.host/', - 'comment_author_IP' => '192.168.0.1', - 'comment_date' => '2018-03-28 20:05:00', - 'comment_agent' => '', - 'comment_content' => 'Comment', - ); - - $c = self::factory()->comment->create( $args ); - - $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); - - $this->assertTrue( $actual['done'] ); - - // Number of exported comments. - $this->assertCount( 1, $actual['data'] ); - - // Number of exported comment properties. - $this->assertCount( 7, $actual['data'][0]['data'] ); - } - - /** - * Testing the `wp_comments_personal_data_exporter()` function with an empty second page. - * - * @group privacy - * @ticket 43440 - * - * @covers ::wp_comments_personal_data_exporter - */ - public function test_wp_comments_personal_data_exporter_empty_second_page() { - $args = array( - 'comment_post_ID' => self::$post_id, - 'comment_author' => 'Comment Author', - 'comment_author_email' => 'personal@local.host', - 'comment_author_url' => 'https://local.host/', - 'comment_author_IP' => '192.168.0.1', - 'comment_date' => '2018-03-28 20:05:00', - 'comment_agent' => 'SOME_AGENT', - 'comment_content' => 'Comment', - ); - - $c = self::factory()->comment->create( $args ); - - $actual = wp_comments_personal_data_exporter( $args['comment_author_email'], 2 ); - - $this->assertTrue( $actual['done'] ); - - // Number of exported comments. - $this->assertCount( 0, $actual['data'] ); - } } diff --git a/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php b/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php new file mode 100644 index 0000000000..ac539a8939 --- /dev/null +++ b/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php @@ -0,0 +1,129 @@ + self::$post_id, + 'comment_author' => 'Comment Author', + 'comment_author_email' => 'personal@local.host', + 'comment_author_url' => 'https://local.host/', + 'comment_author_IP' => '192.168.0.1', + 'comment_agent' => 'SOME_AGENT', + 'comment_date' => '2018-03-28 20:05:00', + 'comment_content' => 'Comment', + ); + + $comment_id = self::factory()->comment->create( $args ); + + $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); + $expected = $args; + + $this->assertTrue( $actual['done'] ); + + // Number of exported comments. + $this->assertCount( 1, $actual['data'] ); + + // Number of exported comment properties. + $this->assertCount( 8, $actual['data'][0]['data'] ); + + // Exported group. + $this->assertSame( 'comments', $actual['data'][0]['group_id'] ); + $this->assertSame( 'Comments', $actual['data'][0]['group_label'] ); + + // Exported comment properties. + $this->assertSame( $expected['comment_author'], $actual['data'][0]['data'][0]['value'] ); + $this->assertSame( $expected['comment_author_email'], $actual['data'][0]['data'][1]['value'] ); + $this->assertSame( $expected['comment_author_url'], $actual['data'][0]['data'][2]['value'] ); + $this->assertSame( $expected['comment_author_IP'], $actual['data'][0]['data'][3]['value'] ); + $this->assertSame( $expected['comment_agent'], $actual['data'][0]['data'][4]['value'] ); + $this->assertSame( $expected['comment_date'], $actual['data'][0]['data'][5]['value'] ); + $this->assertSame( $expected['comment_content'], $actual['data'][0]['data'][6]['value'] ); + $this->assertSame( esc_html( get_comment_link( $comment_id ) ), strip_tags( $actual['data'][0]['data'][7]['value'] ) ); + } + + /** + * Testing the `wp_comments_personal_data_exporter()` function for no comments found. + * + * @ticket 43440 + */ + public function test_wp_comments_personal_data_exporter_no_comments_found() { + + $actual = wp_comments_personal_data_exporter( 'nocommentsfound@local.host' ); + + $expected = array( + 'data' => array(), + 'done' => true, + ); + + $this->assertSame( $expected, $actual ); + } + + /** + * Testing the `wp_comments_personal_data_exporter()` function for an empty comment property. + * + * @ticket 43440 + */ + public function test_wp_comments_personal_data_exporter_empty_comment_prop() { + $args = array( + 'comment_post_ID' => self::$post_id, + 'comment_author' => 'Comment Author', + 'comment_author_email' => 'personal@local.host', + 'comment_author_url' => 'https://local.host/', + 'comment_author_IP' => '192.168.0.1', + 'comment_date' => '2018-03-28 20:05:00', + 'comment_agent' => '', + 'comment_content' => 'Comment', + ); + + $c = self::factory()->comment->create( $args ); + + $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); + + $this->assertTrue( $actual['done'] ); + + // Number of exported comments. + $this->assertCount( 1, $actual['data'] ); + + // Number of exported comment properties. + $this->assertCount( 7, $actual['data'][0]['data'] ); + } + + /** + * Testing the `wp_comments_personal_data_exporter()` function with an empty second page. + * + * @ticket 43440 + */ + public function test_wp_comments_personal_data_exporter_empty_second_page() { + $args = array( + 'comment_post_ID' => self::$post_id, + 'comment_author' => 'Comment Author', + 'comment_author_email' => 'personal@local.host', + 'comment_author_url' => 'https://local.host/', + 'comment_author_IP' => '192.168.0.1', + 'comment_date' => '2018-03-28 20:05:00', + 'comment_agent' => 'SOME_AGENT', + 'comment_content' => 'Comment', + ); + + $c = self::factory()->comment->create( $args ); + + $actual = wp_comments_personal_data_exporter( $args['comment_author_email'], 2 ); + + $this->assertTrue( $actual['done'] ); + + // Number of exported comments. + $this->assertCount( 0, $actual['data'] ); + } +}