Skip to content
Merged
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
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
branches: [main, develop, 'feature/**', 'hotfix/**', 'release/**']
pull_request:
branches: [main, develop]
# Nightly, on the default branch: the browser tests in Firefox and WebKit as well as
# Chromium, which pull requests run alone to stay fast.
schedule:
- cron: '30 3 * * *'
workflow_dispatch:

jobs:
tests:
Expand Down Expand Up @@ -238,6 +243,11 @@ jobs:
# authoritative: a deployment dumped with --classmap-authoritative answers
# from the classmap alone. Theme and plugin classes are autoloaded at
# runtime, and every front-end page once answered 404 there (#320).
# Chromium on pushes and pull requests; all three engines on the nightly and on a
# manual run.
env:
E2E_BROWSERS: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && 'chromium,firefox,webkit' || 'chromium' }}

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -328,7 +338,7 @@ jobs:
working-directory: packages/framework/tests/e2e
run: |
npm ci
npx playwright install --with-deps chromium
npx playwright install --with-deps ${E2E_BROWSERS//,/ }

# DDEV serves HTTPS with a mkcert certificate when mkcert is present.
# Say which case the runner is in rather than guessing.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Plugin\E2eFeatures\Endpoints;

use Pollora\Attributes\WpRestRoute;
use Pollora\Attributes\WpRestRoute\Method;

/**
* What `__()` answers, on each side of the helper that shares the name: WordPress keeps
* its own as `__wp()`, and `__()` sends a call with a text domain to WordPress and a call
* with replacements to Laravel. This plugin's fr_FR catalogue is what WordPress finds,
* whatever the site's language.
*/
#[WpRestRoute('e2e/v1', '/translations')]
class Translations
{
/** @return array{wordpress: string, untranslated: string, laravel: string, wpNative: string} */
#[Method('GET')]
public function show(): array
{
// Loaded as the catalogue of the current locale, whatever the site's language:
// since WordPress 6.5 translations are kept per locale, so loading it as fr_FR
// on an en_US site would leave __() nothing to find.
unload_textdomain('e2e-features');
load_textdomain('e2e-features', WP_PLUGIN_DIR.'/e2e-features/languages/e2e-features-fr_FR.mo', determine_locale());

return [
'wordpress' => __('E2E greeting', 'e2e-features'),
'untranslated' => __('E2E string outside the catalogue', 'e2e-features'),
'laravel' => __('Shipping :brand', ['brand' => 'Example']),
'wpNative' => __wp('E2E greeting', 'e2e-features'),
];
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Pollora browser test fixture: the catalogue the i18n test reads in fr_FR.
msgid ""
msgstr ""
"Project-Id-Version: E2E Features\n"
"Language: fr_FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Domain: e2e-features\n"

msgid "E2E greeting"
msgstr "Bonjour depuis le catalogue"
17 changes: 16 additions & 1 deletion tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { defineConfig, devices } from '@playwright/test';
* WP_BASE_URL WordPress itself (`siteurl`), e.g. https://pollora-test.ddev.site/cms/ —
* read by @wordpress/e2e-test-utils-playwright for wp-admin, login and REST
* E2E_WP_CLI how to run WP-CLI against that site, e.g. "ddev wp" (default)
* E2E_BROWSERS comma-separated: chromium (default), firefox, webkit — the nightly runs all three
*/
const homeUrl = process.env.E2E_HOME_URL ?? 'https://pollora-test.ddev.site';
// Trailing slash: relative paths such as wp-login.php must resolve inside /cms.
Expand All @@ -29,6 +30,20 @@ if (! process.env.NODE_EXTRA_CA_CERTS) {
}
}

const browsers: Record<string, string> = {
chromium: 'Desktop Chrome',
firefox: 'Desktop Firefox',
webkit: 'Desktop Safari',
};

const projects = (process.env.E2E_BROWSERS ?? 'chromium').split(',').map((name) => name.trim()).map((name) => {
if (! (name in browsers)) {
throw new Error(`E2E_BROWSERS: unknown browser "${name}" (known: ${Object.keys(browsers).join(', ')})`);
}

return { name, use: { ...devices[browsers[name]] } };
});

export default defineConfig({
testDir: './specs',
globalSetup: './global-setup.ts',
Expand All @@ -46,5 +61,5 @@ export default defineConfig({
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
projects,
});
15 changes: 15 additions & 0 deletions tests/e2e/specs/features.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ test.describe('Assets', () => {
});
});

test.describe('Translations through __()', () => {
test("a text domain goes to WordPress's catalogues, replacements to Laravel", async () => {
const context = await visitor();
const translations = await (await context.get(homeUrl('/wp-json/e2e/v1/translations'))).json();
await context.dispose();

expect(translations).toEqual({
wordpress: 'Bonjour depuis le catalogue',
untranslated: 'E2E string outside the catalogue',
laravel: 'Shipping Example',
wpNative: 'Bonjour depuis le catalogue',
});
});
});

test.describe('The active theme', () => {
test('registers the menu locations its config/menus.php declares', async ({ requestUtils }) => {
const configFile = join(siteDir, 'themes', activeTheme(), 'config', 'menus.php');
Expand Down
Loading