mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-11 08:04:32 +00:00
> PHPUnit 8.0.0 introduced a `void` return type declaration to the "fixture" methods – `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()`. As the `void` return type was not introduced until PHP 7.1, this makes it more difficult to create cross-version compatible tests when using fixtures, due to signature mismatches. > > The `Yoast\PHPUnitPolyfills\TestCases\TestCase` overcomes the signature mismatch by having two versions. The correct one will be loaded depending on the PHPUnit version being used. > > When using this TestCase, if an individual test, or another TestCase which extends this TestCase, needs to overload any of the "fixture" methods, it should do so by using a snake_case variant of the original fixture method name, i.e. `set_up_before_class()`, `set_up()`, `assert_pre_conditions()`, `assert_post_conditions()`, `tear_down()`, and `tear_down_after_class()`. > > The snake_case methods will automatically be called by PHPUnit. > > > IMPORTANT: The snake_case methods should not call the PHPUnit parent, i.e. do not use `parent::setUp()` from within an overloaded `set_up()` method. If necessary, DO call `parent::set_up()`. Reference: https://github.com/Yoast/PHPUnit-Polyfills#testcases This commit renames all declared fixture methods, and calls to parent versions of those fixture methods, from camelCase to snake_case. Follow-up to [51559-51567]. Props jrf, hellofromTonya, johnbillion, netweb, dd32, pputzer, SergeyBiryukov. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51568 602fd350-edb4-49c9-b593-d223f7449a82
130 lines
3.4 KiB
PHP
130 lines
3.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group term
|
|
* @group slashes
|
|
* @ticket 21767
|
|
*/
|
|
class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
|
|
protected static $author_id;
|
|
|
|
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) );
|
|
}
|
|
|
|
function set_up() {
|
|
parent::set_up();
|
|
|
|
wp_set_current_user( self::$author_id );
|
|
|
|
$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_term() {
|
|
$taxonomies = array(
|
|
'category',
|
|
'post_tag',
|
|
);
|
|
foreach ( $taxonomies as $taxonomy ) {
|
|
$insert = wp_insert_term(
|
|
$this->slash_1,
|
|
$taxonomy,
|
|
array(
|
|
'slug' => 'slash_test_1_' . $taxonomy,
|
|
'description' => $this->slash_3,
|
|
)
|
|
);
|
|
$term = get_term( $insert['term_id'], $taxonomy );
|
|
$this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
|
|
$this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
|
|
|
|
$insert = wp_insert_term(
|
|
$this->slash_3,
|
|
$taxonomy,
|
|
array(
|
|
'slug' => 'slash_test_2_' . $taxonomy,
|
|
'description' => $this->slash_5,
|
|
)
|
|
);
|
|
$term = get_term( $insert['term_id'], $taxonomy );
|
|
$this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
|
|
$this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
|
|
|
|
$insert = wp_insert_term(
|
|
$this->slash_2,
|
|
$taxonomy,
|
|
array(
|
|
'slug' => 'slash_test_3_' . $taxonomy,
|
|
'description' => $this->slash_4,
|
|
)
|
|
);
|
|
$term = get_term( $insert['term_id'], $taxonomy );
|
|
$this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
|
|
$this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Tests the model function that expects slashed data.
|
|
*/
|
|
function test_wp_update_term() {
|
|
$taxonomies = array(
|
|
'category',
|
|
'post_tag',
|
|
);
|
|
foreach ( $taxonomies as $taxonomy ) {
|
|
$term_id = self::factory()->term->create(
|
|
array(
|
|
'taxonomy' => $taxonomy,
|
|
)
|
|
);
|
|
|
|
$update = wp_update_term(
|
|
$term_id,
|
|
$taxonomy,
|
|
array(
|
|
'name' => $this->slash_1,
|
|
'description' => $this->slash_3,
|
|
)
|
|
);
|
|
|
|
$term = get_term( $term_id, $taxonomy );
|
|
$this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
|
|
$this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
|
|
|
|
$update = wp_update_term(
|
|
$term_id,
|
|
$taxonomy,
|
|
array(
|
|
'name' => $this->slash_3,
|
|
'description' => $this->slash_5,
|
|
)
|
|
);
|
|
$term = get_term( $term_id, $taxonomy );
|
|
$this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
|
|
$this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
|
|
|
|
$update = wp_update_term(
|
|
$term_id,
|
|
$taxonomy,
|
|
array(
|
|
'name' => $this->slash_2,
|
|
'description' => $this->slash_4,
|
|
)
|
|
);
|
|
$term = get_term( $term_id, $taxonomy );
|
|
$this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
|
|
$this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
|
|
}
|
|
}
|
|
}
|