Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/unit-tests-suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ suites:
paths:
- 'environments/support-forums/**'

wordpress-tv:
type: wordpress
name: WordPress.tv Theme
script: wptv:test
paths:
- 'environments/wordpress-tv/**'
- 'wordpress.tv/public_html/wp-content/themes/wptv-27/**'

sso:
type: wordpress
name: WordPress.org SSO
Expand Down
39 changes: 39 additions & 0 deletions environments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,45 @@ All accounts use the password `password`.

**Block editor:** the forums use the block editor through [Blocks Everywhere](https://github.com/Automattic/blocks-everywhere), which is not installed here — it needs a Gutenberg old enough to break against WordPress trunk until [Automattic/blocks-everywhere#211](https://github.com/Automattic/blocks-everywhere/pull/211) lands. `Plugin::__construct()` loads the block support only when that plugin is present, so the environment runs on bbPress' plain editor until then.

### WordPress.tv

A local instance of [WordPress.tv](https://wordpress.tv/) with the `wptv-27` block theme and Jetpack, which provides the VideoPress player and the sharing buttons.

**Start:**

```bash
npm run wptv:env start
```

The first start imports about 60 recent, featured, Education and How-To videos from WordPress.tv. It brings their speakers, events, languages, categories and producers, plus the site's pages. Each video embeds its real VideoPress video, so the players stream and the thumbnails load. A pending submission is added for the moderation tools.

**Access:** `http://localhost:8888`. Log in with `admin` / `password` to edit videos or moderate submissions.

**Import new videos** (clears the import flag, then imports the videos that are missing):

```bash
npm run wptv:refresh
```

**WP CLI:**

```bash
npm run wptv:env -- run cli -- wp <command>
```

**Run tests** (the theme's PHPUnit suite, in a dedicated test environment):

```bash
npm run wptv:test
```

**What differs from production.** WordPress.tv runs on WordPress.com, which provides VideoPress internals that Jetpack doesn't have. Without them, the theme leaves out what it builds from them:

- Download links, subtitle tracks, and the video data in JSON-LD and Open Graph tags are missing, and `/api/videos.json` lists no video files.
- `/oembed/` and `/unisubs/` answer with an error for every video.
- Jetpack runs in offline mode. `mocks/wptv-local.php` turns on the VideoPress and Sharing modules anyway, so the players and sharing buttons render. The Like button needs a connection, so it doesn't show, and the editor asks to connect Jetpack.
- Uploads from the submission form stay local instead of going to VideoPress, so every submission gets the State of the Word 2024 video.

### Photo Directory

A test-only environment for the Photo Directory plugin in `wordpress.org/public_html/wp-content/plugins/photo-directory/`. The plugin is mounted at `wp-content/plugins/photo-directory` but not activated: its test bootstrap loads only the classes under test, so the suite runs without Google Cloud credentials.
Expand Down
59 changes: 59 additions & 0 deletions environments/mocks/wptv-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Plugin Name: WordPress.tv Local
* Description: Stands in for what WordPress.com provides WordPress.tv, so the theme runs locally.
*
* @package WordPressdotorg\Environments
*/

declare( strict_types = 1 );

namespace WordPressdotorg\Environments\WordPressTV_Local;

/**
* VideoPress GUID of State of the Word 2024, given to every local submission.
*/
const SUBMISSION_GUID = 'NxCFxkXD';

/**
* Jetpack modules WordPress.tv uses that offline mode skips, because they need a connection.
*/
const MODULES = array( 'videopress', 'sharedaddy' );

/**
* Lets WordPress.tv's Jetpack modules load in offline mode.
*
* @param array|false $module Module data.
* @param string $slug Module slug.
* @return array|false
*/
function allow_offline( array|false $module, string $slug ): array|false {
if ( $module && in_array( $slug, MODULES, true ) ) {
$module['requires_connection'] = false;
$module['requires_user_connection'] = false;
}

return $module;
}
add_filter( 'jetpack_get_module', __NAMESPACE__ . '\allow_offline', 10, 2 );

/**
* Turns WordPress.tv's Jetpack modules on, along with the Blocks module.
*
* @param string[] $modules Active module slugs.
* @return string[]
*/
function activate( array $modules ): array {
return array_merge( $modules, array( 'blocks' ), MODULES );
}
add_filter( 'jetpack_active_modules', __NAMESPACE__ . '\activate' );

/**
* Gives local uploads, which never reach VideoPress, a published video's GUID.
*
* @return string VideoPress GUID.
*/
function submission_guid(): string {
return SUBMISSION_GUID;
}
add_filter( 'wptv_pre_submission_video_guid', __NAMESPACE__ . '\submission_guid' );
4 changes: 4 additions & 0 deletions environments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"support:refresh": "npm run support:env -- run cli -- wp option delete wporg_support_env_seeded; bash support-forums/bin/after-start.sh",
"support:test:env": "wp-env --config support-forums/.wp-env.test.json",
"support:test": "npm run support:test:env -- start && npm run support:test:env -- run cli --env-cwd=wp-content/plugins/support-forums phpunit",
"wptv:env": "wp-env --config wordpress-tv/.wp-env.json",
"wptv:refresh": "npm run wptv:env -- run cli -- wp option delete wptv_env_imported; npm run wptv:env -- run cli -- wp eval-file wp-content/env-bin/import-videos.php",
"wptv:test:env": "wp-env --config wordpress-tv/.wp-env.test.json",
"wptv:test": "npm run wptv:test:env -- start && npm run wptv:test:env -- run cli --env-cwd=wp-content/themes/wptv-27 phpunit",
"freescout:env": "docker compose --file freescout/docker-compose.yml",
"freescout:start": "npm run freescout:env -- up --detach --build --wait && npm run freescout:setup",
"freescout:setup": "npm run freescout:env -- exec -T --user www-data app bash /srv/env/bin/setup.sh",
Expand Down
23 changes: 23 additions & 0 deletions environments/wordpress-tv/.wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"core": "https://wordpress.org/nightly-builds/wordpress-latest.zip",
"phpVersion": "8.4",
"testsEnvironment": false,
"plugins": [
"https://downloads.wordpress.org/plugin/jetpack.zip"
],
"themes": [
"../wordpress.tv/public_html/wp-content/themes/wptv-27"
],
"mappings": {
"wp-content/mu-plugins/wporg-dev-login.php": "./mocks/mu-plugins/wporg-dev-login.php",
"wp-content/mu-plugins/wptv-local.php": "./mocks/wptv-local.php",
"wp-content/env-bin": "./wordpress-tv/bin"
},
"lifecycleScripts": {
"afterStart": "bash wordpress-tv/bin/after-start.sh"
},
"config": {
"WP_DEBUG": true,
"JETPACK_DEV_DEBUG": true
}
}
12 changes: 12 additions & 0 deletions environments/wordpress-tv/.wp-env.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"core": "https://wordpress.org/nightly-builds/wordpress-latest.zip",
"phpVersion": "8.4",
"testsEnvironment": false,
"plugins": [],
"themes": [
"../wordpress.tv/public_html/wp-content/themes/wptv-27"
],
"lifecycleScripts": {
"afterStart": "bash wordpress-tv/bin/after-start-test.sh"
}
}
14 changes: 14 additions & 0 deletions environments/wordpress-tv/bin/after-start-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Runs after wp-env start for the test environment.
# Installs PHPUnit 11 and Yoast polyfills in the test container.
#

set -euo pipefail

CONFIG="--config wordpress-tv/.wp-env.test.json"
RUN="npx wp-env $CONFIG run cli"

echo "Installing PHPUnit 11 and polyfills..."
$RUN composer global require -W phpunit/phpunit:^11.0 2>&1
$RUN composer require --dev yoast/phpunit-polyfills:^4.0 --working-dir=/wordpress-phpunit 2>&1
20 changes: 20 additions & 0 deletions environments/wordpress-tv/bin/after-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Runs after wp-env start. Sets up the site like WordPress.tv and imports its videos once.
#

CONFIG="--config wordpress-tv/.wp-env.json"
WP="npx wp-env $CONFIG run cli --"

$WP wp option update blogname 'WordPress.tv'
$WP wp option update blogdescription 'WordPress-related videos curated and moderated by the WordPress.org community'
$WP wp rewrite structure '/%year%/%monthnum%/%day%/%postname%/' --hard
# The theme registers the taxonomies the import assigns.
$WP wp theme activate wptv-27 || exit 1

# Anonymous submissions are filed under this account.
if ! $WP wp user get anonvideoupload --field=ID > /dev/null 2>&1; then
$WP wp user create anonvideoupload anonvideoupload@example.org --role=author --porcelain > /dev/null && echo "Created user: anonvideoupload"
fi

$WP wp eval-file wp-content/env-bin/import-videos.php
Loading
Loading