<!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>[51639] trunk/tests/phpunit/tests/admin: Tests: Rename classes in `phpunit/tests/admin/` 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/51639">51639</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/51639","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-08-19 13:08:43 +0000 (Thu, 19 Aug 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 classes in `phpunit/tests/admin/` 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>, <a href="https://core.trac.wordpress.org/changeset/50292">[50292]</a>, <a href="https://core.trac.wordpress.org/changeset/50342">[50342]</a>, <a href="https://core.trac.wordpress.org/changeset/50452">[50452]</a>, <a href="https://core.trac.wordpress.org/changeset/50453">[50453]</a>, <a href="https://core.trac.wordpress.org/changeset/50456">[50456]</a>, <a href="https://core.trac.wordpress.org/changeset/50967">[50967]</a>, <a href="https://core.trac.wordpress.org/changeset/50968">[50968]</a>, <a href="https://core.trac.wordpress.org/changeset/50969">[50969]</a>, <a href="https://core.trac.wordpress.org/changeset/51491">[51491]</a>, <a href="https://core.trac.wordpress.org/changeset/51492">[514
92]</a>, <a href="https://core.trac.wordpress.org/changeset/51493">[51493]</a>, <a href="https://core.trac.wordpress.org/changeset/51623">[51623]</a>.
See <a href="https://core.trac.wordpress.org/ticket/53363">#53363</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsadminincludesFilephp">trunk/tests/phpunit/tests/admin/includesFile.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesListTablephp">trunk/tests/phpunit/tests/admin/includesListTable.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesMiscphp">trunk/tests/phpunit/tests/admin/includesMisc.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesPluginphp">trunk/tests/phpunit/tests/admin/includesPlugin.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesPostphp">trunk/tests/phpunit/tests/admin/includesPost.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesSchemaphp">trunk/tests/phpunit/tests/admin/includesSchema.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesScreenphp">trunk/tests/phpunit/tests/admin/includesScreen.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesTemplatephp">trunk/tests/phpunit/tests/admin/includesTemplate.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesThemephp">trunk/tests/phpunit/tests/admin/includesTheme.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsadminwpCommunityEventsphp">trunk/tests/phpunit/tests/admin/wpCommunityEvents.php</a></li>
<li><a href="#trunktestsphpunittestsadminwpMediaListTablephp">trunk/tests/phpunit/tests/admin/wpMediaListTable.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsadminincludesCommunityEventsphp">trunk/tests/phpunit/tests/admin/includesCommunityEvents.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesMediaListTablephp">trunk/tests/phpunit/tests/admin/includesMediaListTable.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsadminincludesCommunityEventsphp"></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/admin/includesCommunityEvents.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesCommunityEvents.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesCommunityEvents.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,580 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * Unit tests for methods in WP_Community_Events.
- *
- * @package WordPress
- * @subpackage UnitTests
- * @since 4.8.0
- */
-
-/**
- * Class Test_WP_Community_Events.
- *
- * @group admin
- * @group community-events
- *
- * @since 4.8.0
- */
-class Test_WP_Community_Events extends WP_UnitTestCase {
- /**
- * An instance of the class to test.
- *
- * @access private
- * @since 4.8.0
- *
- * @var WP_Community_Events
- */
- private $instance;
-
- /**
- * Performs setup tasks for every test.
- *
- * @since 4.8.0
- */
- public function set_up() {
- parent::set_up();
-
- require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
-
- $this->instance = new WP_Community_Events( 1, $this->get_user_location() );
- }
-
- /**
- * Simulates a stored user location.
- *
- * @access private
- * @since 4.8.0
- *
- * @return array The mock location.
- */
- private function get_user_location() {
- return array(
- 'description' => 'San Francisco',
- 'latitude' => '37.7749300',
- 'longitude' => '-122.4194200',
- 'country' => 'US',
- );
- }
-
- /**
- * Test: get_events() should return an instance of WP_Error if the response code is not 200.
- *
- * @since 4.8.0
- */
- public function test_get_events_bad_response_code() {
- add_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
-
- $this->assertWPError( $this->instance->get_events() );
-
- remove_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
- }
-
- /**
- * Test: The response body should not be cached if the response code is not 200.
- *
- * @since 4.8.0
- */
- public function test_get_cached_events_bad_response_code() {
- add_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
-
- $this->instance->get_events();
-
- $this->assertFalse( $this->instance->get_cached_events() );
-
- remove_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
- }
-
- /**
- * Simulates an HTTP response with a non-200 response code.
- *
- * @since 4.8.0
- *
- * @return array A mock response with a 404 HTTP status code
- */
- public function _http_request_bad_response_code() {
- return array(
- 'headers' => '',
- 'body' => '',
- 'response' => array(
- 'code' => 404,
- ),
- 'cookies' => '',
- 'filename' => '',
- );
- }
-
- /**
- * Test: get_events() should return an instance of WP_Error if the response body does not have
- * the required properties.
- *
- * @since 4.8.0
- */
- public function test_get_events_invalid_response() {
- add_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
-
- $this->assertWPError( $this->instance->get_events() );
-
- remove_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
- }
-
- /**
- * Test: The response body should not be cached if it does not have the required properties.
- *
- * @since 4.8.0
- */
- public function test_get_cached_events_invalid_response() {
- add_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
-
- $this->instance->get_events();
-
- $this->assertFalse( $this->instance->get_cached_events() );
-
- remove_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
- }
-
- /**
- * Simulates an HTTP response with a body that does not have the required properties.
- *
- * @since 4.8.0
- *
- * @return array A mock response that's missing required properties.
- */
- public function _http_request_invalid_response() {
- return array(
- 'headers' => '',
- 'body' => wp_json_encode( array() ),
- 'response' => array(
- 'code' => 200,
- ),
- 'cookies' => '',
- 'filename' => '',
- );
- }
-
- /**
- * Test: With a valid response, get_events() should return an associative array containing a location array and
- * an events array with individual events that have Unix start/end timestamps.
- *
- * @since 4.8.0
- */
- public function test_get_events_valid_response() {
- add_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
-
- $response = $this->instance->get_events();
-
- $this->assertNotWPError( $response );
- $this->assertSameSetsWithIndex( $this->get_user_location(), $response['location'] );
- $this->assertSame( strtotime( 'next Sunday 1pm' ), $response['events'][0]['start_unix_timestamp'] );
- $this->assertSame( strtotime( 'next Sunday 2pm' ), $response['events'][0]['end_unix_timestamp'] );
-
- remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
- }
-
- /**
- * Test: `get_cached_events()` should return the same data as get_events(), including Unix start/end
- * timestamps for each event.
- *
- * @since 4.8.0
- */
- public function test_get_cached_events_valid_response() {
- add_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
-
- $this->instance->get_events();
-
- $cached_events = $this->instance->get_cached_events();
-
- $this->assertNotWPError( $cached_events );
- $this->assertSameSetsWithIndex( $this->get_user_location(), $cached_events['location'] );
- $this->assertSame( strtotime( 'next Sunday 1pm' ), $cached_events['events'][0]['start_unix_timestamp'] );
- $this->assertSame( strtotime( 'next Sunday 2pm' ), $cached_events['events'][0]['end_unix_timestamp'] );
-
- remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
- }
-
- /**
- * Simulates an HTTP response with valid location and event data.
- *
- * @since 4.8.0
- *
- * @return array A mock HTTP response with valid data.
- */
- public function _http_request_valid_response() {
- return array(
- 'headers' => '',
- 'body' => wp_json_encode(
- array(
- 'location' => $this->get_user_location(),
- 'events' => $this->get_valid_events(),
- )
- ),
- 'response' => array(
- 'code' => 200,
- ),
- 'cookies' => '',
- 'filename' => '',
- );
- }
-
- /**
- * Get a sample of valid events.
- *
- * @return array[]
- */
- protected function get_valid_events() {
- return array(
- array(
- 'type' => 'meetup',
- 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts',
- 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/',
- 'meetup' => 'The East Bay WordPress Meetup Group',
- 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/',
- 'start_unix_timestamp' => strtotime( 'next Sunday 1pm' ),
- 'end_unix_timestamp' => strtotime( 'next Sunday 2pm' ),
-
- 'location' => array(
- 'location' => 'Oakland, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.808453,
- 'longitude' => -122.26593,
- ),
- ),
-
- array(
- 'type' => 'meetup',
- 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy',
- 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/',
- 'meetup' => 'WordPress Bay Area Foothills Group',
- 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/',
- 'start_unix_timestamp' => strtotime( 'next Wednesday 1:30pm' ),
- 'end_unix_timestamp' => strtotime( 'next Wednesday 2:30pm' ),
-
- 'location' => array(
- 'location' => 'Milpitas, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.432813,
- 'longitude' => -121.907095,
- ),
- ),
-
- array(
- 'type' => 'wordcamp',
- 'title' => 'WordCamp San Francisco',
- 'url' => 'https://sf.wordcamp.org/2020/',
- 'meetup' => null,
- 'meetup_url' => null,
- 'start_unix_timestamp' => strtotime( 'next Saturday' ),
- 'end_unix_timestamp' => strtotime( 'next Saturday 8pm' ),
-
- 'location' => array(
- 'location' => 'San Francisco, CA',
- 'country' => 'US',
- 'latitude' => 37.432813,
- 'longitude' => -121.907095,
- ),
- ),
- );
- }
-
- /**
- * Test: `trim_events()` should immediately remove expired events.
- *
- * @covers WP_Community_Events::trim_events
- *
- * @since 5.5.2
- */
- public function test_trim_expired_events() {
- $trim_events = new ReflectionMethod( $this->instance, 'trim_events' );
- $trim_events->setAccessible( true );
-
- $events = $this->get_valid_events();
-
- // This should be removed because it's already ended.
- $events[0]['start_unix_timestamp'] = strtotime( '1 hour ago' );
- $events[0]['end_unix_timestamp'] = strtotime( '2 seconds ago' );
-
- // This should remain because it hasn't ended yet.
- $events[1]['start_unix_timestamp'] = strtotime( '2 seconds ago' );
- $events[1]['end_unix_timestamp'] = strtotime( '+1 hour' );
-
- $actual = $trim_events->invoke( $this->instance, $events );
-
- $this->assertCount( 2, $actual );
- $this->assertSame( $actual[0]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
- $this->assertSame( $actual[1]['title'], 'WordCamp San Francisco' );
- }
-
- /**
- * Test: get_events() should return the events with the WordCamp pinned in the prepared list.
- *
- * @covers WP_Community_Events::trim_events
- *
- * @since 4.9.7
- * @since 5.5.2 Tests `trim_events()` directly instead of indirectly via `get_events()`.
- */
- public function test_trim_events_pin_wordcamp() {
- $trim_events = new ReflectionMethod( $this->instance, 'trim_events' );
- $trim_events->setAccessible( true );
-
- $actual = $trim_events->invoke( $this->instance, $this->_events_with_unpinned_wordcamp() );
-
- /*
- * San Diego was at index 3 in the mock API response, but pinning puts it at index 2,
- * so that it remains in the list. The other events should remain unchanged.
- */
- $this->assertCount( 3, $actual );
- $this->assertSame( $actual[0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' );
- $this->assertSame( $actual[1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
- $this->assertSame( $actual[2]['title'], 'WordCamp San Diego' );
- }
-
- /**
- * Simulates a scenario where a WordCamp needs to be pinned higher than it's default position.
- *
- * @since 4.9.7
- * @since 5.5.2 Accepts and returns only the events, rather than an entire HTTP response.
- *
- * @return array A list of mock events.
- */
- public function _events_with_unpinned_wordcamp() {
- return array(
- array(
- 'type' => 'meetup',
- 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts',
- 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/',
- 'meetup' => 'The East Bay WordPress Meetup Group',
- 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/',
- 'start_unix_timestamp' => strtotime( 'next Monday 1pm' ),
- 'end_unix_timestamp' => strtotime( 'next Monday 2pm' ),
-
- 'location' => array(
- 'location' => 'Oakland, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.808453,
- 'longitude' => -122.26593,
- ),
- ),
-
- array(
- 'type' => 'meetup',
- 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy',
- 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/',
- 'meetup' => 'WordPress Bay Area Foothills Group',
- 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/',
- 'start_unix_timestamp' => strtotime( 'next Tuesday 1:30pm' ),
- 'end_unix_timestamp' => strtotime( 'next Tuesday 2:30pm' ),
-
- 'location' => array(
- 'location' => 'Milpitas, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.432813,
- 'longitude' => -121.907095,
- ),
- ),
-
- array(
- 'type' => 'meetup',
- 'title' => 'WordPress Q&A',
- 'url' => 'https://www.meetup.com/sanjosewp/events/245419844/',
- 'meetup' => 'The San Jose WordPress Meetup',
- 'meetup_url' => 'https://www.meetup.com/sanjosewp/',
- 'start_unix_timestamp' => strtotime( 'next Wednesday 5:30pm' ),
- 'end_unix_timestamp' => strtotime( 'next Wednesday 6:30pm' ),
-
- 'location' => array(
- 'location' => 'Milpitas, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.244194,
- 'longitude' => -121.889313,
- ),
- ),
-
- array(
- 'type' => 'wordcamp',
- 'title' => 'WordCamp San Diego',
- 'url' => 'https://2018.sandiego.wordcamp.org',
- 'meetup' => null,
- 'meetup_url' => null,
- 'start_unix_timestamp' => strtotime( 'next Thursday 9am' ),
- 'end_unix_timestamp' => strtotime( 'next Thursday 10am' ),
-
- 'location' => array(
- 'location' => 'San Diego, CA',
- 'country' => 'US',
- 'latitude' => 32.7220419,
- 'longitude' => -117.1534513,
- ),
- ),
- );
- }
-
- /**
- * Test: get_events() shouldn't stick an extra WordCamp when there's already one that naturally
- * falls into the list.
- *
- * @covers WP_Community_Events::trim_events
- *
- * @since 4.9.7
- * @since 5.5.2 Tests `trim_events()` directly instead of indirectly via `get_events()`.
- */
- public function test_trim_events_dont_pin_multiple_wordcamps() {
- $trim_events = new ReflectionMethod( $this->instance, 'trim_events' );
- $trim_events->setAccessible( true );
-
- $actual = $trim_events->invoke( $this->instance, $this->_events_with_multiple_wordcamps() );
-
- /*
- * The first meetup should be removed because it's expired, while the next 3 events are selected.
- * WordCamp LA should not be stuck to the list, because San Diego already appears naturally.
- */
- $this->assertCount( 3, $actual );
- $this->assertSame( $actual[0]['title'], 'WordCamp San Diego' );
- $this->assertSame( $actual[1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
- $this->assertSame( $actual[2]['title'], 'WordPress Q&A' );
- }
-
- /**
- * Simulates a valid HTTP response where a WordCamp needs to be pinned higher than it's default position.
- * no need to pin extra camp b/c one already exists in response
- *
- * @since 4.9.7
- * @since 5.5.2 Tests `trim_events()` directly instead of indirectly via `get_events()`.
- *
- * @return array A mock HTTP response.
- */
- public function _events_with_multiple_wordcamps() {
- return array(
- array(
- 'type' => 'meetup',
- 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts',
- 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/',
- 'meetup' => 'The East Bay WordPress Meetup Group',
- 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/',
- 'start_unix_timestamp' => strtotime( '2 days ago' ) - HOUR_IN_SECONDS,
- 'end_unix_timestamp' => strtotime( '2 days ago' ),
-
- 'location' => array(
- 'location' => 'Oakland, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.808453,
- 'longitude' => -122.26593,
- ),
- ),
-
- array(
- 'type' => 'wordcamp',
- 'title' => 'WordCamp San Diego',
- 'url' => 'https://2018.sandiego.wordcamp.org',
- 'meetup' => null,
- 'meetup_url' => null,
- 'start_unix_timestamp' => strtotime( 'next Tuesday 9am' ),
- 'end_unix_timestamp' => strtotime( 'next Tuesday 10am' ),
-
- 'location' => array(
- 'location' => 'San Diego, CA',
- 'country' => 'US',
- 'latitude' => 32.7220419,
- 'longitude' => -117.1534513,
- ),
- ),
-
- array(
- 'type' => 'meetup',
- 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy',
- 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/',
- 'meetup' => 'WordPress Bay Area Foothills Group',
- 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/',
- 'start_unix_timestamp' => strtotime( 'next Wednesday 1:30pm' ),
- 'end_unix_timestamp' => strtotime( 'next Wednesday 2:30pm' ),
-
- 'location' => array(
- 'location' => 'Milpitas, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.432813,
- 'longitude' => -121.907095,
- ),
- ),
-
- array(
- 'type' => 'meetup',
- 'title' => 'WordPress Q&A',
- 'url' => 'https://www.meetup.com/sanjosewp/events/245419844/',
- 'meetup' => 'The San Jose WordPress Meetup',
- 'meetup_url' => 'https://www.meetup.com/sanjosewp/',
- 'start_unix_timestamp' => strtotime( 'next Thursday 5:30pm' ),
- 'end_unix_timestamp' => strtotime( 'next Thursday 6:30pm' ),
-
- 'location' => array(
- 'location' => 'Milpitas, CA, USA',
- 'country' => 'us',
- 'latitude' => 37.244194,
- 'longitude' => -121.889313,
- ),
- ),
-
- array(
- 'type' => 'wordcamp',
- 'title' => 'WordCamp Los Angeles',
- 'url' => 'https://2018.la.wordcamp.org',
- 'meetup' => null,
- 'meetup_url' => null,
- 'start_unix_timestamp' => strtotime( 'next Friday 9am' ),
- 'end_unix_timestamp' => strtotime( 'next Friday 10am' ),
-
- 'location' => array(
- 'location' => 'Los Angeles, CA',
- 'country' => 'US',
- 'latitude' => 34.050888,
- 'longitude' => -118.285426,
- ),
- ),
- );
- }
-
- /**
- * Test that get_unsafe_client_ip() properly anonymizes all possible address formats
- *
- * @dataProvider data_get_unsafe_client_ip
- *
- * @ticket 41083
- */
- public function test_get_unsafe_client_ip( $raw_ip, $expected_result ) {
- $_SERVER['REMOTE_ADDR'] = 'this should not be used';
- $_SERVER['HTTP_CLIENT_IP'] = $raw_ip;
- $actual_result = WP_Community_Events::get_unsafe_client_ip();
-
- $this->assertSame( $expected_result, $actual_result );
- }
-
- /**
- * Provide test cases for `test_get_unsafe_client_ip()`.
- *
- * @return array
- */
- public function data_get_unsafe_client_ip() {
- return array(
- // Handle '::' returned from `wp_privacy_anonymize_ip()`.
- array(
- 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001',
- false,
- ),
-
- // Handle '0.0.0.0' returned from `wp_privacy_anonymize_ip()`.
- array(
- 'unknown',
- false,
- ),
-
- // Valid IPv4.
- array(
- '198.143.164.252',
- '198.143.164.0',
- ),
-
- // Valid IPv6.
- array(
- '2a03:2880:2110:df07:face:b00c::1',
- '2a03:2880:2110:df07::',
- ),
- );
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsadminincludesFilephp"></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/admin/includesFile.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesFile.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesFile.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,7 +4,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @group file
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_includesFile extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesFile 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"> * @ticket 20449
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesListTablephp"></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/admin/includesListTable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesListTable.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesListTable.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_includesListTable extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesListTable extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px"> protected static $top = array();
</span><span class="cx" style="display: block; padding: 0 10px"> protected static $children = array();
</span><span class="cx" style="display: block; padding: 0 10px"> protected static $grandchildren = array();
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesMediaListTablephp"></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/admin/includesMediaListTable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesMediaListTable.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesMediaListTable.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,50 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group admin
- */
-class Tests_Admin_includesMediaListTable extends WP_UnitTestCase {
-
- public static function set_up_before_class() {
- parent::set_up_before_class();
-
- require_once ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php';
- }
-
- /**
- * Tests that a call to WP_Media_List_Table::prepare_items() on a site without any scheduled events
- * does not result in a PHP warning.
- *
- * The warning that we should not see:
- * PHP 5.6 - 7.4: `Invalid argument supplied for foreach()`.
- * PHP 8.0 and higher: `Warning: foreach() argument must be of type array|object, bool given`.
- *
- * Note: This does not test the actual functioning of the WP_Media_List_Table::prepare_items() method.
- * It just and only tests for/against the PHP warning.
- *
- * @ticket 53949
- * @covers WP_Media_List_Table::prepare_items
- */
- public function test_prepare_items_without_cron_option_does_not_throw_warning() {
- global $wp_query;
-
- // Note: setMethods() is deprecated in PHPUnit 9, but still supported.
- $mock = $this->getMockBuilder( WP_Media_List_Table::class )
- ->disableOriginalConstructor()
- ->disallowMockingUnknownTypes()
- ->setMethods( array( 'set_pagination_args' ) )
- ->getMock();
-
- $mock->expects( $this->once() )
- ->method( 'set_pagination_args' );
-
- $wp_query->query_vars['posts_per_page'] = 10;
- delete_option( 'cron' );
-
- // Verify that the cause of the error is in place.
- $this->assertFalse( _get_cron_array(), '_get_cron_array() does not return false' );
-
- // If this test does not error out due to the PHP warning, we're good.
- $mock->prepare_items();
- }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsadminincludesMiscphp"></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/admin/includesMisc.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesMisc.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesMisc.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_includesMisc extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesMisc extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_shorten_url() {
</span><span class="cx" style="display: block; padding: 0 10px"> $tests = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wordpress\.org/about/philosophy'
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesPluginphp"></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/admin/includesPlugin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesPlugin.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesPlugin.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @group plugins
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_includesPlugin extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesPlugin extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px"> public static function wpSetUpBeforeClass( $factory ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self::_back_up_mu_plugins();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesPostphp"></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/admin/includesPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesPost.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesPost.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_Includes_Post extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesPost extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px"> protected static $contributor_id;
</span><span class="cx" style="display: block; padding: 0 10px"> protected static $author_ids;
</span><span class="cx" style="display: block; padding: 0 10px"> protected static $editor_id;
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesSchemaphp"></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/admin/includesSchema.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesSchema.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesSchema.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_Includes_Schema extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesSchema extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> private static $options;
</span><span class="cx" style="display: block; padding: 0 10px"> private static $blogmeta;
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesScreenphp"></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/admin/includesScreen.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesScreen.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesScreen.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,7 +4,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</span><span class="cx" style="display: block; padding: 0 10px"> * @group adminScreen
</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_Admin_includesScreen extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesScreen extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px"> public $core_screens = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'index.php' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'base' => 'dashboard',
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesTemplatephp"></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/admin/includesTemplate.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesTemplate.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesTemplate.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,7 +2,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</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_Admin_includesTemplate extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesTemplate 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"> * @ticket 51147
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesThemephp"></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/admin/includesTheme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesTheme.php 2021-08-19 12:43:03 UTC (rev 51638)
+++ trunk/tests/phpunit/tests/admin/includesTheme.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,7 +2,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group themes
</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_Admin_includesTheme extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Admin_IncludesTheme extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function set_up() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::set_up();
</span></span></pre></div>
<a id="trunktestsphpunittestsadminwpCommunityEventsphpfromrev51638trunktestsphpunittestsadminincludesCommunityEventsphp"></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/admin/wpCommunityEvents.php (from rev 51638, trunk/tests/phpunit/tests/admin/includesCommunityEvents.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/wpCommunityEvents.php (rev 0)
+++ trunk/tests/phpunit/tests/admin/wpCommunityEvents.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,580 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Unit tests for methods in WP_Community_Events.
+ *
+ * @package WordPress
+ * @subpackage UnitTests
+ * @since 4.8.0
+ */
+
+/**
+ * Class Tests_Admin_wpCommunityEvents.
+ *
+ * @group admin
+ * @group community-events
+ *
+ * @since 4.8.0
+ */
+class Tests_Admin_wpCommunityEvents extends WP_UnitTestCase {
+ /**
+ * An instance of the class to test.
+ *
+ * @access private
+ * @since 4.8.0
+ *
+ * @var WP_Community_Events
+ */
+ private $instance;
+
+ /**
+ * Performs setup tasks for every test.
+ *
+ * @since 4.8.0
+ */
+ public function set_up() {
+ parent::set_up();
+
+ require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
+
+ $this->instance = new WP_Community_Events( 1, $this->get_user_location() );
+ }
+
+ /**
+ * Simulates a stored user location.
+ *
+ * @access private
+ * @since 4.8.0
+ *
+ * @return array The mock location.
+ */
+ private function get_user_location() {
+ return array(
+ 'description' => 'San Francisco',
+ 'latitude' => '37.7749300',
+ 'longitude' => '-122.4194200',
+ 'country' => 'US',
+ );
+ }
+
+ /**
+ * Test: get_events() should return an instance of WP_Error if the response code is not 200.
+ *
+ * @since 4.8.0
+ */
+ public function test_get_events_bad_response_code() {
+ add_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
+
+ $this->assertWPError( $this->instance->get_events() );
+
+ remove_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
+ }
+
+ /**
+ * Test: The response body should not be cached if the response code is not 200.
+ *
+ * @since 4.8.0
+ */
+ public function test_get_cached_events_bad_response_code() {
+ add_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
+
+ $this->instance->get_events();
+
+ $this->assertFalse( $this->instance->get_cached_events() );
+
+ remove_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) );
+ }
+
+ /**
+ * Simulates an HTTP response with a non-200 response code.
+ *
+ * @since 4.8.0
+ *
+ * @return array A mock response with a 404 HTTP status code
+ */
+ public function _http_request_bad_response_code() {
+ return array(
+ 'headers' => '',
+ 'body' => '',
+ 'response' => array(
+ 'code' => 404,
+ ),
+ 'cookies' => '',
+ 'filename' => '',
+ );
+ }
+
+ /**
+ * Test: get_events() should return an instance of WP_Error if the response body does not have
+ * the required properties.
+ *
+ * @since 4.8.0
+ */
+ public function test_get_events_invalid_response() {
+ add_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
+
+ $this->assertWPError( $this->instance->get_events() );
+
+ remove_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
+ }
+
+ /**
+ * Test: The response body should not be cached if it does not have the required properties.
+ *
+ * @since 4.8.0
+ */
+ public function test_get_cached_events_invalid_response() {
+ add_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
+
+ $this->instance->get_events();
+
+ $this->assertFalse( $this->instance->get_cached_events() );
+
+ remove_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) );
+ }
+
+ /**
+ * Simulates an HTTP response with a body that does not have the required properties.
+ *
+ * @since 4.8.0
+ *
+ * @return array A mock response that's missing required properties.
+ */
+ public function _http_request_invalid_response() {
+ return array(
+ 'headers' => '',
+ 'body' => wp_json_encode( array() ),
+ 'response' => array(
+ 'code' => 200,
+ ),
+ 'cookies' => '',
+ 'filename' => '',
+ );
+ }
+
+ /**
+ * Test: With a valid response, get_events() should return an associative array containing a location array and
+ * an events array with individual events that have Unix start/end timestamps.
+ *
+ * @since 4.8.0
+ */
+ public function test_get_events_valid_response() {
+ add_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
+
+ $response = $this->instance->get_events();
+
+ $this->assertNotWPError( $response );
+ $this->assertSameSetsWithIndex( $this->get_user_location(), $response['location'] );
+ $this->assertSame( strtotime( 'next Sunday 1pm' ), $response['events'][0]['start_unix_timestamp'] );
+ $this->assertSame( strtotime( 'next Sunday 2pm' ), $response['events'][0]['end_unix_timestamp'] );
+
+ remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
+ }
+
+ /**
+ * Test: `get_cached_events()` should return the same data as get_events(), including Unix start/end
+ * timestamps for each event.
+ *
+ * @since 4.8.0
+ */
+ public function test_get_cached_events_valid_response() {
+ add_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
+
+ $this->instance->get_events();
+
+ $cached_events = $this->instance->get_cached_events();
+
+ $this->assertNotWPError( $cached_events );
+ $this->assertSameSetsWithIndex( $this->get_user_location(), $cached_events['location'] );
+ $this->assertSame( strtotime( 'next Sunday 1pm' ), $cached_events['events'][0]['start_unix_timestamp'] );
+ $this->assertSame( strtotime( 'next Sunday 2pm' ), $cached_events['events'][0]['end_unix_timestamp'] );
+
+ remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
+ }
+
+ /**
+ * Simulates an HTTP response with valid location and event data.
+ *
+ * @since 4.8.0
+ *
+ * @return array A mock HTTP response with valid data.
+ */
+ public function _http_request_valid_response() {
+ return array(
+ 'headers' => '',
+ 'body' => wp_json_encode(
+ array(
+ 'location' => $this->get_user_location(),
+ 'events' => $this->get_valid_events(),
+ )
+ ),
+ 'response' => array(
+ 'code' => 200,
+ ),
+ 'cookies' => '',
+ 'filename' => '',
+ );
+ }
+
+ /**
+ * Get a sample of valid events.
+ *
+ * @return array[]
+ */
+ protected function get_valid_events() {
+ return array(
+ array(
+ 'type' => 'meetup',
+ 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts',
+ 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/',
+ 'meetup' => 'The East Bay WordPress Meetup Group',
+ 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/',
+ 'start_unix_timestamp' => strtotime( 'next Sunday 1pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Sunday 2pm' ),
+
+ 'location' => array(
+ 'location' => 'Oakland, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.808453,
+ 'longitude' => -122.26593,
+ ),
+ ),
+
+ array(
+ 'type' => 'meetup',
+ 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy',
+ 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/',
+ 'meetup' => 'WordPress Bay Area Foothills Group',
+ 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/',
+ 'start_unix_timestamp' => strtotime( 'next Wednesday 1:30pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Wednesday 2:30pm' ),
+
+ 'location' => array(
+ 'location' => 'Milpitas, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.432813,
+ 'longitude' => -121.907095,
+ ),
+ ),
+
+ array(
+ 'type' => 'wordcamp',
+ 'title' => 'WordCamp San Francisco',
+ 'url' => 'https://sf.wordcamp.org/2020/',
+ 'meetup' => null,
+ 'meetup_url' => null,
+ 'start_unix_timestamp' => strtotime( 'next Saturday' ),
+ 'end_unix_timestamp' => strtotime( 'next Saturday 8pm' ),
+
+ 'location' => array(
+ 'location' => 'San Francisco, CA',
+ 'country' => 'US',
+ 'latitude' => 37.432813,
+ 'longitude' => -121.907095,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Test: `trim_events()` should immediately remove expired events.
+ *
+ * @covers WP_Community_Events::trim_events
+ *
+ * @since 5.5.2
+ */
+ public function test_trim_expired_events() {
+ $trim_events = new ReflectionMethod( $this->instance, 'trim_events' );
+ $trim_events->setAccessible( true );
+
+ $events = $this->get_valid_events();
+
+ // This should be removed because it's already ended.
+ $events[0]['start_unix_timestamp'] = strtotime( '1 hour ago' );
+ $events[0]['end_unix_timestamp'] = strtotime( '2 seconds ago' );
+
+ // This should remain because it hasn't ended yet.
+ $events[1]['start_unix_timestamp'] = strtotime( '2 seconds ago' );
+ $events[1]['end_unix_timestamp'] = strtotime( '+1 hour' );
+
+ $actual = $trim_events->invoke( $this->instance, $events );
+
+ $this->assertCount( 2, $actual );
+ $this->assertSame( $actual[0]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
+ $this->assertSame( $actual[1]['title'], 'WordCamp San Francisco' );
+ }
+
+ /**
+ * Test: get_events() should return the events with the WordCamp pinned in the prepared list.
+ *
+ * @covers WP_Community_Events::trim_events
+ *
+ * @since 4.9.7
+ * @since 5.5.2 Tests `trim_events()` directly instead of indirectly via `get_events()`.
+ */
+ public function test_trim_events_pin_wordcamp() {
+ $trim_events = new ReflectionMethod( $this->instance, 'trim_events' );
+ $trim_events->setAccessible( true );
+
+ $actual = $trim_events->invoke( $this->instance, $this->_events_with_unpinned_wordcamp() );
+
+ /*
+ * San Diego was at index 3 in the mock API response, but pinning puts it at index 2,
+ * so that it remains in the list. The other events should remain unchanged.
+ */
+ $this->assertCount( 3, $actual );
+ $this->assertSame( $actual[0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' );
+ $this->assertSame( $actual[1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
+ $this->assertSame( $actual[2]['title'], 'WordCamp San Diego' );
+ }
+
+ /**
+ * Simulates a scenario where a WordCamp needs to be pinned higher than it's default position.
+ *
+ * @since 4.9.7
+ * @since 5.5.2 Accepts and returns only the events, rather than an entire HTTP response.
+ *
+ * @return array A list of mock events.
+ */
+ public function _events_with_unpinned_wordcamp() {
+ return array(
+ array(
+ 'type' => 'meetup',
+ 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts',
+ 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/',
+ 'meetup' => 'The East Bay WordPress Meetup Group',
+ 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/',
+ 'start_unix_timestamp' => strtotime( 'next Monday 1pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Monday 2pm' ),
+
+ 'location' => array(
+ 'location' => 'Oakland, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.808453,
+ 'longitude' => -122.26593,
+ ),
+ ),
+
+ array(
+ 'type' => 'meetup',
+ 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy',
+ 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/',
+ 'meetup' => 'WordPress Bay Area Foothills Group',
+ 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/',
+ 'start_unix_timestamp' => strtotime( 'next Tuesday 1:30pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Tuesday 2:30pm' ),
+
+ 'location' => array(
+ 'location' => 'Milpitas, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.432813,
+ 'longitude' => -121.907095,
+ ),
+ ),
+
+ array(
+ 'type' => 'meetup',
+ 'title' => 'WordPress Q&A',
+ 'url' => 'https://www.meetup.com/sanjosewp/events/245419844/',
+ 'meetup' => 'The San Jose WordPress Meetup',
+ 'meetup_url' => 'https://www.meetup.com/sanjosewp/',
+ 'start_unix_timestamp' => strtotime( 'next Wednesday 5:30pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Wednesday 6:30pm' ),
+
+ 'location' => array(
+ 'location' => 'Milpitas, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.244194,
+ 'longitude' => -121.889313,
+ ),
+ ),
+
+ array(
+ 'type' => 'wordcamp',
+ 'title' => 'WordCamp San Diego',
+ 'url' => 'https://2018.sandiego.wordcamp.org',
+ 'meetup' => null,
+ 'meetup_url' => null,
+ 'start_unix_timestamp' => strtotime( 'next Thursday 9am' ),
+ 'end_unix_timestamp' => strtotime( 'next Thursday 10am' ),
+
+ 'location' => array(
+ 'location' => 'San Diego, CA',
+ 'country' => 'US',
+ 'latitude' => 32.7220419,
+ 'longitude' => -117.1534513,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Test: get_events() shouldn't stick an extra WordCamp when there's already one that naturally
+ * falls into the list.
+ *
+ * @covers WP_Community_Events::trim_events
+ *
+ * @since 4.9.7
+ * @since 5.5.2 Tests `trim_events()` directly instead of indirectly via `get_events()`.
+ */
+ public function test_trim_events_dont_pin_multiple_wordcamps() {
+ $trim_events = new ReflectionMethod( $this->instance, 'trim_events' );
+ $trim_events->setAccessible( true );
+
+ $actual = $trim_events->invoke( $this->instance, $this->_events_with_multiple_wordcamps() );
+
+ /*
+ * The first meetup should be removed because it's expired, while the next 3 events are selected.
+ * WordCamp LA should not be stuck to the list, because San Diego already appears naturally.
+ */
+ $this->assertCount( 3, $actual );
+ $this->assertSame( $actual[0]['title'], 'WordCamp San Diego' );
+ $this->assertSame( $actual[1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
+ $this->assertSame( $actual[2]['title'], 'WordPress Q&A' );
+ }
+
+ /**
+ * Simulates a valid HTTP response where a WordCamp needs to be pinned higher than it's default position.
+ * no need to pin extra camp b/c one already exists in response
+ *
+ * @since 4.9.7
+ * @since 5.5.2 Tests `trim_events()` directly instead of indirectly via `get_events()`.
+ *
+ * @return array A mock HTTP response.
+ */
+ public function _events_with_multiple_wordcamps() {
+ return array(
+ array(
+ 'type' => 'meetup',
+ 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts',
+ 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/',
+ 'meetup' => 'The East Bay WordPress Meetup Group',
+ 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/',
+ 'start_unix_timestamp' => strtotime( '2 days ago' ) - HOUR_IN_SECONDS,
+ 'end_unix_timestamp' => strtotime( '2 days ago' ),
+
+ 'location' => array(
+ 'location' => 'Oakland, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.808453,
+ 'longitude' => -122.26593,
+ ),
+ ),
+
+ array(
+ 'type' => 'wordcamp',
+ 'title' => 'WordCamp San Diego',
+ 'url' => 'https://2018.sandiego.wordcamp.org',
+ 'meetup' => null,
+ 'meetup_url' => null,
+ 'start_unix_timestamp' => strtotime( 'next Tuesday 9am' ),
+ 'end_unix_timestamp' => strtotime( 'next Tuesday 10am' ),
+
+ 'location' => array(
+ 'location' => 'San Diego, CA',
+ 'country' => 'US',
+ 'latitude' => 32.7220419,
+ 'longitude' => -117.1534513,
+ ),
+ ),
+
+ array(
+ 'type' => 'meetup',
+ 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy',
+ 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/',
+ 'meetup' => 'WordPress Bay Area Foothills Group',
+ 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/',
+ 'start_unix_timestamp' => strtotime( 'next Wednesday 1:30pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Wednesday 2:30pm' ),
+
+ 'location' => array(
+ 'location' => 'Milpitas, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.432813,
+ 'longitude' => -121.907095,
+ ),
+ ),
+
+ array(
+ 'type' => 'meetup',
+ 'title' => 'WordPress Q&A',
+ 'url' => 'https://www.meetup.com/sanjosewp/events/245419844/',
+ 'meetup' => 'The San Jose WordPress Meetup',
+ 'meetup_url' => 'https://www.meetup.com/sanjosewp/',
+ 'start_unix_timestamp' => strtotime( 'next Thursday 5:30pm' ),
+ 'end_unix_timestamp' => strtotime( 'next Thursday 6:30pm' ),
+
+ 'location' => array(
+ 'location' => 'Milpitas, CA, USA',
+ 'country' => 'us',
+ 'latitude' => 37.244194,
+ 'longitude' => -121.889313,
+ ),
+ ),
+
+ array(
+ 'type' => 'wordcamp',
+ 'title' => 'WordCamp Los Angeles',
+ 'url' => 'https://2018.la.wordcamp.org',
+ 'meetup' => null,
+ 'meetup_url' => null,
+ 'start_unix_timestamp' => strtotime( 'next Friday 9am' ),
+ 'end_unix_timestamp' => strtotime( 'next Friday 10am' ),
+
+ 'location' => array(
+ 'location' => 'Los Angeles, CA',
+ 'country' => 'US',
+ 'latitude' => 34.050888,
+ 'longitude' => -118.285426,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Test that get_unsafe_client_ip() properly anonymizes all possible address formats
+ *
+ * @dataProvider data_get_unsafe_client_ip
+ *
+ * @ticket 41083
+ */
+ public function test_get_unsafe_client_ip( $raw_ip, $expected_result ) {
+ $_SERVER['REMOTE_ADDR'] = 'this should not be used';
+ $_SERVER['HTTP_CLIENT_IP'] = $raw_ip;
+ $actual_result = WP_Community_Events::get_unsafe_client_ip();
+
+ $this->assertSame( $expected_result, $actual_result );
+ }
+
+ /**
+ * Provide test cases for `test_get_unsafe_client_ip()`.
+ *
+ * @return array
+ */
+ public function data_get_unsafe_client_ip() {
+ return array(
+ // Handle '::' returned from `wp_privacy_anonymize_ip()`.
+ array(
+ 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001',
+ false,
+ ),
+
+ // Handle '0.0.0.0' returned from `wp_privacy_anonymize_ip()`.
+ array(
+ 'unknown',
+ false,
+ ),
+
+ // Valid IPv4.
+ array(
+ '198.143.164.252',
+ '198.143.164.0',
+ ),
+
+ // Valid IPv6.
+ array(
+ '2a03:2880:2110:df07:face:b00c::1',
+ '2a03:2880:2110:df07::',
+ ),
+ );
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsadminwpMediaListTablephpfromrev51638trunktestsphpunittestsadminincludesMediaListTablephp"></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/admin/wpMediaListTable.php (from rev 51638, trunk/tests/phpunit/tests/admin/includesMediaListTable.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/wpMediaListTable.php (rev 0)
+++ trunk/tests/phpunit/tests/admin/wpMediaListTable.php 2021-08-19 13:08:43 UTC (rev 51639)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,50 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group admin
+ */
+class Tests_Admin_wpMediaListTable extends WP_UnitTestCase {
+
+ public static function set_up_before_class() {
+ parent::set_up_before_class();
+
+ require_once ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php';
+ }
+
+ /**
+ * Tests that a call to WP_Media_List_Table::prepare_items() on a site without any scheduled events
+ * does not result in a PHP warning.
+ *
+ * The warning that we should not see:
+ * PHP 5.6 - 7.4: `Invalid argument supplied for foreach()`.
+ * PHP 8.0 and higher: `Warning: foreach() argument must be of type array|object, bool given`.
+ *
+ * Note: This does not test the actual functioning of the WP_Media_List_Table::prepare_items() method.
+ * It just and only tests for/against the PHP warning.
+ *
+ * @ticket 53949
+ * @covers WP_Media_List_Table::prepare_items
+ */
+ public function test_prepare_items_without_cron_option_does_not_throw_warning() {
+ global $wp_query;
+
+ // Note: setMethods() is deprecated in PHPUnit 9, but still supported.
+ $mock = $this->getMockBuilder( WP_Media_List_Table::class )
+ ->disableOriginalConstructor()
+ ->disallowMockingUnknownTypes()
+ ->setMethods( array( 'set_pagination_args' ) )
+ ->getMock();
+
+ $mock->expects( $this->once() )
+ ->method( 'set_pagination_args' );
+
+ $wp_query->query_vars['posts_per_page'] = 10;
+ delete_option( 'cron' );
+
+ // Verify that the cause of the error is in place.
+ $this->assertFalse( _get_cron_array(), '_get_cron_array() does not return false' );
+
+ // If this test does not error out due to the PHP warning, we're good.
+ $mock->prepare_items();
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>