wordpress-develop/tests/phpunit/tests/canonical/pageOnFront.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

72 lines
2.0 KiB
PHP

<?php
/**
* @group canonical
* @group rewrite
* @group query
*/
class Tests_Canonical_PageOnFront extends WP_Canonical_UnitTestCase {
function set_up() {
parent::set_up();
update_option( 'show_on_front', 'page' );
update_option(
'page_for_posts',
self::factory()->post->create(
array(
'post_title' => 'blog-page',
'post_type' => 'page',
)
)
);
update_option(
'page_on_front',
self::factory()->post->create(
array(
'post_title' => 'front-page',
'post_type' => 'page',
'post_content' => "Page 1\n<!--nextpage-->\nPage 2",
)
)
);
}
/**
* @dataProvider data
*/
function test( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) {
$this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong );
}
function data() {
/*
* Data format:
* [0]: Test URL.
* [1]: Expected results: Any of the following can be used.
* array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
* array( expected query vars to be set, same as 'qv' above )
* (string) expected redirect location
* [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
*/
return array(
// Check against an odd redirect.
array( '/page/2/', '/page/2/' ),
array( '/?page=2', '/page/2/' ),
array( '/page/1/', '/' ),
array( '/?page=1', '/' ),
// The page designated as the front page should redirect to the front of the site.
array( '/front-page/', '/' ),
// The front page supports the <!--nextpage--> pagination.
array( '/front-page/2/', '/page/2/' ),
array( '/front-page/?page=2', '/page/2/' ),
// The posts page does not support the <!--nextpage--> pagination.
array( '/blog-page/2/', '/blog-page/' ),
array( '/blog-page/?page=2', '/blog-page/' ),
// The posts page supports regular pagination.
array( '/blog-page/?paged=2', '/blog-page/page/2/' ),
);
}
}