Tests: Permalink Structures Phase II: DRY up logic for setting permalink structures in test methods.

Renames `reset_permalinks()` to `set_permalink_structure()` (mimicking `$wp_rewrite->set_permalink_structure()`) and allows it to accept an optional permalink structure. In this way, we can double dip using it to both set and reset the permalink structure from anywhere.

Removes alot of duplicated code from tests.

See #33968.


git-svn-id: https://develop.svn.wordpress.org/trunk@34810 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes
2015-10-03 20:54:11 +00:00
parent eebe549408
commit 0ea2acb720
15 changed files with 82 additions and 264 deletions

View File

@@ -169,10 +169,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_be_suffixed() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -187,10 +184,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_not_be_suffixed_for_already_published_posts() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -206,10 +200,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_yearlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_year_archives() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -224,10 +215,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_slugs_resulting_in_permalinks_that_resemble_month_archives_should_be_suffixed() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -242,10 +230,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_monthlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_month_archives() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/foo/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/foo/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -260,10 +245,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_monthlike_slugs_should_not_be_suffixed_for_invalid_month_numbers() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -278,10 +260,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_slugs_resulting_in_permalinks_that_resemble_day_archives_should_be_suffixed() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -296,10 +275,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_daylike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_day_archives() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',
@@ -314,10 +290,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @ticket 5305
*/
public function test_daylike_slugs_should_not_be_suffixed_for_invalid_day_numbers() {
global $wp_rewrite;
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
$wp_rewrite->flush_rules();
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
$p = $this->factory->post->create( array(
'post_type' => 'post',