wordpress-develop/tests/phpunit/tests/attachment/slashes.php
Gary Pendergast 8f95800d52 Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
2017-11-30 23:09:33 +00:00

61 lines
1.9 KiB
PHP

<?php
/**
* @group attachment
* @group slashes
* @ticket 21767
*/
class Tests_Attachment_Slashes extends WP_UnitTestCase {
function setUp() {
parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
wp_set_current_user( $this->author_id );
// it is important to test with both even and odd numbered slashes as
// kses does a strip-then-add slashes in some of its function calls
$this->slash_1 = 'String with 1 slash \\';
$this->slash_2 = 'String with 2 slashes \\\\';
$this->slash_3 = 'String with 3 slashes \\\\\\';
$this->slash_4 = 'String with 4 slashes \\\\\\\\';
$this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
$this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
}
/**
* Tests the model function that expects slashed data
*/
function test_wp_insert_attachment() {
$id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => $this->slash_1,
'post_content_filtered' => $this->slash_3,
'post_excerpt' => $this->slash_5,
'post_type' => 'post',
)
);
$post = get_post( $id );
$this->assertEquals( wp_unslash( $this->slash_1 ), $post->post_title );
$this->assertEquals( wp_unslash( $this->slash_3 ), $post->post_content_filtered );
$this->assertEquals( wp_unslash( $this->slash_5 ), $post->post_excerpt );
$id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => $this->slash_2,
'post_content_filtered' => $this->slash_4,
'post_excerpt' => $this->slash_6,
'post_type' => 'post',
)
);
$post = get_post( $id );
$this->assertEquals( wp_unslash( $this->slash_2 ), $post->post_title );
$this->assertEquals( wp_unslash( $this->slash_4 ), $post->post_content_filtered );
$this->assertEquals( wp_unslash( $this->slash_6 ), $post->post_excerpt );
}
}