Make WordPress Core


Ignore:
Timestamp:
02/13/2023 07:11:15 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r55320 r55321  
    12371237        $this->assertSame( '1', $comment->comment_approved );
    12381238    }
    1239 
    1240     /**
    1241      * Testing the `wp_comments_personal_data_exporter()` function.
    1242      *
    1243      * @group privacy
    1244      * @ticket 43440
    1245      *
    1246      * @covers ::wp_comments_personal_data_exporter
    1247      */
    1248     public function test_wp_comments_personal_data_exporter() {
    1249         $args = array(
    1250             'comment_post_ID'      => self::$post_id,
    1251             'comment_author'       => 'Comment Author',
    1252             'comment_author_email' => 'personal@local.host',
    1253             'comment_author_url'   => 'https://local.host/',
    1254             'comment_author_IP'    => '192.168.0.1',
    1255             'comment_agent'        => 'SOME_AGENT',
    1256             'comment_date'         => '2018-03-28 20:05:00',
    1257             'comment_content'      => 'Comment',
    1258         );
    1259 
    1260         $comment_id = self::factory()->comment->create( $args );
    1261 
    1262         $actual   = wp_comments_personal_data_exporter( $args['comment_author_email'] );
    1263         $expected = $args;
    1264 
    1265         $this->assertTrue( $actual['done'] );
    1266 
    1267         // Number of exported comments.
    1268         $this->assertCount( 1, $actual['data'] );
    1269 
    1270         // Number of exported comment properties.
    1271         $this->assertCount( 8, $actual['data'][0]['data'] );
    1272 
    1273         // Exported group.
    1274         $this->assertSame( 'comments', $actual['data'][0]['group_id'] );
    1275         $this->assertSame( 'Comments', $actual['data'][0]['group_label'] );
    1276 
    1277         // Exported comment properties.
    1278         $this->assertSame( $expected['comment_author'], $actual['data'][0]['data'][0]['value'] );
    1279         $this->assertSame( $expected['comment_author_email'], $actual['data'][0]['data'][1]['value'] );
    1280         $this->assertSame( $expected['comment_author_url'], $actual['data'][0]['data'][2]['value'] );
    1281         $this->assertSame( $expected['comment_author_IP'], $actual['data'][0]['data'][3]['value'] );
    1282         $this->assertSame( $expected['comment_agent'], $actual['data'][0]['data'][4]['value'] );
    1283         $this->assertSame( $expected['comment_date'], $actual['data'][0]['data'][5]['value'] );
    1284         $this->assertSame( $expected['comment_content'], $actual['data'][0]['data'][6]['value'] );
    1285         $this->assertSame( esc_html( get_comment_link( $comment_id ) ), strip_tags( $actual['data'][0]['data'][7]['value'] ) );
    1286     }
    1287 
    1288     /**
    1289      * Testing the `wp_comments_personal_data_exporter()` function for no comments found.
    1290      *
    1291      * @group privacy
    1292      * @ticket 43440
    1293      *
    1294      * @covers ::wp_comments_personal_data_exporter
    1295      */
    1296     public function test_wp_comments_personal_data_exporter_no_comments_found() {
    1297 
    1298         $actual = wp_comments_personal_data_exporter( 'nocommentsfound@local.host' );
    1299 
    1300         $expected = array(
    1301             'data' => array(),
    1302             'done' => true,
    1303         );
    1304 
    1305         $this->assertSame( $expected, $actual );
    1306     }
    1307 
    1308     /**
    1309      * Testing the `wp_comments_personal_data_exporter()` function for an empty comment property.
    1310      *
    1311      * @group privacy
    1312      * @ticket 43440
    1313      *
    1314      * @covers ::wp_comments_personal_data_exporter
    1315      */
    1316     public function test_wp_comments_personal_data_exporter_empty_comment_prop() {
    1317         $args = array(
    1318             'comment_post_ID'      => self::$post_id,
    1319             'comment_author'       => 'Comment Author',
    1320             'comment_author_email' => 'personal@local.host',
    1321             'comment_author_url'   => 'https://local.host/',
    1322             'comment_author_IP'    => '192.168.0.1',
    1323             'comment_date'         => '2018-03-28 20:05:00',
    1324             'comment_agent'        => '',
    1325             'comment_content'      => 'Comment',
    1326         );
    1327 
    1328         $c = self::factory()->comment->create( $args );
    1329 
    1330         $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] );
    1331 
    1332         $this->assertTrue( $actual['done'] );
    1333 
    1334         // Number of exported comments.
    1335         $this->assertCount( 1, $actual['data'] );
    1336 
    1337         // Number of exported comment properties.
    1338         $this->assertCount( 7, $actual['data'][0]['data'] );
    1339     }
    1340 
    1341     /**
    1342      * Testing the `wp_comments_personal_data_exporter()` function with an empty second page.
    1343      *
    1344      * @group privacy
    1345      * @ticket 43440
    1346      *
    1347      * @covers ::wp_comments_personal_data_exporter
    1348      */
    1349     public function test_wp_comments_personal_data_exporter_empty_second_page() {
    1350         $args = array(
    1351             'comment_post_ID'      => self::$post_id,
    1352             'comment_author'       => 'Comment Author',
    1353             'comment_author_email' => 'personal@local.host',
    1354             'comment_author_url'   => 'https://local.host/',
    1355             'comment_author_IP'    => '192.168.0.1',
    1356             'comment_date'         => '2018-03-28 20:05:00',
    1357             'comment_agent'        => 'SOME_AGENT',
    1358             'comment_content'      => 'Comment',
    1359         );
    1360 
    1361         $c = self::factory()->comment->create( $args );
    1362 
    1363         $actual = wp_comments_personal_data_exporter( $args['comment_author_email'], 2 );
    1364 
    1365         $this->assertTrue( $actual['done'] );
    1366 
    1367         // Number of exported comments.
    1368         $this->assertCount( 0, $actual['data'] );
    1369     }
    13701239}
Note: See TracChangeset for help on using the changeset viewer.