From 9f7bfa9805ca03e87e14996ed47679a4edfe108d Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 14 Oct 2015 21:29:59 +0000 Subject: [PATCH] Share fixtures in `Tests_Get_Archives`. See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35163 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions/getArchives.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/functions/getArchives.php b/tests/phpunit/tests/functions/getArchives.php index b8596d7810..c64496b879 100644 --- a/tests/phpunit/tests/functions/getArchives.php +++ b/tests/phpunit/tests/functions/getArchives.php @@ -8,7 +8,7 @@ $defaults = array( ); */ class Tests_Get_Archives extends WP_UnitTestCase { - protected $post_ids; + protected static $post_ids; protected $month_url; function setUp() { @@ -16,7 +16,21 @@ class Tests_Get_Archives extends WP_UnitTestCase { $this->month_url = get_month_link( date( 'Y' ), date( 'm' ) ); $this->year_url = get_year_link( date( 'Y' ) ); - $this->post_ids = $this->factory->post->create_many( 8, array( 'post_type' => 'post', 'post_author' => '1' ) ); + } + + public static function setUpBeforeClass() { + $factory = new WP_UnitTest_Factory(); + self::$post_ids = $factory->post->create_many( 8, array( 'post_type' => 'post', 'post_author' => '1' ) ); + + self::commit_transaction(); + } + + public static function tearDownAfterClass() { + foreach ( self::$post_ids as $post_id ) { + wp_delete_post( $post_id, true ); + } + + self::commit_transaction(); } function test_wp_get_archives_default() { @@ -30,7 +44,7 @@ class Tests_Get_Archives extends WP_UnitTestCase { } function test_wp_get_archives_limit() { - $ids = array_slice( array_reverse( $this->post_ids ), 0, 5 ); + $ids = array_slice( array_reverse( self::$post_ids ), 0, 5 ); $link1 = get_permalink( $ids[0] ); $link2 = get_permalink( $ids[1] );