mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Unit Tests: one $factory to rule them all, and it shall be static.
Using more than one instance of `WP_UnitTest_Factory` causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use `setUpBeforeClass`, we were creating ad hoc instances. To avoid that, we were injecting one `static` instance via Dependency Injection in `wpSetUpBeforeClass`. All tests should really use the `static` instance, so we will remove the instance prop `$factory`. Replace `$this->factory` with `self::$factory` over 2000 times. Rewrite all of the tests that were hard-coding dynamic values. #YOLOFriday git-svn-id: https://develop.svn.wordpress.org/trunk@35225 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -8,7 +8,7 @@ class Tests_Post_Template extends WP_UnitTestCase {
|
||||
function test_wp_link_pages() {
|
||||
$contents = array( 'One', 'Two', 'Three' );
|
||||
$content = join( '<!--nextpage-->', $contents );
|
||||
$post_id = $this->factory->post->create( array( 'post_content' => $content ) );
|
||||
$post_id = self::$factory->post->create( array( 'post_content' => $content ) );
|
||||
|
||||
$this->go_to( '?p=' . $post_id );
|
||||
|
||||
@@ -81,15 +81,19 @@ class Tests_Post_Template extends WP_UnitTestCase {
|
||||
$this->assertEmpty( $none );
|
||||
|
||||
$bump = ' ';
|
||||
$page_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
|
||||
$child_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id ) );
|
||||
$grandchild_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $child_id ) );
|
||||
$page_id = self::$factory->post->create( array( 'post_type' => 'page' ) );
|
||||
$child_id = self::$factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id ) );
|
||||
$grandchild_id = self::$factory->post->create( array( 'post_type' => 'page', 'post_parent' => $child_id ) );
|
||||
|
||||
$title1 = get_post( $page_id )->post_title;
|
||||
$title2 = get_post( $child_id )->post_title;
|
||||
$title3 = get_post( $grandchild_id )->post_title;
|
||||
|
||||
$lineage =<<<LINEAGE
|
||||
<select name='page_id' id='page_id'>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
<option class="level-1" value="$child_id">{$bump}Post title 2</option>
|
||||
<option class="level-2" value="$grandchild_id">{$bump}{$bump}Post title 3</option>
|
||||
<option class="level-0" value="$page_id">$title1</option>
|
||||
<option class="level-1" value="$child_id">{$bump}$title2</option>
|
||||
<option class="level-2" value="$grandchild_id">{$bump}{$bump}$title3</option>
|
||||
</select>
|
||||
|
||||
LINEAGE;
|
||||
@@ -99,7 +103,7 @@ LINEAGE;
|
||||
|
||||
$depth =<<<DEPTH
|
||||
<select name='page_id' id='page_id'>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
<option class="level-0" value="$page_id">$title1</option>
|
||||
</select>
|
||||
|
||||
DEPTH;
|
||||
@@ -110,7 +114,7 @@ DEPTH;
|
||||
$option_none =<<<NONE
|
||||
<select name='page_id' id='page_id'>
|
||||
<option value="Woo">Hoo</option>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
<option class="level-0" value="$page_id">$title1</option>
|
||||
</select>
|
||||
|
||||
NONE;
|
||||
@@ -124,7 +128,7 @@ NONE;
|
||||
<select name='page_id' id='page_id'>
|
||||
<option value="-1">Burrito</option>
|
||||
<option value="Woo">Hoo</option>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
<option class="level-0" value="$page_id">$title1</option>
|
||||
</select>
|
||||
|
||||
NO;
|
||||
@@ -139,7 +143,7 @@ NO;
|
||||
* @ticket 12494
|
||||
*/
|
||||
public function test_wp_dropdown_pages_value_field_should_default_to_ID() {
|
||||
$p = $this->factory->post->create( array(
|
||||
$p = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
@@ -155,7 +159,7 @@ NO;
|
||||
* @ticket 12494
|
||||
*/
|
||||
public function test_wp_dropdown_pages_value_field_ID() {
|
||||
$p = $this->factory->post->create( array(
|
||||
$p = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
@@ -171,7 +175,7 @@ NO;
|
||||
* @ticket 12494
|
||||
*/
|
||||
public function test_wp_dropdown_pages_value_field_post_name() {
|
||||
$p = $this->factory->post->create( array(
|
||||
$p = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'foo',
|
||||
) );
|
||||
@@ -188,7 +192,7 @@ NO;
|
||||
* @ticket 12494
|
||||
*/
|
||||
public function test_wp_dropdown_pages_value_field_should_fall_back_on_ID_when_an_invalid_value_is_provided() {
|
||||
$p = $this->factory->post->create( array(
|
||||
$p = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'foo',
|
||||
) );
|
||||
@@ -205,7 +209,7 @@ NO;
|
||||
* @ticket 30082
|
||||
*/
|
||||
public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() {
|
||||
$p = $this->factory->post->create( array(
|
||||
$p = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'foo',
|
||||
) );
|
||||
@@ -221,7 +225,7 @@ NO;
|
||||
* @ticket 30082
|
||||
*/
|
||||
public function test_wp_dropdown_pages_should_obey_class_parameter() {
|
||||
$p = $this->factory->post->create( array(
|
||||
$p = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'foo',
|
||||
) );
|
||||
@@ -238,7 +242,7 @@ NO;
|
||||
* @ticket 31389
|
||||
*/
|
||||
public function test_get_page_template_slug_by_id() {
|
||||
$page_id = $this->factory->post->create( array(
|
||||
$page_id = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
@@ -255,7 +259,7 @@ NO;
|
||||
* @ticket 31389
|
||||
*/
|
||||
public function test_get_page_template_slug_from_loop() {
|
||||
$page_id = $this->factory->post->create( array(
|
||||
$page_id = self::$factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
@@ -269,7 +273,7 @@ NO;
|
||||
* @ticket 31389
|
||||
*/
|
||||
public function test_get_page_template_slug_non_page() {
|
||||
$post_id = $this->factory->post->create( array(
|
||||
$post_id = self::$factory->post->create( array(
|
||||
'post_type' => 'post',
|
||||
) );
|
||||
|
||||
@@ -284,7 +288,7 @@ NO;
|
||||
* @ticket 33974
|
||||
*/
|
||||
public function test_wp_page_menu_wp_nav_menu_fallback() {
|
||||
$pages = $this->factory->post->create_many( 3, array( 'post_type' => 'page' ) );
|
||||
$pages = self::$factory->post->create_many( 3, array( 'post_type' => 'page' ) );
|
||||
|
||||
// No menus + wp_nav_menu() falls back to wp_page_menu().
|
||||
$menu = wp_nav_menu( array( 'echo' => false ) );
|
||||
|
||||
Reference in New Issue
Block a user