wordpress-develop/tests/phpunit/tests/formatting/stripslashesDeep.php
Sergey Biryukov 4d2762ed93 Tests: Rename classes in phpunit/tests/formatting/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51623 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-16 21:33:54 +00:00

55 lines
1.7 KiB
PHP

<?php
/**
* @group formatting
* @group slashes
*/
class Tests_Formatting_StripslashesDeep extends WP_UnitTestCase {
/**
* @ticket 18026
*/
function test_preserves_original_datatype() {
$this->assertTrue( stripslashes_deep( true ) );
$this->assertFalse( stripslashes_deep( false ) );
$this->assertSame( 4, stripslashes_deep( 4 ) );
$this->assertSame( 'foo', stripslashes_deep( 'foo' ) );
$arr = array(
'a' => true,
'b' => false,
'c' => 4,
'd' => 'foo',
);
$arr['e'] = $arr; // Add a sub-array.
$this->assertSame( $arr, stripslashes_deep( $arr ) ); // Keyed array.
$this->assertSame( array_values( $arr ), stripslashes_deep( array_values( $arr ) ) ); // Non-keyed.
$obj = new stdClass;
foreach ( $arr as $k => $v ) {
$obj->$k = $v;
}
$this->assertSame( $obj, stripslashes_deep( $obj ) );
}
function test_strips_slashes() {
$old = "I can\'t see, isn\'t that it?";
$new = "I can't see, isn't that it?";
$this->assertSame( $new, stripslashes_deep( $old ) );
$this->assertSame( $new, stripslashes_deep( "I can\\'t see, isn\\'t that it?" ) );
$this->assertSame( array( 'a' => $new ), stripslashes_deep( array( 'a' => $old ) ) ); // Keyed array.
$this->assertSame( array( $new ), stripslashes_deep( array( $old ) ) ); // Non-keyed.
$obj_old = new stdClass;
$obj_old->a = $old;
$obj_new = new stdClass;
$obj_new->a = $new;
$this->assertEquals( $obj_new, stripslashes_deep( $obj_old ) );
}
function test_permits_escaped_slash() {
$txt = "I can't see, isn\'t that it?";
$this->assertSame( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) );
$this->assertSame( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) );
}
}