Files
wordpress-develop/tests/phpunit/tests/term/getTermLink.php
Sergey Biryukov ddb409edca Build/Test Tools: Implement use of the void solution.
> 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
2021-08-07 10:29:41 +00:00

211 lines
4.5 KiB
PHP

<?php
/**
* @group taxonomy
*/
class Tests_Term_GetTermLink extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
register_taxonomy( 'wptests_tax', 'post' );
}
public function test_integer_should_be_interpreted_as_term_id() {
$t1 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'name' => 'foo',
)
);
$t2 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'slug' => $t1,
)
);
$term = (int) $t1;
$actual = get_term_link( $term, 'wptests_tax' );
$this->assertStringContainsString( 'wptests_tax=foo', $actual );
}
public function test_numeric_string_should_be_interpreted_as_term_slug() {
$t1 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'name' => 'foo',
)
);
$t2 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'slug' => $t1,
)
);
$term = (string) $t1;
$actual = get_term_link( $term, 'wptests_tax' );
$this->assertStringContainsString( 'wptests_tax=' . $term, $actual );
}
public function test_invalid_term_should_return_wp_error() {
$actual = get_term_link( 'foo', 'wptests_tax' );
$this->assertWPError( $actual );
}
public function test_category_should_use_cat_query_var_with_term_id() {
$c = self::factory()->category->create();
$actual = get_term_link( $c, 'category' );
$this->assertStringContainsString( 'cat=' . $c, $actual );
}
public function test_taxonomy_with_query_var_should_use_that_query_var_with_term_slug() {
register_taxonomy(
'wptests_tax2',
'post',
array(
'query_var' => 'foo',
)
);
$t = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'bar',
)
);
$actual = get_term_link( $t, 'wptests_tax2' );
$this->assertStringContainsString( 'foo=bar', $actual );
}
public function test_taxonomy_without_query_var_should_use_taxonomy_query_var_and_term_query_var_with_term_slug() {
register_taxonomy(
'wptests_tax2',
'post',
array(
'query_var' => false,
)
);
$t = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'bar',
)
);
$actual = get_term_link( $t, 'wptests_tax2' );
$this->assertStringContainsString( 'taxonomy=wptests_tax2', $actual );
$this->assertStringContainsString( 'term=bar', $actual );
}
/**
* @ticket 52882
*/
public function test_taxonomy_with_rewrite_false_and_custom_permalink_structure() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
register_taxonomy(
'wptests_tax2',
'post',
array(
'rewrite' => false,
)
);
add_permastruct( 'wptests_tax2', 'foo/%wptests_tax2%' );
$t = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'bar',
)
);
$actual = get_term_link( $t, 'wptests_tax2' );
remove_permastruct( 'wptests_tax2' );
$this->assertStringContainsString( '/foo/bar/', $actual );
}
public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
register_taxonomy(
'wptests_tax2',
'post',
array(
'hierarchical' => true,
'rewrite' => array(
'slug' => 'foo',
'hierarchical' => true,
),
)
);
flush_rewrite_rules();
$t1 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term1',
)
);
$t2 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term2',
'parent' => $t1,
)
);
$actual = get_term_link( $t2, 'wptests_tax2' );
$this->assertStringContainsString( '/foo/term1/term2/', $actual );
}
public function test_taxonomy_permastruct_with_nonhierarchical_rewrite_should_not_put_term_ancestors_in_link() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
register_taxonomy(
'wptests_tax2',
'post',
array(
'hierarchical' => true,
'rewrite' => array(
'slug' => 'foo',
'hierarchical' => false,
),
)
);
flush_rewrite_rules();
$t1 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term1',
)
);
$t2 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term2',
'parent' => $t1,
)
);
$actual = get_term_link( $t2, 'wptests_tax2' );
$this->assertStringContainsString( '/foo/term2/', $actual );
}
}