<!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>[30367] trunk/tests/phpunit/tests: Add unit test files mistakenly excluded from [30085].</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 { 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/30367">30367</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/30367","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-11-17 16:16:01 +0000 (Mon, 17 Nov 2014)</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'>Add unit test files mistakenly excluded from <a href="https://core.trac.wordpress.org/changeset/30085">[30085]</a>.
See <a href="https://core.trac.wordpress.org/ticket/9256">#9256</a>, <a href="https://core.trac.wordpress.org/ticket/25349">#25349</a>.</pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsformattingWpTrimExcerptphp">trunk/tests/phpunit/tests/formatting/WpTrimExcerpt.php</a></li>
<li><a href="#trunktestsphpunittestsquerysetupPostdataphp">trunk/tests/phpunit/tests/query/setupPostdata.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsformattingWpTrimExcerptphp"></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/formatting/WpTrimExcerpt.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/WpTrimExcerpt.php (rev 0)
+++ trunk/tests/phpunit/tests/formatting/WpTrimExcerpt.php 2014-11-17 16:16:01 UTC (rev 30367)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,57 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group formatting
+ * @covers wp_trim_excerpt
+ */
+class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase {
+ /**
+ * @ticket 25349
+ */
+ public function test_secondary_loop_respect_more() {
+ $post1 = $this->factory->post->create( array(
+ 'post_content' => 'Post 1 Page 1<!--more-->Post 1 Page 2',
+ ) );
+ $post2 = $this->factory->post->create( array(
+ 'post_content' => 'Post 2 Page 1<!--more-->Post 2 Page 2',
+ ) );
+
+ $this->go_to( '/?p=' . $post1 );
+ setup_postdata( get_post( $post1 ) );
+
+ $q = new WP_Query( array(
+ 'post__in' => array( $post2 ),
+ ) );
+ if ( $q->have_posts() ) {
+ while ( $q->have_posts() ) {
+ $q->the_post();
+ $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
+ }
+ }
+ }
+
+ /**
+ * @ticket 25349
+ */
+ public function test_secondary_loop_respect_nextpage() {
+ $post1 = $this->factory->post->create( array(
+ 'post_content' => 'Post 1 Page 1<!--nextpage-->Post 1 Page 2',
+ ) );
+ $post2 = $this->factory->post->create( array(
+ 'post_content' => 'Post 2 Page 1<!--nextpage-->Post 2 Page 2',
+ ) );
+
+ $this->go_to( '/?p=' . $post1 );
+ setup_postdata( get_post( $post1 ) );
+
+ $q = new WP_Query( array(
+ 'post__in' => array( $post2 ),
+ ) );
+ if ( $q->have_posts() ) {
+ while ( $q->have_posts() ) {
+ $q->the_post();
+ $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
+ }
+ }
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsquerysetupPostdataphp"></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/query/setupPostdata.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/query/setupPostdata.php (rev 0)
+++ trunk/tests/phpunit/tests/query/setupPostdata.php 2014-11-17 16:16:01 UTC (rev 30367)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,363 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group query
+ * @covers setup_postdata
+ */
+class Tests_Query_SetupPostdata extends WP_UnitTestCase {
+ protected $global_keys = array( 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' );
+
+ protected $global_data = array();
+
+ public function setUp() {
+ parent::setUp();
+ return;
+
+ foreach ( $this->global_keys as $global_key ) {
+ if ( isset( $GLOBALS[ $global_key ] ) ) {
+ $this->global_data[ $global_key ] = $GLOBALS[ $global_key ];
+ unset( $GLOBALS[ $global_key ] );
+ } else {
+ $this->global_data[ $global_key ] = null;
+ }
+ }
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+ return;
+
+ foreach ( $this->global_keys as $global_key ) {
+ if ( ! is_null( $this->global_data[ $global_key ] ) ) {
+ $GLOBALS[ $global_key ] = $this->global_data[ $global_key ];
+ } else {
+ unset( $GLOBALS[ $global_key ] );
+ }
+ }
+
+ $this->global_data = array();
+ }
+
+ public function test_id() {
+ $p = $this->factory->post->create_and_get();
+ setup_postdata( $p );
+
+ $this->assertNotEmpty( $p->ID );
+ $this->assertSame( $p->ID, $GLOBALS['id'] );
+ }
+
+ public function test_authordata() {
+ $u = $this->factory->user->create_and_get();
+ $p = $this->factory->post->create_and_get( array(
+ 'post_author' => $u->ID,
+ ) );
+ setup_postdata( $p );
+
+ $this->assertNotEmpty( $GLOBALS['authordata'] );
+ $this->assertEquals( $u, $GLOBALS['authordata'] );
+ }
+
+ public function test_currentday() {
+ $p = $this->factory->post->create_and_get( array(
+ 'post_date' => '1980-09-09 06:30:00',
+ ) );
+ setup_postdata( $p );
+
+ $this->assertSame( '09.09.80', $GLOBALS['currentday'] );
+ }
+
+ public function test_currentmonth() {
+ $p = $this->factory->post->create_and_get( array(
+ 'post_date' => '1980-09-09 06:30:00',
+ ) );
+ setup_postdata( $p );
+
+ $this->assertSame( '09', $GLOBALS['currentmonth'] );
+ }
+
+ public function test_secondary_query_post_vars() {
+ $users = $this->factory->user->create_many( 2 );
+
+ $post1 = $this->factory->post->create_and_get( array(
+ 'post_author' => $users[0],
+ 'post_date' => '2012-02-02 02:00:00',
+ ) );
+
+ $post2 = $this->factory->post->create_and_get( array(
+ 'post_author' => $users[1],
+ 'post_date' => '2013-03-03 03:00:00',
+ ) );
+
+ $this->go_to( get_permalink( $post1 ) );
+ setup_postdata( $post1 );
+
+ // Main loop.
+ $this->assertSame( $post1->ID, $GLOBALS['id'] );
+ $this->assertEquals( get_userdata( $users[0] ), $GLOBALS['authordata'] );
+ $this->assertSame( '02.02.12', $GLOBALS['currentday'] );
+ $this->assertSame( '02', $GLOBALS['currentmonth'] );
+
+ // Secondary loop.
+ $q = new WP_Query( array(
+ 'posts_per_page' => 1,
+ ) );
+ if ( $q->have_posts() ) {
+ while ( $q->have_posts() ) {
+ $q->the_post();
+
+ // Should refer to the current loop.
+ $this->assertSame( $post2->ID, $GLOBALS['id'] );
+ $this->assertEquals( get_userdata( $users[1] ), $GLOBALS['authordata'] );
+ $this->assertSame( '03.03.13', $GLOBALS['currentday'] );
+ $this->assertSame( '03', $GLOBALS['currentmonth'] );
+ }
+ }
+ wp_reset_postdata();
+
+ // Should be reset to main loop.
+ $this->assertSame( $post1->ID, $GLOBALS['id'] );
+ $this->assertEquals( get_userdata( $users[0] ), $GLOBALS['authordata'] );
+ $this->assertSame( '02.02.12', $GLOBALS['currentday'] );
+ $this->assertSame( '02', $GLOBALS['currentmonth'] );
+ }
+
+ public function test_single_page() {
+ $post = $this->factory->post->create_and_get( array(
+ 'post_content' => 'Page 0',
+ ) );
+ setup_postdata( $post );
+
+ $this->assertSame( 0, $GLOBALS['multipage'] );
+ $this->assertSame( 1, $GLOBALS['numpages'] );
+ $this->assertEquals( array( 'Page 0' ), $GLOBALS['pages'] );
+ }
+
+ public function test_multi_page() {
+ $post = $this->factory->post->create_and_get( array(
+ 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
+ ) );
+ setup_postdata( $post );
+
+ $this->assertSame( 1, $GLOBALS['multipage'] );
+ $this->assertSame( 4, $GLOBALS['numpages'] );
+ $this->assertEquals( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $GLOBALS['pages'] );
+ }
+
+ /**
+ * @ticket 16746
+ */
+ public function test_nextpage_at_start_of_content() {
+ $post = $this->factory->post->create_and_get( array(
+ 'post_content' => '<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
+ ) );
+ setup_postdata( $post );
+
+ $this->assertSame( 1, $GLOBALS['multipage'] );
+ $this->assertSame( 3, $GLOBALS['numpages'] );
+ $this->assertEquals( array( 'Page 1', 'Page 2', 'Page 3' ), $GLOBALS['pages'] );
+ }
+
+ public function test_trim_nextpage_linebreaks() {
+ $post = $this->factory->post->create_and_get( array(
+ 'post_content' => "Page 0\n<!--nextpage-->\nPage 1\nhas a line break\n<!--nextpage-->Page 2<!--nextpage-->\n\nPage 3",
+ ) );
+ setup_postdata( $post );
+
+ $this->assertEquals( array( 'Page 0', "Page 1\nhas a line break", 'Page 2', "\nPage 3" ), $GLOBALS['pages'] );
+ }
+
+ /**
+ * @ticket 25349
+ */
+ public function test_secondary_query_nextpage() {
+ $post1 = $this->factory->post->create( array(
+ 'post_content' => 'Post 1 Page 1<!--nextpage-->Post 1 Page 2',
+ ) );
+ $post2 = $this->factory->post->create( array(
+ 'post_content' => 'Post 2 Page 1<!--nextpage-->Post 2 Page 2',
+ ) );
+
+ $this->go_to( '/?p=' . $post1 );
+ setup_postdata( get_post( $post1 ) );
+
+ // Main loop.
+ $this->assertSame( array( 'Post 1 Page 1', 'Post 1 Page 2' ), $GLOBALS['pages'] );
+
+ // Secondary loop.
+ $q = new WP_Query( array(
+ 'post__in' => array( $post2 ),
+ ) );
+ if ( $q->have_posts() ) {
+ while ( $q->have_posts() ) {
+ $q->the_post();
+
+ // Should refer to the current loop.
+ $this->assertSame( array( 'Post 2 Page 1', 'Post 2 Page 2' ), $GLOBALS['pages'] );
+ }
+ }
+ wp_reset_postdata();
+
+ // Should be reset to main loop.
+ $this->assertSame( array( 'Post 1 Page 1', 'Post 1 Page 2' ), $GLOBALS['pages'] );
+ }
+
+ public function test_page_from_wp_query() {
+ $page = $this->factory->post->create_and_get( array(
+ 'post_type' => 'page',
+ ) );
+
+ $this->go_to( '/?page=78' );
+
+ $GLOBALS['wp_query']->query_vars['page'] = 78;
+ setup_postdata( $page );
+
+ $this->assertSame( 78, $GLOBALS['page'] );
+ }
+
+ public function test_page_when_on_page() {
+ $page = $this->factory->post->create_and_get( array(
+ 'post_type' => 'page',
+ ) );
+ $this->go_to( get_permalink( $page ) );
+ setup_postdata( $page );
+
+ $this->assertSame( 1, $GLOBALS['page'] );
+ }
+
+ /**
+ * @ticket 20904
+ */
+ public function test_secondary_query_page() {
+ $post = $this->factory->post->create_and_get();
+ $this->go_to( '/?page=3' );
+ setup_postdata( $post );
+
+ // Main loop.
+ $this->assertSame( 3, $GLOBALS['page'] );
+
+ // Secondary loop.
+ $posts = $this->factory->post->create_many( 5 );
+ $q = new WP_Query( array(
+ 'page' => 4,
+ 'posts_per_page' => 1,
+ ) );
+ if ( $q->have_posts() ) {
+ while ( $q->have_posts() ) {
+ $q->the_post();
+
+ // $page should refer to the current loop.
+ $this->assertSame( 4, $GLOBALS['page'] );
+ }
+ }
+ wp_reset_postdata();
+
+ // $page should be reset to main loop.
+ $this->assertSame( 3, $GLOBALS['page'] );
+ }
+
+ /**
+ * @ticket 20904
+ */
+ public function test_more_when_on_setup_post() {
+ $post = $this->factory->post->create_and_get();
+ $this->go_to( get_permalink( $post ) );
+ setup_postdata( $post );
+
+ $this->assertSame( 1, $GLOBALS['more'] );
+ }
+
+ /**
+ * @ticket 20904
+ *
+ * $more should not be true when the set-up post is not the same as the current post.
+ */
+ public function test_more_when_on_single() {
+ $post1 = $this->factory->post->create_and_get();
+ $post2 = $this->factory->post->create_and_get();
+ $this->go_to( get_permalink( $post1 ) );
+ setup_postdata( $post2 );
+
+ $this->assertTrue( empty( $GLOBALS['more'] ) );
+ }
+
+ /**
+ * @ticket 20904
+ *
+ * $more should not be true when the set-up post is not the same as the current page.
+ */
+ public function test_more_when_on_page() {
+ $post = $this->factory->post->create_and_get();
+ $page = $this->factory->post->create_and_get( array(
+ 'post_type' => 'page',
+ ) );
+ $this->go_to( get_permalink( $page ) );
+ setup_postdata( $post );
+
+ $this->assertTrue( empty( $GLOBALS['more'] ) );
+ }
+
+ /**
+ * @ticket 20904
+ */
+ public function test_more_when_on_feed() {
+ $post = $this->factory->post->create_and_get();
+ $this->go_to( '/?feed=rss' );
+ setup_postdata( $post );
+
+ $this->assertSame( 1, $GLOBALS['more'] );
+ }
+
+ /**
+ * @ticket 20904
+ * @ticket 25349
+ */
+ public function test_secondary_query_more() {
+ $post = $this->factory->post->create_and_get();
+ $this->go_to( get_permalink( $post ) );
+ setup_postdata( $post );
+
+ // Main loop.
+ $this->assertSame( 1, $GLOBALS['more'] );
+
+ // Secondary loop.
+ $q = new WP_Query( array(
+ 'posts_per_page' => 1,
+ ) );
+ if ( $q->have_posts() ) {
+ while ( $q->have_posts() ) {
+ $q->the_post();
+
+ // $more should refer to the current loop.
+ $this->assertTrue( empty( $GLOBALS['more'] ) );
+ }
+ }
+ wp_reset_postdata();
+
+ // $page should be reset to main loop.
+ $this->assertSame( 1, $GLOBALS['more'] );
+ }
+
+ /**
+ * @ticket 24330
+ *
+ * setup_postdata( $a_post ) followed by the_content() in a loop that does not update
+ * global $post should use the content of $a_post rather then the global post.
+ */
+ function test_setup_postdata_loop() {
+ $post_id = $this->factory->post->create( array( 'post_content' => 'global post' ) );
+ $GLOBALS['wp_query']->post = $GLOBALS['post'] = get_post( $post_id );
+
+ $ids = $this->factory->post->create_many(5);
+ foreach ( $ids as $id ) {
+ $page = get_post( $id );
+ if ( $page ) {
+ setup_postdata( $page );
+ $content = get_echo( 'the_content', array() );
+ $this->assertEquals( $post_id, $GLOBALS['post']->ID );
+ $this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
+ wp_reset_postdata();
+ }
+ }
+ }
+
+}
</ins></span></pre>
</div>
</div>
</body>
</html>