<!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>[50292] trunk/tests/phpunit/tests/general: Tests: Rename some files and classes in `phpunit/tests/general/` per the naming conventions.</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/50292">50292</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/50292","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>2021-02-11 21:38:30 +0000 (Thu, 11 Feb 2021)</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: Rename some files and classes in `phpunit/tests/general/` per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization
Follow-up to <a href="https://core.trac.wordpress.org/changeset/47780">[47780]</a>, <a href="https://core.trac.wordpress.org/changeset/48911">[48911]</a>, <a href="https://core.trac.wordpress.org/changeset/49327">[49327]</a>, <a href="https://core.trac.wordpress.org/changeset/50291">[50291]</a>.
See <a href="https://core.trac.wordpress.org/ticket/51802">#51802</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsgeneralpaginateLinksphp">trunk/tests/phpunit/tests/general/paginateLinks.php</a></li>
<li><a href="#trunktestsphpunittestsgeneralwpErrorphp">trunk/tests/phpunit/tests/general/wpError.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsgeneralwpGetArchivesphp">trunk/tests/phpunit/tests/general/wpGetArchives.php</a></li>
<li><a href="#trunktestsphpunittestsgeneralwpGetDocumentTitlephp">trunk/tests/phpunit/tests/general/wpGetDocumentTitle.php</a></li>
<li><a href="#trunktestsphpunittestsgeneralwpResourceHintsphp">trunk/tests/phpunit/tests/general/wpResourceHints.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsgeneralarchivesphp">trunk/tests/phpunit/tests/general/archives.php</a></li>
<li><a href="#trunktestsphpunittestsgeneraldocumenttitlephp">trunk/tests/phpunit/tests/general/document-title.php</a></li>
<li><a href="#trunktestsphpunittestsgeneralresourceHintsphp">trunk/tests/phpunit/tests/general/resourceHints.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsgeneralarchivesphp"></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/general/archives.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/archives.php 2021-02-11 21:20:41 UTC (rev 50291)
+++ trunk/tests/phpunit/tests/general/archives.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,174 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group general
- */
-class Tests_General_Archives extends WP_UnitTestCase {
- function setUp() {
- parent::setUp();
-
- wp_cache_delete( 'last_changed', 'posts' );
- }
-
- /**
- * @ticket 23206
- */
- function test_get_archives_cache() {
- global $wpdb;
-
- self::factory()->post->create_many( 3, array( 'post_type' => 'post' ) );
- wp_cache_delete( 'last_changed', 'posts' );
- $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is not primed, expect 1 query.
- $result = wp_get_archives(
- array(
- 'type' => 'monthly',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $time1 = wp_cache_get( 'last_changed', 'posts' );
- $this->assertNotEmpty( $time1 );
- $this->assertSame( $num_queries + 1, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is primed, expect no queries.
- $result = wp_get_archives(
- array(
- 'type' => 'monthly',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries, $wpdb->num_queries );
-
- // Change args, resulting in a different query string. Cache is not primed, expect 1 query.
- $result = wp_get_archives(
- array(
- 'type' => 'monthly',
- 'echo' => false,
- 'order' => 'ASC',
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries + 1, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is primed, expect no queries.
- $result = wp_get_archives(
- array(
- 'type' => 'monthly',
- 'echo' => false,
- 'order' => 'ASC',
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Change type. Cache is not primed, expect 1 query.
- $result = wp_get_archives(
- array(
- 'type' => 'yearly',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries + 1, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is primed, expect no queries.
- $result = wp_get_archives(
- array(
- 'type' => 'yearly',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries, $wpdb->num_queries );
-
- // Change type. Cache is not primed, expect 1 query.
- $result = wp_get_archives(
- array(
- 'type' => 'daily',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries + 1, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is primed, expect no queries.
- $result = wp_get_archives(
- array(
- 'type' => 'daily',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries, $wpdb->num_queries );
-
- // Change type. Cache is not primed, expect 1 query.
- $result = wp_get_archives(
- array(
- 'type' => 'weekly',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries + 1, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is primed, expect no queries.
- $result = wp_get_archives(
- array(
- 'type' => 'weekly',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries, $wpdb->num_queries );
-
- // Change type. Cache is not primed, expect 1 query.
- $result = wp_get_archives(
- array(
- 'type' => 'postbypost',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries + 1, $wpdb->num_queries );
-
- $num_queries = $wpdb->num_queries;
-
- // Cache is primed, expect no queries.
- $result = wp_get_archives(
- array(
- 'type' => 'postbypost',
- 'echo' => false,
- )
- );
- $this->assertInternalType( 'string', $result );
- $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
- $this->assertSame( $num_queries, $wpdb->num_queries );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsgeneraldocumenttitlephp"></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/general/document-title.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/document-title.php 2021-02-11 21:20:41 UTC (rev 50291)
+++ trunk/tests/phpunit/tests/general/document-title.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,278 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * A set of unit tests for functions in wp-includes/general-template.php
- *
- * @group template
- * @group document-title
- */
-class Tests_General_DocumentTitle extends WP_UnitTestCase {
-
- public $blog_name;
- public static $category_id;
- public static $author_id;
- public static $post_id;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$category_id = $factory->category->create(
- array(
- 'name' => 'test_category',
- )
- );
-
- self::$author_id = $factory->user->create(
- array(
- 'role' => 'author',
- 'user_login' => 'test_author',
- 'description' => 'test_author',
- )
- );
-
- self::$post_id = $factory->post->create(
- array(
- 'post_author' => self::$author_id,
- 'post_status' => 'publish',
- 'post_title' => 'test_title',
- 'post_type' => 'post',
- 'post_date' => '2015-09-22 18:52:17',
- 'category' => self::$category_id,
- )
- );
- }
-
- function setUp() {
- parent::setUp();
-
- add_action( 'after_setup_theme', array( $this, '_add_title_tag_support' ) );
-
- $this->blog_name = get_option( 'blogname' );
-
- setup_postdata( get_post( self::$post_id ) );
- }
-
- function tearDown() {
- wp_reset_postdata();
- parent::tearDown();
- }
-
- function _add_title_tag_support() {
- add_theme_support( 'title-tag' );
- }
-
- function test__wp_render_title_tag() {
- $this->go_to( '/' );
-
- $this->expectOutputString( sprintf( "<title>%s – %s</title>\n", $this->blog_name, get_option( 'blogdescription' ) ) );
- _wp_render_title_tag();
- }
-
- function test__wp_render_title_no_theme_support() {
- $this->go_to( '/' );
-
- remove_theme_support( 'title-tag' );
-
- $this->expectOutputString( '' );
- _wp_render_title_tag();
- }
-
- function test_short_circuiting_title() {
- $this->go_to( '/' );
-
- add_filter( 'pre_get_document_title', array( $this, '_short_circuit_title' ) );
-
- $this->assertSame( 'A Wild Title', wp_get_document_title() );
- }
-
- function _short_circuit_title( $title ) {
- return 'A Wild Title';
- }
-
- function test_front_page_title() {
- update_option( 'show_on_front', 'page' );
- update_option(
- 'page_on_front',
- $this->factory->post->create(
- array(
- 'post_title' => 'front-page',
- 'post_type' => 'page',
- )
- )
- );
- add_filter( 'document_title_parts', array( $this, '_front_page_title_parts' ) );
-
- $this->go_to( '/' );
- $this->assertSame( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
-
- update_option( 'show_on_front', 'posts' );
-
- $this->go_to( '/' );
- $this->assertSame( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
- }
-
- function _front_page_title_parts( $parts ) {
- $this->assertArrayHasKey( 'title', $parts );
- $this->assertArrayHasKey( 'tagline', $parts );
- $this->assertArrayNotHasKey( 'site', $parts );
-
- return $parts;
- }
-
- function test_home_title() {
- $blog_page_id = $this->factory->post->create(
- array(
- 'post_title' => 'blog-page',
- 'post_type' => 'page',
- )
- );
- update_option( 'show_on_front', 'page' );
- update_option( 'page_for_posts', $blog_page_id );
-
- // Show page name on home page if it's not the front page.
- $this->go_to( get_permalink( $blog_page_id ) );
- $this->assertSame( sprintf( 'blog-page – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_paged_title() {
- $this->go_to( '?page=4' );
-
- add_filter( 'document_title_parts', array( $this, '_paged_title_parts' ) );
-
- $this->assertSame( sprintf( '%s – Page 4 – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
- }
-
- function _paged_title_parts( $parts ) {
- $this->assertArrayHasKey( 'page', $parts );
- $this->assertArrayHasKey( 'title', $parts );
- $this->assertArrayHasKey( 'tagline', $parts );
- $this->assertArrayNotHasKey( 'site', $parts );
-
- return $parts;
- }
-
- function test_singular_title() {
- $this->go_to( '?p=' . self::$post_id );
-
- add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) );
-
- $this->assertSame( sprintf( 'test_title – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function _singular_title_parts( $parts ) {
- $this->assertArrayHasKey( 'site', $parts );
- $this->assertArrayHasKey( 'title', $parts );
- $this->assertArrayNotHasKey( 'tagline', $parts );
-
- return $parts;
- }
-
- function test_category_title() {
- $this->go_to( '?cat=' . self::$category_id );
-
- $this->assertSame( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_search_title() {
- $this->go_to( '?s=test_title' );
-
- $this->assertSame( sprintf( 'Search Results for “test_title” – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_author_title() {
- $this->go_to( '?author=' . self::$author_id );
-
- $this->assertSame( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_post_type_archive_title() {
- register_post_type(
- 'cpt',
- array(
- 'public' => true,
- 'has_archive' => true,
- 'labels' => array(
- 'name' => 'test_cpt',
- ),
- )
- );
-
- $this->factory->post->create(
- array(
- 'post_type' => 'cpt',
- )
- );
-
- $this->go_to( '?post_type=cpt' );
-
- $this->assertSame( sprintf( 'test_cpt – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_year_title() {
- $this->go_to( '?year=2015' );
-
- $this->assertSame( sprintf( '2015 – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_month_title() {
- $this->go_to( '?monthnum=09' );
-
- $this->assertSame( sprintf( 'September 2015 – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_day_title() {
- $this->go_to( '?day=22' );
-
- $this->assertSame( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_404_title() {
- $this->go_to( '?m=404' );
-
- $this->assertSame( sprintf( 'Page not found – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function test_paged_post_title() {
- $this->go_to( '?paged=4&p=' . self::$post_id );
-
- add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) );
-
- $this->assertSame( sprintf( 'test_title – Page 4 – %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function _paged_post_title_parts( $parts ) {
- $this->assertArrayHasKey( 'page', $parts );
- $this->assertArrayHasKey( 'site', $parts );
- $this->assertArrayHasKey( 'title', $parts );
- $this->assertArrayNotHasKey( 'tagline', $parts );
-
- return $parts;
- }
-
- function test_rearrange_title_parts() {
- $this->go_to( '?p=' . self::$post_id );
-
- add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) );
-
- $this->assertSame( sprintf( '%s – test_title', $this->blog_name ), wp_get_document_title() );
- }
-
- function _rearrange_title_parts( $parts ) {
- $parts = array(
- $parts['site'],
- $parts['title'],
- );
-
- return $parts;
- }
-
- function test_change_title_separator() {
- $this->go_to( '?p=' . self::$post_id );
-
- add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) );
-
- $this->assertSame( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() );
- }
-
- function _change_title_separator( $sep ) {
- return '%%';
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsgeneralpaginateLinksphp"></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/general/paginateLinks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/paginateLinks.php 2021-02-11 21:20:41 UTC (rev 50291)
+++ trunk/tests/phpunit/tests/general/paginateLinks.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class Tests_Paginate_Links extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_General_PaginateLinks extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> private $i18n_count = 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsgeneralresourceHintsphp"></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/general/resourceHints.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/resourceHints.php 2021-02-11 21:20:41 UTC (rev 50291)
+++ trunk/tests/phpunit/tests/general/resourceHints.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,300 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group template
- * @ticket 34292
- */
-class Tests_WP_Resource_Hints extends WP_UnitTestCase {
- private $old_wp_scripts;
- private $old_wp_styles;
-
- function setUp() {
- parent::setUp();
- $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
- $this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
-
- remove_action( 'wp_default_scripts', 'wp_default_scripts' );
- remove_action( 'wp_default_styles', 'wp_default_styles' );
-
- $GLOBALS['wp_scripts'] = new WP_Scripts();
- $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' );
- $GLOBALS['wp_styles'] = new WP_Styles();
- $GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' );
- }
-
- function tearDown() {
- $GLOBALS['wp_scripts'] = $this->old_wp_scripts;
- $GLOBALS['wp_styles'] = $this->old_wp_styles;
- add_action( 'wp_default_scripts', 'wp_default_scripts' );
- add_action( 'wp_default_styles', 'wp_default_styles' );
- parent::tearDown();
- }
-
- function test_should_have_defaults_on_frontend() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
-
- $this->expectOutputString( $expected );
-
- wp_resource_hints();
- }
-
- function test_dns_prefetching() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
- "<link rel='dns-prefetch' href='//wordpress.org' />\n" .
- "<link rel='dns-prefetch' href='//google.com' />\n" .
- "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
-
- add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ) );
-
- $this->assertSame( $expected, $actual );
- }
-
- function _add_dns_prefetch_domains( $hints, $method ) {
- if ( 'dns-prefetch' === $method ) {
- $hints[] = 'http://wordpress.org';
- $hints[] = 'https://wordpress.org';
- $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped.
- $hints[] = 'https://google.com';
- $hints[] = '//make.wordpress.org';
- $hints[] = 'https://wordpress.org/plugins/';
- }
-
- return $hints;
- }
-
- /**
- * @ticket 37652
- */
- function test_preconnect() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
- "<link rel='preconnect' href='//wordpress.org' />\n" .
- "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
- "<link rel='preconnect' href='http://google.com' />\n" .
- "<link rel='preconnect' href='http://w.org' />\n";
-
- add_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ), 10, 2 );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- remove_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ) );
-
- $this->assertSame( $expected, $actual );
- }
-
- function _add_preconnect_domains( $hints, $method ) {
- if ( 'preconnect' === $method ) {
- $hints[] = '//wordpress.org';
- $hints[] = 'https://make.wordpress.org';
- $hints[] = 'htps://example.com'; // Invalid URLs should be skipped.
- $hints[] = 'http://google.com';
- $hints[] = 'w.org';
- }
-
- return $hints;
- }
-
- function test_prerender() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
- "<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" .
- "<link rel='prerender' href='http://jobs.wordpress.net' />\n" .
- "<link rel='prerender' href='//core.trac.wordpress.org' />\n";
-
- add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- remove_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ) );
-
- $this->assertSame( $expected, $actual );
- }
-
- function _add_prerender_urls( $hints, $method ) {
- if ( 'prerender' === $method ) {
- $hints[] = 'https://make.wordpress.org/great-again';
- $hints[] = 'http://jobs.wordpress.net';
- $hints[] = '//core.trac.wordpress.org';
- $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped.
- }
-
- return $hints;
- }
-
- function test_parse_url_dns_prefetch() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
- "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
-
- add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ) );
-
- $this->assertSame( $expected, $actual );
- }
-
- function _add_dns_prefetch_long_urls( $hints, $method ) {
- if ( 'dns-prefetch' === $method ) {
- $hints[] = 'http://make.wordpress.org/wp-includes/css/editor.css';
- }
-
- return $hints;
- }
-
- function test_dns_prefetch_styles() {
- $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
- "<link rel='dns-prefetch' href='//s.w.org' />\n";
-
- $args = array(
- 'family' => 'Open+Sans:400',
- 'subset' => 'latin',
- );
-
- wp_enqueue_style( 'googlefonts', add_query_arg( $args, '//fonts.googleapis.com/css' ) );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- wp_dequeue_style( 'googlefonts' );
-
- $this->assertSame( $expected, $actual );
-
- }
-
- function test_dns_prefetch_scripts() {
- $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
- "<link rel='dns-prefetch' href='//s.w.org' />\n";
-
- $args = array(
- 'family' => 'Open+Sans:400',
- 'subset' => 'latin',
- );
-
- wp_enqueue_script( 'googlefonts', add_query_arg( $args, '//fonts.googleapis.com/css' ) );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- wp_dequeue_style( 'googlefonts' );
-
- $this->assertSame( $expected, $actual );
- }
-
- function test_dns_prefetch_scripts_does_not_included_registered_only() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
- $unexpected = "<link rel='dns-prefetch' href='//wordpress.org' />\n";
-
- wp_register_script( 'jquery-elsewhere', 'https://wordpress.org/wp-includes/js/jquery/jquery.js' );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- wp_deregister_script( 'jquery-elsewhere' );
-
- $this->assertSame( $expected, $actual );
- $this->assertNotContains( $unexpected, $actual );
- }
-
- /**
- * @ticket 37502
- */
- function test_deregistered_scripts_are_ignored() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
-
- wp_enqueue_script( 'test-script', 'http://example.org/script.js' );
- wp_deregister_script( 'test-script' );
-
- $actual = get_echo( 'wp_resource_hints' );
- $this->assertSame( $expected, $actual );
- }
-
- /**
- * @ticket 37652
- */
- function test_malformed_urls() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
-
- // Errant colon.
- add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ), 10, 2 );
- $actual = get_echo( 'wp_resource_hints' );
- remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ) );
- $this->assertSame( $expected, $actual );
-
- // Unsupported Scheme.
- add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ), 10, 2 );
- $actual = get_echo( 'wp_resource_hints' );
- remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ) );
- $this->assertSame( $expected, $actual );
- }
-
- function _add_malformed_url_errant_colon( $hints, $method ) {
- if ( 'preconnect' === $method ) {
- $hints[] = '://core.trac.wordpress.org/ticket/37652';
- }
-
- return $hints;
- }
-
- function _add_malformed_url_unsupported_scheme( $hints, $method ) {
- if ( 'preconnect' === $method ) {
- $hints[] = 'git://develop.git.wordpress.org/';
- }
-
- return $hints;
- }
-
- /**
- * @group 38121
- */
- function test_custom_attributes() {
- $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
- "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
- "<link crossorigin as='image' pr='0.5' href='https://example.com/foo.jpeg' rel='prefetch' />\n" .
- "<link crossorigin='use-credentials' as='style' href='https://example.com/foo.css' rel='prefetch' />\n" .
- "<link href='http://wordpress.org' rel='prerender' />\n";
-
- add_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ), 10, 2 );
-
- $actual = get_echo( 'wp_resource_hints' );
-
- remove_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ) );
-
- $this->assertSame( $expected, $actual );
- }
-
- function _add_url_with_attributes( $hints, $method ) {
- // Ignore hints with missing href attributes.
- $hints[] = array(
- 'rel' => 'foo',
- );
-
- if ( 'preconnect' === $method ) {
- // Should ignore rel attributes.
- $hints[] = array(
- 'rel' => 'foo',
- 'href' => 'https://make.wordpress.org/great-again',
- );
- } elseif ( 'prefetch' === $method ) {
- $hints[] = array(
- 'crossorigin',
- 'as' => 'image',
- 'pr' => 0.5,
- 'href' => 'https://example.com/foo.jpeg',
- );
- $hints[] = array(
- 'crossorigin' => 'use-credentials',
- 'as' => 'style',
- 'href' => 'https://example.com/foo.css',
- );
- } elseif ( 'prerender' === $method ) {
- // Ignore invalid attributes.
- $hints[] = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'href' => 'http://wordpress.org',
- );
- }
-
- return $hints;
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsgeneralwpErrorphp"></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/general/wpError.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/wpError.php 2021-02-11 21:20:41 UTC (rev 50291)
+++ trunk/tests/phpunit/tests/general/wpError.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7,7 +7,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @coversDefaultClass WP_Error
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class Tests_WP_Error extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_General_wpError extends WP_UnitTestCase {
</ins><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"> * WP_Error fixture.
</span></span></pre></div>
<a id="trunktestsphpunittestsgeneralwpGetArchivesphpfromrev50291trunktestsphpunittestsgeneralarchivesphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/general/wpGetArchives.php (from rev 50291, trunk/tests/phpunit/tests/general/archives.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/wpGetArchives.php (rev 0)
+++ trunk/tests/phpunit/tests/general/wpGetArchives.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,174 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group general
+ */
+class Tests_General_wpGetArchives extends WP_UnitTestCase {
+ function setUp() {
+ parent::setUp();
+
+ wp_cache_delete( 'last_changed', 'posts' );
+ }
+
+ /**
+ * @ticket 23206
+ */
+ function test_get_archives_cache() {
+ global $wpdb;
+
+ self::factory()->post->create_many( 3, array( 'post_type' => 'post' ) );
+ wp_cache_delete( 'last_changed', 'posts' );
+ $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is not primed, expect 1 query.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'monthly',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $time1 = wp_cache_get( 'last_changed', 'posts' );
+ $this->assertNotEmpty( $time1 );
+ $this->assertSame( $num_queries + 1, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is primed, expect no queries.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'monthly',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries, $wpdb->num_queries );
+
+ // Change args, resulting in a different query string. Cache is not primed, expect 1 query.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'monthly',
+ 'echo' => false,
+ 'order' => 'ASC',
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries + 1, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is primed, expect no queries.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'monthly',
+ 'echo' => false,
+ 'order' => 'ASC',
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Change type. Cache is not primed, expect 1 query.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'yearly',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries + 1, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is primed, expect no queries.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'yearly',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries, $wpdb->num_queries );
+
+ // Change type. Cache is not primed, expect 1 query.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'daily',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries + 1, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is primed, expect no queries.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'daily',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries, $wpdb->num_queries );
+
+ // Change type. Cache is not primed, expect 1 query.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'weekly',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries + 1, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is primed, expect no queries.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'weekly',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries, $wpdb->num_queries );
+
+ // Change type. Cache is not primed, expect 1 query.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'postbypost',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries + 1, $wpdb->num_queries );
+
+ $num_queries = $wpdb->num_queries;
+
+ // Cache is primed, expect no queries.
+ $result = wp_get_archives(
+ array(
+ 'type' => 'postbypost',
+ 'echo' => false,
+ )
+ );
+ $this->assertInternalType( 'string', $result );
+ $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
+ $this->assertSame( $num_queries, $wpdb->num_queries );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsgeneralwpGetDocumentTitlephpfromrev50291trunktestsphpunittestsgeneraldocumenttitlephp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/general/wpGetDocumentTitle.php (from rev 50291, trunk/tests/phpunit/tests/general/document-title.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/wpGetDocumentTitle.php (rev 0)
+++ trunk/tests/phpunit/tests/general/wpGetDocumentTitle.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,278 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * A set of unit tests for functions in wp-includes/general-template.php
+ *
+ * @group template
+ * @group document-title
+ */
+class Tests_General_wpGetDocumentTitle extends WP_UnitTestCase {
+
+ public $blog_name;
+ public static $category_id;
+ public static $author_id;
+ public static $post_id;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$category_id = $factory->category->create(
+ array(
+ 'name' => 'test_category',
+ )
+ );
+
+ self::$author_id = $factory->user->create(
+ array(
+ 'role' => 'author',
+ 'user_login' => 'test_author',
+ 'description' => 'test_author',
+ )
+ );
+
+ self::$post_id = $factory->post->create(
+ array(
+ 'post_author' => self::$author_id,
+ 'post_status' => 'publish',
+ 'post_title' => 'test_title',
+ 'post_type' => 'post',
+ 'post_date' => '2015-09-22 18:52:17',
+ 'category' => self::$category_id,
+ )
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ add_action( 'after_setup_theme', array( $this, '_add_title_tag_support' ) );
+
+ $this->blog_name = get_option( 'blogname' );
+
+ setup_postdata( get_post( self::$post_id ) );
+ }
+
+ function tearDown() {
+ wp_reset_postdata();
+ parent::tearDown();
+ }
+
+ function _add_title_tag_support() {
+ add_theme_support( 'title-tag' );
+ }
+
+ function test__wp_render_title_tag() {
+ $this->go_to( '/' );
+
+ $this->expectOutputString( sprintf( "<title>%s – %s</title>\n", $this->blog_name, get_option( 'blogdescription' ) ) );
+ _wp_render_title_tag();
+ }
+
+ function test__wp_render_title_no_theme_support() {
+ $this->go_to( '/' );
+
+ remove_theme_support( 'title-tag' );
+
+ $this->expectOutputString( '' );
+ _wp_render_title_tag();
+ }
+
+ function test_short_circuiting_title() {
+ $this->go_to( '/' );
+
+ add_filter( 'pre_get_document_title', array( $this, '_short_circuit_title' ) );
+
+ $this->assertSame( 'A Wild Title', wp_get_document_title() );
+ }
+
+ function _short_circuit_title( $title ) {
+ return 'A Wild Title';
+ }
+
+ function test_front_page_title() {
+ update_option( 'show_on_front', 'page' );
+ update_option(
+ 'page_on_front',
+ $this->factory->post->create(
+ array(
+ 'post_title' => 'front-page',
+ 'post_type' => 'page',
+ )
+ )
+ );
+ add_filter( 'document_title_parts', array( $this, '_front_page_title_parts' ) );
+
+ $this->go_to( '/' );
+ $this->assertSame( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
+
+ update_option( 'show_on_front', 'posts' );
+
+ $this->go_to( '/' );
+ $this->assertSame( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function _front_page_title_parts( $parts ) {
+ $this->assertArrayHasKey( 'title', $parts );
+ $this->assertArrayHasKey( 'tagline', $parts );
+ $this->assertArrayNotHasKey( 'site', $parts );
+
+ return $parts;
+ }
+
+ function test_home_title() {
+ $blog_page_id = $this->factory->post->create(
+ array(
+ 'post_title' => 'blog-page',
+ 'post_type' => 'page',
+ )
+ );
+ update_option( 'show_on_front', 'page' );
+ update_option( 'page_for_posts', $blog_page_id );
+
+ // Show page name on home page if it's not the front page.
+ $this->go_to( get_permalink( $blog_page_id ) );
+ $this->assertSame( sprintf( 'blog-page – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_paged_title() {
+ $this->go_to( '?page=4' );
+
+ add_filter( 'document_title_parts', array( $this, '_paged_title_parts' ) );
+
+ $this->assertSame( sprintf( '%s – Page 4 – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function _paged_title_parts( $parts ) {
+ $this->assertArrayHasKey( 'page', $parts );
+ $this->assertArrayHasKey( 'title', $parts );
+ $this->assertArrayHasKey( 'tagline', $parts );
+ $this->assertArrayNotHasKey( 'site', $parts );
+
+ return $parts;
+ }
+
+ function test_singular_title() {
+ $this->go_to( '?p=' . self::$post_id );
+
+ add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) );
+
+ $this->assertSame( sprintf( 'test_title – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function _singular_title_parts( $parts ) {
+ $this->assertArrayHasKey( 'site', $parts );
+ $this->assertArrayHasKey( 'title', $parts );
+ $this->assertArrayNotHasKey( 'tagline', $parts );
+
+ return $parts;
+ }
+
+ function test_category_title() {
+ $this->go_to( '?cat=' . self::$category_id );
+
+ $this->assertSame( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_search_title() {
+ $this->go_to( '?s=test_title' );
+
+ $this->assertSame( sprintf( 'Search Results for “test_title” – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_author_title() {
+ $this->go_to( '?author=' . self::$author_id );
+
+ $this->assertSame( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_post_type_archive_title() {
+ register_post_type(
+ 'cpt',
+ array(
+ 'public' => true,
+ 'has_archive' => true,
+ 'labels' => array(
+ 'name' => 'test_cpt',
+ ),
+ )
+ );
+
+ $this->factory->post->create(
+ array(
+ 'post_type' => 'cpt',
+ )
+ );
+
+ $this->go_to( '?post_type=cpt' );
+
+ $this->assertSame( sprintf( 'test_cpt – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_year_title() {
+ $this->go_to( '?year=2015' );
+
+ $this->assertSame( sprintf( '2015 – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_month_title() {
+ $this->go_to( '?monthnum=09' );
+
+ $this->assertSame( sprintf( 'September 2015 – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_day_title() {
+ $this->go_to( '?day=22' );
+
+ $this->assertSame( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_404_title() {
+ $this->go_to( '?m=404' );
+
+ $this->assertSame( sprintf( 'Page not found – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function test_paged_post_title() {
+ $this->go_to( '?paged=4&p=' . self::$post_id );
+
+ add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) );
+
+ $this->assertSame( sprintf( 'test_title – Page 4 – %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function _paged_post_title_parts( $parts ) {
+ $this->assertArrayHasKey( 'page', $parts );
+ $this->assertArrayHasKey( 'site', $parts );
+ $this->assertArrayHasKey( 'title', $parts );
+ $this->assertArrayNotHasKey( 'tagline', $parts );
+
+ return $parts;
+ }
+
+ function test_rearrange_title_parts() {
+ $this->go_to( '?p=' . self::$post_id );
+
+ add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) );
+
+ $this->assertSame( sprintf( '%s – test_title', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function _rearrange_title_parts( $parts ) {
+ $parts = array(
+ $parts['site'],
+ $parts['title'],
+ );
+
+ return $parts;
+ }
+
+ function test_change_title_separator() {
+ $this->go_to( '?p=' . self::$post_id );
+
+ add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) );
+
+ $this->assertSame( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() );
+ }
+
+ function _change_title_separator( $sep ) {
+ return '%%';
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsgeneralwpResourceHintsphpfromrev50291trunktestsphpunittestsgeneralresourceHintsphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/general/wpResourceHints.php (from rev 50291, trunk/tests/phpunit/tests/general/resourceHints.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/wpResourceHints.php (rev 0)
+++ trunk/tests/phpunit/tests/general/wpResourceHints.php 2021-02-11 21:38:30 UTC (rev 50292)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,300 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group template
+ * @ticket 34292
+ */
+class Tests_General_wpResourceHints extends WP_UnitTestCase {
+ private $old_wp_scripts;
+ private $old_wp_styles;
+
+ function setUp() {
+ parent::setUp();
+ $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
+ $this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
+
+ remove_action( 'wp_default_scripts', 'wp_default_scripts' );
+ remove_action( 'wp_default_styles', 'wp_default_styles' );
+
+ $GLOBALS['wp_scripts'] = new WP_Scripts();
+ $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' );
+ $GLOBALS['wp_styles'] = new WP_Styles();
+ $GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' );
+ }
+
+ function tearDown() {
+ $GLOBALS['wp_scripts'] = $this->old_wp_scripts;
+ $GLOBALS['wp_styles'] = $this->old_wp_styles;
+ add_action( 'wp_default_scripts', 'wp_default_scripts' );
+ add_action( 'wp_default_styles', 'wp_default_styles' );
+ parent::tearDown();
+ }
+
+ function test_should_have_defaults_on_frontend() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
+
+ $this->expectOutputString( $expected );
+
+ wp_resource_hints();
+ }
+
+ function test_dns_prefetching() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
+ "<link rel='dns-prefetch' href='//wordpress.org' />\n" .
+ "<link rel='dns-prefetch' href='//google.com' />\n" .
+ "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
+
+ add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ) );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ function _add_dns_prefetch_domains( $hints, $method ) {
+ if ( 'dns-prefetch' === $method ) {
+ $hints[] = 'http://wordpress.org';
+ $hints[] = 'https://wordpress.org';
+ $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped.
+ $hints[] = 'https://google.com';
+ $hints[] = '//make.wordpress.org';
+ $hints[] = 'https://wordpress.org/plugins/';
+ }
+
+ return $hints;
+ }
+
+ /**
+ * @ticket 37652
+ */
+ function test_preconnect() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
+ "<link rel='preconnect' href='//wordpress.org' />\n" .
+ "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
+ "<link rel='preconnect' href='http://google.com' />\n" .
+ "<link rel='preconnect' href='http://w.org' />\n";
+
+ add_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ), 10, 2 );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ remove_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ) );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ function _add_preconnect_domains( $hints, $method ) {
+ if ( 'preconnect' === $method ) {
+ $hints[] = '//wordpress.org';
+ $hints[] = 'https://make.wordpress.org';
+ $hints[] = 'htps://example.com'; // Invalid URLs should be skipped.
+ $hints[] = 'http://google.com';
+ $hints[] = 'w.org';
+ }
+
+ return $hints;
+ }
+
+ function test_prerender() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
+ "<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" .
+ "<link rel='prerender' href='http://jobs.wordpress.net' />\n" .
+ "<link rel='prerender' href='//core.trac.wordpress.org' />\n";
+
+ add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ remove_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ) );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ function _add_prerender_urls( $hints, $method ) {
+ if ( 'prerender' === $method ) {
+ $hints[] = 'https://make.wordpress.org/great-again';
+ $hints[] = 'http://jobs.wordpress.net';
+ $hints[] = '//core.trac.wordpress.org';
+ $hints[] = 'htps://wordpress.org'; // Invalid URLs should be skipped.
+ }
+
+ return $hints;
+ }
+
+ function test_parse_url_dns_prefetch() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
+ "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
+
+ add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ) );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ function _add_dns_prefetch_long_urls( $hints, $method ) {
+ if ( 'dns-prefetch' === $method ) {
+ $hints[] = 'http://make.wordpress.org/wp-includes/css/editor.css';
+ }
+
+ return $hints;
+ }
+
+ function test_dns_prefetch_styles() {
+ $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
+ "<link rel='dns-prefetch' href='//s.w.org' />\n";
+
+ $args = array(
+ 'family' => 'Open+Sans:400',
+ 'subset' => 'latin',
+ );
+
+ wp_enqueue_style( 'googlefonts', add_query_arg( $args, '//fonts.googleapis.com/css' ) );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ wp_dequeue_style( 'googlefonts' );
+
+ $this->assertSame( $expected, $actual );
+
+ }
+
+ function test_dns_prefetch_scripts() {
+ $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
+ "<link rel='dns-prefetch' href='//s.w.org' />\n";
+
+ $args = array(
+ 'family' => 'Open+Sans:400',
+ 'subset' => 'latin',
+ );
+
+ wp_enqueue_script( 'googlefonts', add_query_arg( $args, '//fonts.googleapis.com/css' ) );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ wp_dequeue_style( 'googlefonts' );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ function test_dns_prefetch_scripts_does_not_included_registered_only() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
+ $unexpected = "<link rel='dns-prefetch' href='//wordpress.org' />\n";
+
+ wp_register_script( 'jquery-elsewhere', 'https://wordpress.org/wp-includes/js/jquery/jquery.js' );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ wp_deregister_script( 'jquery-elsewhere' );
+
+ $this->assertSame( $expected, $actual );
+ $this->assertNotContains( $unexpected, $actual );
+ }
+
+ /**
+ * @ticket 37502
+ */
+ function test_deregistered_scripts_are_ignored() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
+
+ wp_enqueue_script( 'test-script', 'http://example.org/script.js' );
+ wp_deregister_script( 'test-script' );
+
+ $actual = get_echo( 'wp_resource_hints' );
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @ticket 37652
+ */
+ function test_malformed_urls() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
+
+ // Errant colon.
+ add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ), 10, 2 );
+ $actual = get_echo( 'wp_resource_hints' );
+ remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ) );
+ $this->assertSame( $expected, $actual );
+
+ // Unsupported Scheme.
+ add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ), 10, 2 );
+ $actual = get_echo( 'wp_resource_hints' );
+ remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ) );
+ $this->assertSame( $expected, $actual );
+ }
+
+ function _add_malformed_url_errant_colon( $hints, $method ) {
+ if ( 'preconnect' === $method ) {
+ $hints[] = '://core.trac.wordpress.org/ticket/37652';
+ }
+
+ return $hints;
+ }
+
+ function _add_malformed_url_unsupported_scheme( $hints, $method ) {
+ if ( 'preconnect' === $method ) {
+ $hints[] = 'git://develop.git.wordpress.org/';
+ }
+
+ return $hints;
+ }
+
+ /**
+ * @group 38121
+ */
+ function test_custom_attributes() {
+ $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
+ "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
+ "<link crossorigin as='image' pr='0.5' href='https://example.com/foo.jpeg' rel='prefetch' />\n" .
+ "<link crossorigin='use-credentials' as='style' href='https://example.com/foo.css' rel='prefetch' />\n" .
+ "<link href='http://wordpress.org' rel='prerender' />\n";
+
+ add_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ), 10, 2 );
+
+ $actual = get_echo( 'wp_resource_hints' );
+
+ remove_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ) );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ function _add_url_with_attributes( $hints, $method ) {
+ // Ignore hints with missing href attributes.
+ $hints[] = array(
+ 'rel' => 'foo',
+ );
+
+ if ( 'preconnect' === $method ) {
+ // Should ignore rel attributes.
+ $hints[] = array(
+ 'rel' => 'foo',
+ 'href' => 'https://make.wordpress.org/great-again',
+ );
+ } elseif ( 'prefetch' === $method ) {
+ $hints[] = array(
+ 'crossorigin',
+ 'as' => 'image',
+ 'pr' => 0.5,
+ 'href' => 'https://example.com/foo.jpeg',
+ );
+ $hints[] = array(
+ 'crossorigin' => 'use-credentials',
+ 'as' => 'style',
+ 'href' => 'https://example.com/foo.css',
+ );
+ } elseif ( 'prerender' === $method ) {
+ // Ignore invalid attributes.
+ $hints[] = array(
+ 'foo' => 'bar',
+ 'bar' => 'baz',
+ 'href' => 'http://wordpress.org',
+ );
+ }
+
+ return $hints;
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>