diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index 5ce9dc05e2..3de294aa22 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -486,17 +486,6 @@ class Tests_Post_GetPages extends WP_UnitTestCase { $this->assertSameSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) ); } - /** - * @ticket 22389 - */ - public function test_wp_dropdown_pages() { - self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) ); - - preg_match_all( '#assertCount( 5, $matches[0] ); - } - /** * @ticket 22208 */ diff --git a/tests/phpunit/tests/post/template.php b/tests/phpunit/tests/post/template.php index c30f31fba2..54da278d94 100644 --- a/tests/phpunit/tests/post/template.php +++ b/tests/phpunit/tests/post/template.php @@ -131,218 +131,6 @@ class Tests_Post_Template extends WP_UnitTestCase { $this->assertSame( $pagelink, $output ); } - public function test_wp_dropdown_pages() { - $none = wp_dropdown_pages( array( 'echo' => 0 ) ); - $this->assertEmpty( $none ); - - $bump = '   '; - $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; - - $output = wp_dropdown_pages( array( 'echo' => 0 ) ); - $this->assertSameIgnoreEOL( $lineage, $output ); - - $depth = << - - - -DEPTH; - - $output = wp_dropdown_pages( - array( - 'echo' => 0, - 'depth' => 1, - ) - ); - $this->assertSameIgnoreEOL( $depth, $output ); - - $option_none = << - - - - -NONE; - - $output = wp_dropdown_pages( - array( - 'echo' => 0, - 'depth' => 1, - 'show_option_none' => 'Hoo', - 'option_none_value' => 'Woo', - ) - ); - $this->assertSameIgnoreEOL( $option_none, $output ); - - $option_no_change = << - - - - - -NO; - - $output = wp_dropdown_pages( - array( - 'echo' => 0, - 'depth' => 1, - 'show_option_none' => 'Hoo', - 'option_none_value' => 'Woo', - 'show_option_no_change' => 'Burrito', - ) - ); - $this->assertSameIgnoreEOL( $option_no_change, $output ); - } - - /** - * @ticket 12494 - */ - public function test_wp_dropdown_pages_value_field_should_default_to_ID() { - $p = self::factory()->post->create( - array( - 'post_type' => 'page', - ) - ); - - $found = wp_dropdown_pages( - array( - 'echo' => 0, - ) - ); - - // Should contain page ID by default. - $this->assertStringContainsString( 'value="' . $p . '"', $found ); - } - - /** - * @ticket 12494 - */ - public function test_wp_dropdown_pages_value_field_ID() { - $p = self::factory()->post->create( - array( - 'post_type' => 'page', - ) - ); - - $found = wp_dropdown_pages( - array( - 'echo' => 0, - 'value_field' => 'ID', - ) - ); - - $this->assertStringContainsString( 'value="' . $p . '"', $found ); - } - - /** - * @ticket 12494 - */ - public function test_wp_dropdown_pages_value_field_post_name() { - $p = self::factory()->post->create( - array( - 'post_type' => 'page', - 'post_name' => 'foo', - ) - ); - - $found = wp_dropdown_pages( - array( - 'echo' => 0, - 'value_field' => 'post_name', - ) - ); - - $this->assertStringContainsString( 'value="foo"', $found ); - } - - /** - * @ticket 12494 - */ - public function test_wp_dropdown_pages_value_field_should_fall_back_on_ID_when_an_invalid_value_is_provided() { - $p = self::factory()->post->create( - array( - 'post_type' => 'page', - 'post_name' => 'foo', - ) - ); - - $found = wp_dropdown_pages( - array( - 'echo' => 0, - 'value_field' => 'foo', - ) - ); - - $this->assertStringContainsString( 'value="' . $p . '"', $found ); - } - - /** - * @ticket 30082 - */ - public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() { - $p = self::factory()->post->create( - array( - 'post_type' => 'page', - 'post_name' => 'foo', - ) - ); - - $found = wp_dropdown_pages( - array( - 'echo' => 0, - ) - ); - - $this->assertDoesNotMatchRegularExpression( '/]+class=\'/', $found ); - } - - /** - * @ticket 30082 - */ - public function test_wp_dropdown_pages_should_obey_class_parameter() { - $p = self::factory()->post->create( - array( - 'post_type' => 'page', - 'post_name' => 'foo', - ) - ); - - $found = wp_dropdown_pages( - array( - 'echo' => 0, - 'class' => 'bar', - ) - ); - - $this->assertMatchesRegularExpression( '/]+class=\'bar\'/', $found ); - } - /** * @ticket 31389 */ diff --git a/tests/phpunit/tests/post/wpDropdownPages.php b/tests/phpunit/tests/post/wpDropdownPages.php new file mode 100644 index 0000000000..d838875f1d --- /dev/null +++ b/tests/phpunit/tests/post/wpDropdownPages.php @@ -0,0 +1,222 @@ + 0 ) ); + $this->assertEmpty( $none ); + + $bump = '   '; + $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; + + $output = wp_dropdown_pages( array( 'echo' => 0 ) ); + $this->assertSameIgnoreEOL( $lineage, $output ); + + $depth = << + + + +DEPTH; + + $output = wp_dropdown_pages( + array( + 'echo' => 0, + 'depth' => 1, + ) + ); + $this->assertSameIgnoreEOL( $depth, $output ); + + $option_none = << + + + + +NONE; + + $output = wp_dropdown_pages( + array( + 'echo' => 0, + 'depth' => 1, + 'show_option_none' => 'Hoo', + 'option_none_value' => 'Woo', + ) + ); + $this->assertSameIgnoreEOL( $option_none, $output ); + + $option_no_change = << + + + + + +NO; + + $output = wp_dropdown_pages( + array( + 'echo' => 0, + 'depth' => 1, + 'show_option_none' => 'Hoo', + 'option_none_value' => 'Woo', + 'show_option_no_change' => 'Burrito', + ) + ); + $this->assertSameIgnoreEOL( $option_no_change, $output ); + } + + /** + * @ticket 12494 + */ + public function test_wp_dropdown_pages_value_field_should_default_to_ID() { + $p = self::factory()->post->create( + array( + 'post_type' => 'page', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + ) + ); + + // Should contain page ID by default. + $this->assertStringContainsString( 'value="' . $p . '"', $found ); + } + + /** + * @ticket 12494 + */ + public function test_wp_dropdown_pages_value_field_ID() { + $p = self::factory()->post->create( + array( + 'post_type' => 'page', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + 'value_field' => 'ID', + ) + ); + + $this->assertStringContainsString( 'value="' . $p . '"', $found ); + } + + /** + * @ticket 12494 + */ + public function test_wp_dropdown_pages_value_field_post_name() { + $p = self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + 'value_field' => 'post_name', + ) + ); + + $this->assertStringContainsString( 'value="foo"', $found ); + } + + /** + * @ticket 12494 + */ + public function test_wp_dropdown_pages_value_field_should_fall_back_on_ID_when_an_invalid_value_is_provided() { + $p = self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + 'value_field' => 'foo', + ) + ); + + $this->assertStringContainsString( 'value="' . $p . '"', $found ); + } + + /** + * @ticket 30082 + */ + public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() { + $p = self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + ) + ); + + $this->assertDoesNotMatchRegularExpression( '/]+class=\'/', $found ); + } + + /** + * @ticket 30082 + */ + public function test_wp_dropdown_pages_should_obey_class_parameter() { + $p = self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) + ); + + $found = wp_dropdown_pages( + array( + 'echo' => 0, + 'class' => 'bar', + ) + ); + + $this->assertMatchesRegularExpression( '/]+class=\'bar\'/', $found ); + } +}