<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[55591] trunk/tests/phpunit/tests/post: Tests: Split the tests from `post/template.php` into individual test classes.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/55591">55591</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/55591","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-03-24 17:10:44 +0000 (Fri, 24 Mar 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Split the tests from `post/template.php` into individual test classes.
This aims to bring some consistency to the location of post template function tests, as well as to make the tests more discoverable and easier to expand.
Includes:
* Adding `@covers` tags.
* Renaming `get_post_parent()` and `has_post_parent()` tests to match the names of the functions.
Follow-up to <a href="https://core.trac.wordpress.org/changeset/28398">[28398]</a>, <a href="https://core.trac.wordpress.org/changeset/31522">[31522]</a>, <a href="https://core.trac.wordpress.org/changeset/34654">[34654]</a>, <a href="https://core.trac.wordpress.org/changeset/34950">[34950]</a>, <a href="https://core.trac.wordpress.org/changeset/50127">[50127]</a>, <a href="https://core.trac.wordpress.org/changeset/50396">[50396]</a>, <a href="https://core.trac.wordpress.org/changeset/54717">[54717]</a>, <a href="https://core.trac.wordpress.org/changeset/54726">[54726]</a>, <a href="https://core.trac.wordpress.org/changeset/55590">[55590]</a>.
See <a href="https://core.trac.wordpress.org/ticket/57841">#57841</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestspostnavmenuphp">trunk/tests/phpunit/tests/post/nav-menu.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestspostgetPageTemplateSlugphp">trunk/tests/phpunit/tests/post/getPageTemplateSlug.php</a></li>
<li><a href="#trunktestsphpunittestspostgetPostParentphp">trunk/tests/phpunit/tests/post/getPostParent.php</a></li>
<li><a href="#trunktestsphpunittestspostwpLinkPagesphp">trunk/tests/phpunit/tests/post/wpLinkPages.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsposttemplatephp">trunk/tests/phpunit/tests/post/template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestspostgetPageTemplateSlugphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/post/getPageTemplateSlug.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/getPageTemplateSlug.php (rev 0)
+++ trunk/tests/phpunit/tests/post/getPageTemplateSlug.php 2023-03-24 17:10:44 UTC (rev 55591)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,75 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group post
+ * @group template
+ *
+ * @covers ::get_page_template_slug
+ */
+class Tests_Post_GetPageTemplateSlug extends WP_UnitTestCase {
+
+ /**
+ * @ticket 31389
+ */
+ public function test_get_page_template_slug_by_id() {
+ $page_id = self::factory()->post->create(
+ array(
+ 'post_type' => 'page',
+ )
+ );
+
+ $this->assertSame( '', get_page_template_slug( $page_id ) );
+
+ update_post_meta( $page_id, '_wp_page_template', 'default' );
+ $this->assertSame( '', get_page_template_slug( $page_id ) );
+
+ update_post_meta( $page_id, '_wp_page_template', 'example.php' );
+ $this->assertSame( 'example.php', get_page_template_slug( $page_id ) );
+ }
+
+ /**
+ * @ticket 31389
+ */
+ public function test_get_page_template_slug_from_loop() {
+ $page_id = self::factory()->post->create(
+ array(
+ 'post_type' => 'page',
+ )
+ );
+
+ update_post_meta( $page_id, '_wp_page_template', 'example.php' );
+ $this->go_to( get_permalink( $page_id ) );
+
+ $this->assertSame( 'example.php', get_page_template_slug() );
+ }
+
+ /**
+ * @ticket 31389
+ * @ticket 18375
+ */
+ public function test_get_page_template_slug_non_page() {
+ $post_id = self::factory()->post->create();
+
+ $this->assertSame( '', get_page_template_slug( $post_id ) );
+
+ update_post_meta( $post_id, '_wp_page_template', 'default' );
+
+ $this->assertSame( '', get_page_template_slug( $post_id ) );
+
+ update_post_meta( $post_id, '_wp_page_template', 'example.php' );
+ $this->assertSame( 'example.php', get_page_template_slug( $post_id ) );
+ }
+
+ /**
+ * @ticket 18375
+ */
+ public function test_get_page_template_slug_non_page_from_loop() {
+ $post_id = self::factory()->post->create();
+
+ update_post_meta( $post_id, '_wp_page_template', 'example.php' );
+
+ $this->go_to( get_permalink( $post_id ) );
+
+ $this->assertSame( 'example.php', get_page_template_slug() );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/post/getPageTemplateSlug.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestspostgetPostParentphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/post/getPostParent.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/getPostParent.php (rev 0)
+++ trunk/tests/phpunit/tests/post/getPostParent.php 2023-03-24 17:10:44 UTC (rev 55591)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,72 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group post
+ * @group template
+ *
+ * @covers ::get_post_parent
+ * @covers ::has_post_parent
+ */
+class Tests_Post_GetPostParent extends WP_UnitTestCase {
+
+ /**
+ * @ticket 33045
+ */
+ public function test_get_post_parent() {
+ $post = array(
+ 'post_status' => 'publish',
+ 'post_type' => 'page',
+ );
+
+ // Insert two initial posts.
+ $parent_id = self::factory()->post->create( $post );
+ $child_id = self::factory()->post->create( $post );
+
+ // Test if the function returns null by default.
+ $parent = get_post_parent( $child_id );
+ $this->assertNull( $parent );
+
+ // Update child post with a parent.
+ wp_update_post(
+ array(
+ 'ID' => $child_id,
+ 'post_parent' => $parent_id,
+ )
+ );
+
+ // Test if the function returns the parent object.
+ $parent = get_post_parent( $child_id );
+ $this->assertNotNull( $parent );
+ $this->assertSame( $parent_id, $parent->ID );
+ }
+
+ /**
+ * @ticket 33045
+ */
+ public function test_has_post_parent() {
+ $post = array(
+ 'post_status' => 'publish',
+ 'post_type' => 'page',
+ );
+
+ // Insert two initial posts.
+ $parent_id = self::factory()->post->create( $post );
+ $child_id = self::factory()->post->create( $post );
+
+ // Test if the function returns false by default.
+ $parent = has_post_parent( $child_id );
+ $this->assertFalse( $parent );
+
+ // Update child post with a parent.
+ wp_update_post(
+ array(
+ 'ID' => $child_id,
+ 'post_parent' => $parent_id,
+ )
+ );
+
+ // Test if the function returns true for a child post.
+ $parent = has_post_parent( $child_id );
+ $this->assertTrue( $parent );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/post/getPostParent.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestspostnavmenuphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/nav-menu.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/nav-menu.php 2023-03-24 16:12:35 UTC (rev 55590)
+++ trunk/tests/phpunit/tests/post/nav-menu.php 2023-03-24 17:10:44 UTC (rev 55591)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,6 +16,51 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 11095
+ * @ticket 33974
+ */
+ public function test_wp_page_menu_wp_nav_menu_fallback() {
+ $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 ) );
+
+ // After falling back, the 'before' argument should be set and output as '<ul>'.
+ $this->assertMatchesRegularExpression( '/<div class="menu"><ul>/', $menu );
+
+ // After falling back, the 'after' argument should be set and output as '</ul>'.
+ $this->assertMatchesRegularExpression( '/<\/ul><\/div>/', $menu );
+
+ // After falling back, the markup should include whitespace around <li>'s.
+ $this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
+ $this->assertDoesNotMatchRegularExpression( '/><li.*>|<\/li></U', $menu );
+
+ // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
+ $menu = wp_nav_menu(
+ array(
+ 'echo' => false,
+ 'container' => false,
+ )
+ );
+
+ // After falling back, the empty 'container' argument should still return a container element.
+ $this->assertMatchesRegularExpression( '/<div class="menu">/', $menu );
+
+ // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without white-space.
+ $menu = wp_nav_menu(
+ array(
+ 'echo' => false,
+ 'item_spacing' => 'discard',
+ )
+ );
+
+ // After falling back, the markup should not include whitespace around <li>'s.
+ $this->assertDoesNotMatchRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
+ $this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );
+
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 32464
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_nav_menu_empty_container() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -717,7 +762,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $ignored_1;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 35272
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunktestsphpunittestsposttemplatephp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/post/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/template.php 2023-03-24 16:12:35 UTC (rev 55590)
+++ trunk/tests/phpunit/tests/post/template.php 2023-03-24 17:10:44 UTC (rev 55591)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,304 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group template
- */
-class Tests_Post_Template extends WP_UnitTestCase {
-
- public function test_wp_link_pages() {
- $contents = array( 'One', 'Two', 'Three' );
- $content = implode( '<!--nextpage-->', $contents );
- $post_id = self::factory()->post->create( array( 'post_content' => $content ) );
-
- $this->go_to( '?p=' . $post_id );
-
- setup_postdata( get_post( $post_id ) );
-
- $permalink = sprintf( '<a href="%s" class="post-page-numbers">', get_permalink() );
- $page2 = _wp_link_page( 2 );
- $page3 = _wp_link_page( 3 );
-
- $expected = '<p class="post-nav-links">Pages: <span class="post-page-numbers current" aria-current="page">1</span> ' . $page2 . '2</a> ' . $page3 . '3</a></p>';
- $output = wp_link_pages( array( 'echo' => 0 ) );
-
- $this->assertSame( $expected, $output );
-
- $before_after = " <span class=\"post-page-numbers current\" aria-current=\"page\">1</span> {$page2}2</a> {$page3}3</a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'before' => '',
- 'after' => '',
- )
- );
-
- $this->assertSame( $before_after, $output );
-
- $separator = " <span class=\"post-page-numbers current\" aria-current=\"page\">1</span>{$page2}2</a>{$page3}3</a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'before' => '',
- 'after' => '',
- 'separator' => '',
- )
- );
-
- $this->assertSame( $separator, $output );
-
- $link = " <span class=\"post-page-numbers current\" aria-current=\"page\"><em>1</em></span>{$page2}<em>2</em></a>{$page3}<em>3</em></a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'before' => '',
- 'after' => '',
- 'separator' => '',
- 'link_before' => '<em>',
- 'link_after' => '</em>',
- )
- );
-
- $this->assertSame( $link, $output );
-
- $next = "{$page2}<em>Next page</em></a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'before' => '',
- 'after' => '',
- 'separator' => '',
- 'link_before' => '<em>',
- 'link_after' => '</em>',
- 'next_or_number' => 'next',
- )
- );
-
- $this->assertSame( $next, $output );
-
- $GLOBALS['page'] = 2;
- $next_prev = "{$permalink}<em>Previous page</em></a>{$page3}<em>Next page</em></a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'before' => '',
- 'after' => '',
- 'separator' => '',
- 'link_before' => '<em>',
- 'link_after' => '</em>',
- 'next_or_number' => 'next',
- )
- );
-
- $this->assertSame( $next_prev, $output );
-
- $next_prev_link = "{$permalink}Woo page</a>{$page3}Hoo page</a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'before' => '',
- 'after' => '',
- 'separator' => '',
- 'next_or_number' => 'next',
- 'nextpagelink' => 'Hoo page',
- 'previouspagelink' => 'Woo page',
- )
- );
-
- $this->assertSame( $next_prev_link, $output );
-
- $GLOBALS['page'] = 1;
- $separator = "<p class=\"post-nav-links\">Pages: <span class=\"post-page-numbers current\" aria-current=\"page\">1</span> | {$page2}2</a> | {$page3}3</a></p>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'separator' => ' | ',
- )
- );
-
- $this->assertSame( $separator, $output );
-
- $pagelink = " <span class=\"post-page-numbers current\" aria-current=\"page\">Page 1</span> | {$page2}Page 2</a> | {$page3}Page 3</a>";
- $output = wp_link_pages(
- array(
- 'echo' => 0,
- 'separator' => ' | ',
- 'before' => '',
- 'after' => '',
- 'pagelink' => 'Page %',
- )
- );
-
- $this->assertSame( $pagelink, $output );
- }
-
- /**
- * @ticket 31389
- */
- public function test_get_page_template_slug_by_id() {
- $page_id = self::factory()->post->create(
- array(
- 'post_type' => 'page',
- )
- );
-
- $this->assertSame( '', get_page_template_slug( $page_id ) );
-
- update_post_meta( $page_id, '_wp_page_template', 'default' );
- $this->assertSame( '', get_page_template_slug( $page_id ) );
-
- update_post_meta( $page_id, '_wp_page_template', 'example.php' );
- $this->assertSame( 'example.php', get_page_template_slug( $page_id ) );
- }
-
- /**
- * @ticket 31389
- */
- public function test_get_page_template_slug_from_loop() {
- $page_id = self::factory()->post->create(
- array(
- 'post_type' => 'page',
- )
- );
-
- update_post_meta( $page_id, '_wp_page_template', 'example.php' );
- $this->go_to( get_permalink( $page_id ) );
-
- $this->assertSame( 'example.php', get_page_template_slug() );
- }
-
- /**
- * @ticket 31389
- * @ticket 18375
- */
- public function test_get_page_template_slug_non_page() {
- $post_id = self::factory()->post->create();
-
- $this->assertSame( '', get_page_template_slug( $post_id ) );
-
- update_post_meta( $post_id, '_wp_page_template', 'default' );
-
- $this->assertSame( '', get_page_template_slug( $post_id ) );
-
- update_post_meta( $post_id, '_wp_page_template', 'example.php' );
- $this->assertSame( 'example.php', get_page_template_slug( $post_id ) );
- }
-
- /**
- * @ticket 18375
- */
- public function test_get_page_template_slug_non_page_from_loop() {
- $post_id = self::factory()->post->create();
-
- update_post_meta( $post_id, '_wp_page_template', 'example.php' );
-
- $this->go_to( get_permalink( $post_id ) );
-
- $this->assertSame( 'example.php', get_page_template_slug() );
- }
-
- /**
- * @ticket 11095
- * @ticket 33974
- */
- public function test_wp_page_menu_wp_nav_menu_fallback() {
- $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 ) );
-
- // After falling back, the 'before' argument should be set and output as '<ul>'.
- $this->assertMatchesRegularExpression( '/<div class="menu"><ul>/', $menu );
-
- // After falling back, the 'after' argument should be set and output as '</ul>'.
- $this->assertMatchesRegularExpression( '/<\/ul><\/div>/', $menu );
-
- // After falling back, the markup should include whitespace around <li>'s.
- $this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
- $this->assertDoesNotMatchRegularExpression( '/><li.*>|<\/li></U', $menu );
-
- // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
- $menu = wp_nav_menu(
- array(
- 'echo' => false,
- 'container' => false,
- )
- );
-
- // After falling back, the empty 'container' argument should still return a container element.
- $this->assertMatchesRegularExpression( '/<div class="menu">/', $menu );
-
- // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without white-space.
- $menu = wp_nav_menu(
- array(
- 'echo' => false,
- 'item_spacing' => 'discard',
- )
- );
-
- // After falling back, the markup should not include whitespace around <li>'s.
- $this->assertDoesNotMatchRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
- $this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );
-
- }
-
- /**
- * @ticket 33045
- */
- public function test_get_parent_post() {
- $post = array(
- 'post_status' => 'publish',
- 'post_type' => 'page',
- );
-
- // Insert two initial posts.
- $parent_id = self::factory()->post->create( $post );
- $child_id = self::factory()->post->create( $post );
-
- // Test if child get_parent_post() post returns Null by default.
- $parent = get_post_parent( $child_id );
- $this->assertNull( $parent );
-
- // Update child post with a parent.
- wp_update_post(
- array(
- 'ID' => $child_id,
- 'post_parent' => $parent_id,
- )
- );
-
- // Test if child get_parent_post() post returns the parent object.
- $parent = get_post_parent( $child_id );
- $this->assertNotNull( $parent );
- $this->assertSame( $parent_id, $parent->ID );
- }
-
- /**
- * @ticket 33045
- */
- public function test_has_parent_post() {
- $post = array(
- 'post_status' => 'publish',
- 'post_type' => 'page',
- );
-
- // Insert two initial posts.
- $parent_id = self::factory()->post->create( $post );
- $child_id = self::factory()->post->create( $post );
-
- // Test if child has_parent_post() post returns False by default.
- $parent = has_post_parent( $child_id );
- $this->assertFalse( $parent );
-
- // Update child post with a parent.
- wp_update_post(
- array(
- 'ID' => $child_id,
- 'post_parent' => $parent_id,
- )
- );
-
- // Test if child has_parent_post() returns True.
- $parent = has_post_parent( $child_id );
- $this->assertTrue( $parent );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestspostwpLinkPagesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/post/wpLinkPages.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/wpLinkPages.php (rev 0)
+++ trunk/tests/phpunit/tests/post/wpLinkPages.php 2023-03-24 17:10:44 UTC (rev 55591)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,136 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group post
+ * @group template
+ *
+ * @covers ::wp_link_pages
+ */
+class Tests_Post_wpLinkPages extends WP_UnitTestCase {
+
+ public function test_wp_link_pages() {
+ $contents = array( 'One', 'Two', 'Three' );
+ $content = implode( '<!--nextpage-->', $contents );
+ $post_id = self::factory()->post->create( array( 'post_content' => $content ) );
+
+ $this->go_to( '?p=' . $post_id );
+
+ setup_postdata( get_post( $post_id ) );
+
+ $permalink = sprintf( '<a href="%s" class="post-page-numbers">', get_permalink() );
+ $page2 = _wp_link_page( 2 );
+ $page3 = _wp_link_page( 3 );
+
+ $expected = '<p class="post-nav-links">Pages: <span class="post-page-numbers current" aria-current="page">1</span> ' . $page2 . '2</a> ' . $page3 . '3</a></p>';
+ $output = wp_link_pages( array( 'echo' => 0 ) );
+
+ $this->assertSame( $expected, $output );
+
+ $before_after = " <span class=\"post-page-numbers current\" aria-current=\"page\">1</span> {$page2}2</a> {$page3}3</a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'before' => '',
+ 'after' => '',
+ )
+ );
+
+ $this->assertSame( $before_after, $output );
+
+ $separator = " <span class=\"post-page-numbers current\" aria-current=\"page\">1</span>{$page2}2</a>{$page3}3</a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'before' => '',
+ 'after' => '',
+ 'separator' => '',
+ )
+ );
+
+ $this->assertSame( $separator, $output );
+
+ $link = " <span class=\"post-page-numbers current\" aria-current=\"page\"><em>1</em></span>{$page2}<em>2</em></a>{$page3}<em>3</em></a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'before' => '',
+ 'after' => '',
+ 'separator' => '',
+ 'link_before' => '<em>',
+ 'link_after' => '</em>',
+ )
+ );
+
+ $this->assertSame( $link, $output );
+
+ $next = "{$page2}<em>Next page</em></a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'before' => '',
+ 'after' => '',
+ 'separator' => '',
+ 'link_before' => '<em>',
+ 'link_after' => '</em>',
+ 'next_or_number' => 'next',
+ )
+ );
+
+ $this->assertSame( $next, $output );
+
+ $GLOBALS['page'] = 2;
+ $next_prev = "{$permalink}<em>Previous page</em></a>{$page3}<em>Next page</em></a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'before' => '',
+ 'after' => '',
+ 'separator' => '',
+ 'link_before' => '<em>',
+ 'link_after' => '</em>',
+ 'next_or_number' => 'next',
+ )
+ );
+
+ $this->assertSame( $next_prev, $output );
+
+ $next_prev_link = "{$permalink}Woo page</a>{$page3}Hoo page</a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'before' => '',
+ 'after' => '',
+ 'separator' => '',
+ 'next_or_number' => 'next',
+ 'nextpagelink' => 'Hoo page',
+ 'previouspagelink' => 'Woo page',
+ )
+ );
+
+ $this->assertSame( $next_prev_link, $output );
+
+ $GLOBALS['page'] = 1;
+ $separator = "<p class=\"post-nav-links\">Pages: <span class=\"post-page-numbers current\" aria-current=\"page\">1</span> | {$page2}2</a> | {$page3}3</a></p>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'separator' => ' | ',
+ )
+ );
+
+ $this->assertSame( $separator, $output );
+
+ $pagelink = " <span class=\"post-page-numbers current\" aria-current=\"page\">Page 1</span> | {$page2}Page 2</a> | {$page3}Page 3</a>";
+ $output = wp_link_pages(
+ array(
+ 'echo' => 0,
+ 'separator' => ' | ',
+ 'before' => '',
+ 'after' => '',
+ 'pagelink' => 'Page %',
+ )
+ );
+
+ $this->assertSame( $pagelink, $output );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/post/wpLinkPages.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>