-
+
+
+ list_template_conditional_options( AMP_Theme_Support::get_supportable_templates() );
+ ?>
+
+
+
+
-
+
diff --git a/includes/class-amp-reader-themes.php b/src/Admin/ReaderThemes.php
similarity index 98%
rename from includes/class-amp-reader-themes.php
rename to src/Admin/ReaderThemes.php
index aad90047775..b4da0d8127c 100644
--- a/includes/class-amp-reader-themes.php
+++ b/src/Admin/ReaderThemes.php
@@ -6,12 +6,17 @@
* @since 1.6.0
*/
+namespace AmpProject\AmpWP\Admin;
+
+use AMP_Core_Theme_Sanitizer;
+use WP_Upgrader;
+
/**
- * Class AMP_Reader_Themes.
+ * Handles reader themes.
*
* @since 1.6.0
*/
-final class AMP_Reader_Themes {
+final class ReaderThemes {
/**
* Formatted theme data.
*
diff --git a/src/AmpWpPlugin.php b/src/AmpWpPlugin.php
index 763472cfc46..66f5d3d7f56 100644
--- a/src/AmpWpPlugin.php
+++ b/src/AmpWpPlugin.php
@@ -8,6 +8,10 @@
namespace AmpProject\AmpWP;
use AmpProject\AmpWP\Admin\DevToolsUserAccess;
+use AmpProject\AmpWP\Admin\GoogleFonts;
+use AmpProject\AmpWP\Admin\OnboardingWizardSubmenu;
+use AmpProject\AmpWP\Admin\OnboardingWizardSubmenuPage;
+use AmpProject\AmpWP\Admin\OptionsMenu;
use AmpProject\AmpWP\Admin\PluginActivationNotice;
use AmpProject\AmpWP\Admin\ReenableCssTransientCachingAjaxAction;
use AmpProject\AmpWP\Admin\SiteHealth;
@@ -62,6 +66,10 @@ protected function get_service_classes() {
'plugin_registry' => PluginRegistry::class,
'plugin_suppression' => PluginSuppression::class,
'mobile_redirection' => MobileRedirection::class,
+ 'admin.google_fonts' => GoogleFonts::class,
+ 'admin.options_menu' => OptionsMenu::class,
+ 'admin.onboarding_menu' => OnboardingWizardSubmenu::class,
+ 'admin.onboarding_wizard' => OnboardingWizardSubmenuPage::class,
'reader_theme_loader' => ReaderThemeLoader::class,
'amp_slug_customization_watcher' => AmpSlugCustomizationWatcher::class,
];
diff --git a/src/MobileRedirection.php b/src/MobileRedirection.php
index c38af2de8d2..52bfdc7bf7f 100644
--- a/src/MobileRedirection.php
+++ b/src/MobileRedirection.php
@@ -43,7 +43,6 @@ final class MobileRedirection implements Service, Registerable {
*/
public function register() {
add_filter( 'amp_default_options', [ $this, 'filter_default_options' ] );
- add_action( 'amp_options_menu_items', [ $this, 'add_settings_field' ], 10 );
add_filter( 'amp_options_updating', [ $this, 'sanitize_options' ], 10, 2 );
if ( AMP_Options_Manager::get_option( Option::MOBILE_REDIRECT ) ) {
@@ -71,58 +70,12 @@ public function filter_default_options( $defaults ) {
* @return array Sanitized options.
*/
public function sanitize_options( $options, $new_options ) {
- $options[ Option::MOBILE_REDIRECT ] = (
- isset( $new_options[ Option::MOBILE_REDIRECT ] )
- &&
- rest_sanitize_boolean( $new_options[ Option::MOBILE_REDIRECT ] )
- );
+ if ( isset( $new_options[ Option::MOBILE_REDIRECT ] ) ) {
+ $options[ Option::MOBILE_REDIRECT ] = rest_sanitize_boolean( $new_options[ Option::MOBILE_REDIRECT ] );
+ }
return $options;
}
- /**
- * Add settings field.
- */
- public function add_settings_field() {
- add_settings_field(
- Option::MOBILE_REDIRECT,
- __( 'Mobile Redirection', 'amp' ),
- [ $this, 'render_setting_field' ],
- AMP_Options_Manager::OPTION_NAME,
- 'general',
- [
- 'class' => 'amp-mobile-redirect',
- ]
- );
- }
-
- /**
- * Render mobile redirect setting.
- */
- public function render_setting_field() {
- ?>
-
-
- value="true">
-
-
-
-
- 'amp-suppressed-plugins',
]
@@ -275,7 +275,7 @@ public function render_suppressed_plugins() {
}
#suppressed-plugins-table .column-status {
- width: 120px;
+ width: 150px;
}
#suppressed-plugins-table .column-status > select {
diff --git a/src/ReaderThemeLoader.php b/src/ReaderThemeLoader.php
index 2b1a8985f38..7e54f8b20f1 100644
--- a/src/ReaderThemeLoader.php
+++ b/src/ReaderThemeLoader.php
@@ -12,9 +12,9 @@
use AmpProject\AmpWP\Infrastructure\Service;
use AMP_Options_Manager;
use AMP_Theme_Support;
+use AmpProject\AmpWP\Admin\ReaderThemes;
use WP_Theme;
use WP_Customize_Manager;
-use AMP_Reader_Themes;
/**
* Switches to the designated Reader theme when template mode enabled and when requesting an AMP page.
@@ -39,7 +39,7 @@ public static function is_needed() {
return (
AMP_Theme_Support::READER_MODE_SLUG === AMP_Options_Manager::get_option( Option::THEME_SUPPORT )
&&
- AMP_Reader_Themes::DEFAULT_READER_THEME !== AMP_Options_Manager::get_option( Option::READER_THEME )
+ ReaderThemes::DEFAULT_READER_THEME !== AMP_Options_Manager::get_option( Option::READER_THEME )
);
}
diff --git a/tests/e2e/specs/admin/amp-options.js b/tests/e2e/specs/admin/amp-options.js
index 7fdedbde515..aa30062ffe8 100644
--- a/tests/e2e/specs/admin/amp-options.js
+++ b/tests/e2e/specs/admin/amp-options.js
@@ -3,16 +3,214 @@
*/
import { visitAdminPage } from '@wordpress/e2e-test-utils';
-describe( 'AMP Settings Screen', () => {
- it( 'should display a welcome notice', async () => {
+/**
+ * Internal dependencies
+ */
+import { completeWizard, cleanUpSettings, clickMode, selectReaderTheme } from '../../utils/onboarding-wizard-utils';
+import { installTheme } from '../../utils/install-theme';
+import { activateTheme } from '../../utils/activate-theme';
+import { themeInstalled } from '../../utils/theme-installed';
+import { deleteTheme } from '../../utils/delete-theme';
+
+async function testStandardAndTransitionalSupportedTemplateToggle() {
+ await expect( page ).toMatchElement( '.supported-templates' );
+ await expect( page ).toClick( '.supported-templates .amp-setting-toggle input:checked' );
+ await expect( page ).toMatchElement( '.supported-templates .amp-setting-toggle input:not(:checked)' );
+ await expect( page ).not.toMatchElement( '#supported_templates_fieldset.hidden' );
+ await expect( page ).toMatchElement( '#amp-options-supported-templates-is_author:not(:checked)' );
+ await expect( page ).toClick( '#amp-options-supported-templates-is_archive:not(:checked)' );
+ await expect( page ).toMatchElement( '#amp-options-supported-templates-is_archive:checked' );
+ await expect( page ).toMatchElement( '#amp-options-supported-templates-is_author:checked' );
+}
+
+async function testMobileRedirectToggle() {
+ await expect( page ).toMatchElement( '.mobile-redirection' );
+ await expect( page ).toClick( '.mobile-redirection .amp-setting-toggle input:checked' );
+ await expect( page ).toMatchElement( '.mobile-redirection .amp-setting-toggle input:not(:checked)' );
+}
+
+describe( 'AMP settings screen newly activated', () => {
+ beforeEach( async () => {
+ await visitAdminPage( 'admin.php', 'page=amp-options' );
+ } );
+
+ it( 'should not display the old welcome notice', async () => {
+ await expect( page ).not.toMatchElement( '.amp-welcome-notice h2', { text: 'Welcome to AMP for WordPress' } );
+ } );
+
+ it( 'has main page components', async () => {
+ await expect( page ).toMatchElement( '.amp-plugin-notice' );
+ await expect( page ).toMatchElement( 'h1', { text: 'AMP Settings' } );
+ await expect( page ).toMatchElement( 'h2', { text: 'Configure AMP' } );
+ await expect( page ).toMatchElement( 'a', { text: 'Open Wizard' } );
+ await expect( page ).not.toMatchElement( '.template-mode-selection input:checked' );
+ await expect( page ).toPassAxeTests( {
+ exclude: [
+ '#wpadminbar',
+ ],
+ } );
+ } );
+
+ it( 'shows expected elements for standard mode', async () => {
+ await clickMode( 'standard' );
+ await expect( page ).toMatchElement( '#template-mode-standard:checked' );
+
+ await testStandardAndTransitionalSupportedTemplateToggle();
+
+ await expect( page ).not.toMatchElement( '.mobile-redirection' );
+ await expect( page ).not.toMatchElement( '.reader-themes' );
+ } );
+
+ it( 'shows expected elements for transitional mode', async () => {
+ await clickMode( 'transitional' );
+ await expect( page ).toMatchElement( '#template-mode-transitional:checked' );
+
+ await testStandardAndTransitionalSupportedTemplateToggle();
+ await testMobileRedirectToggle();
+ await expect( page ).not.toMatchElement( '.reader-themes' );
+ } );
+
+ it( 'shows expected elements for reader mode', async () => {
+ await clickMode( 'reader' );
+ await expect( page ).toMatchElement( '#template-mode-reader:checked' );
+
+ await testMobileRedirectToggle();
+
+ await expect( page ).toMatchElement( '.reader-themes' );
+ await expect( page ).not.toMatchElement( '#theme-card__legacy:checked' );
+ await selectReaderTheme();
+ await expect( page ).toMatchElement( '#theme-card__legacy:checked' );
+
+ await expect( page ).not.toMatchElement( '#theme-card__twentytwenty:checked' ); // Active theme is hidden.
+
+ await selectReaderTheme( 'twentynineteen' );
+ await expect( page ).toMatchElement( '#theme-card__twentynineteen:checked' );
+ } );
+} );
+
+describe( 'Settings screen submit button', () => {
+ it( 'has the correct disabled state', async () => {
await visitAdminPage( 'admin.php', 'page=amp-options' );
- await expect( page ).toMatchElement( '.amp-welcome-notice h2', { text: 'Welcome to AMP for WordPress' } );
+ await expect( page ).toMatchElement( '.settings-footer button:disabled' );
+
+ await clickMode( 'standard' );
+ await expect( page ).toMatchElement( '.settings-footer button:not(:disabled)' );
+
+ await clickMode( 'reader' );
+ await expect( page ).toMatchElement( '.settings-footer button:disabled' );
+
+ await clickMode( 'transitional' );
+ await expect( page ).toMatchElement( '.settings-footer button:not(:disabled)' );
+
+ await clickMode( 'reader' );
+ await expect( page ).toMatchElement( '.settings-footer button:disabled' );
+
+ await selectReaderTheme( 'twentynineteen' );
+ await expect( page ).toMatchElement( '.settings-footer button:not(:disabled)' );
} );
+} );
+
+describe( 'Settings screen when reader theme is active theme', () => {
+ it( 'disables reader theme if is currently active on site', async () => {
+ await installTheme( 'twentynineteen' );
+ await activateTheme( 'twentynineteen' );
- it( 'should display a message about theme compatibility', async () => {
await visitAdminPage( 'admin.php', 'page=amp-options' );
- await expect( page ).toMatchElement( '.notice-success p', { text: 'Your active theme is known to work well in standard or transitional mode.' } );
+ await clickMode( 'reader' );
+
+ await expect( page ).toMatchElement( '.amp-notice__body', { text: /^Your active theme/ } );
+
+ await activateTheme( 'twentytwenty' );
} );
} );
+
+describe( 'Mode info notices', () => {
+ it( 'shows expected notices for theme with built-in support', async () => {
+ await activateTheme( 'twentytwenty' );
+ await visitAdminPage( 'admin.php', 'page=amp-options' );
+
+ await expect( page ).toMatchElement( '#template-mode-standard-container .amp-notice--info' );
+ await expect( page ).toMatchElement( '#template-mode-transitional-container .amp-notice--info' );
+
+ await clickMode( 'reader' );
+
+ await expect( page ).toMatchElement( '#template-mode-reader-container .amp-notice--info' );
+ } );
+
+ it.todo( 'shows expected notices for theme with paired flag false' );
+ it.todo( 'shows expected notices for theme that only supports reader mode' );
+} );
+
+describe( 'Show all templates toggle', () => {
+ it.each( [ 'reader', 'standard', 'transitional' ] )( 'shows expected supported template state for %s mode', async ( mode ) => {
+ await visitAdminPage( 'admin.php', 'page=amp-options' );
+
+ await expect( page ).toMatchElement( '.hidden .supported-templates' );
+
+ await clickMode( mode );
+
+ if ( 'reader' === mode ) {
+ await expect( page ).toMatchElement( '.hidden .supported-templates' );
+ await selectReaderTheme( 'twentysixteen' );
+ }
+
+ await expect( page ).not.toMatchElement( '.hidden .supported-templates' );
+ await expect( page ).not.toMatchElement( '.amp-setting-toggle--disabled' );
+
+ if ( 'reader' === mode ) {
+ await selectReaderTheme( 'legacy' );
+ await expect( page ).toMatchElement( '.amp-setting-toggle--disabled' );
+ }
+ } );
+} );
+
+describe( 'AMP settings reader theme install', () => {
+ beforeAll( async () => {
+ if ( themeInstalled( 'twentysixteen' ) ) {
+ await deleteTheme( 'twentysixteen' );
+ }
+ } );
+
+ afterAll( async () => {
+ await cleanUpSettings();
+ } );
+
+ it( 'can install a theme', async () => {
+ await visitAdminPage( 'admin.php', 'page=amp-options' );
+ await clickMode( 'reader' );
+ await selectReaderTheme( 'twentysixteen' );
+
+ await expect( page ).toClick( '.settings-footer button' );
+ await page.waitForSelector( '.settings-footer button:disabled' );
+ await page.waitForSelector( '.settings-footer button:not(:disabled)' );
+
+ const success = await themeInstalled( 'twentysixteen' );
+ expect( success ).toBe( true );
+ } );
+} );
+
+describe( 'AMP Settings Screen after wizard', () => {
+ beforeAll( async () => {
+ await completeWizard( { technical: true, mode: 'standard' } );
+ await visitAdminPage( 'admin.php', 'page=amp-options' );
+ } );
+
+ afterAll( async () => {
+ await cleanUpSettings();
+ } );
+
+ it( 'has main page components', async () => {
+ await expect( page ).not.toMatchElement( '.amp-plugin-notice' );
+ await expect( page ).toMatchElement( 'h1', { text: 'AMP Settings' } );
+ await expect( page ).toMatchElement( 'h2', { text: 'AMP Settings Configured' } );
+ await expect( page ).toMatchElement( 'a', { text: 'Reopen Wizard' } );
+ await expect( page ).toPassAxeTests( {
+ exclude: [
+ '#wpadminbar',
+ ],
+ } );
+ } );
+} );
+
diff --git a/tests/e2e/specs/admin/mobile-redirect.js b/tests/e2e/specs/admin/mobile-redirect.js
index edd886af42a..4f539bce49c 100644
--- a/tests/e2e/specs/admin/mobile-redirect.js
+++ b/tests/e2e/specs/admin/mobile-redirect.js
@@ -6,27 +6,30 @@ const { visitAdminPage } = require( '@wordpress/e2e-test-utils/build/visit-admin
/**
* Internal dependencies
*/
-const { completeWizard, cleanUpWizard } = require( '../../utils/onboarding-wizard-utils' );
+const { completeWizard, cleanUpSettings } = require( '../../utils/onboarding-wizard-utils' );
+
+const toggleSelector = '.amp-setting-toggle input[type="checkbox"]';
describe( 'Mobile redirect settings', () => {
afterEach( async () => {
- await visitAdminPage( 'admin.php', 'page=amp-setup' );
- await cleanUpWizard();
+ await visitAdminPage( 'admin.php', 'page=amp-onboarding-wizard' );
+ await cleanUpSettings();
} );
it( 'persists the mobile redirect setting on', async () => {
await completeWizard( { mode: 'reader' } );
await visitAdminPage( 'admin.php', 'page=amp-options' );
- await page.waitForSelector( '#mobile_redirect' );
- await expect( page ).toMatchElement( '#mobile_redirect:checked' );
+ await page.waitForSelector( toggleSelector );
+ await expect( page ).toMatchElement( `${ toggleSelector }:checked` );
} );
- it( 'persists the mobile redirect setting off', async () => {
+ // eslint-disable-next-line jest/no-disabled-tests
+ it.skip( 'persists the mobile redirect setting off', async () => {
await completeWizard( { mode: 'reader', mobileRedirect: false } );
await visitAdminPage( 'admin.php', 'page=amp-options' );
- await page.waitForSelector( '#mobile_redirect' );
- await expect( page ).not.toMatchElement( '#mobile_redirect:checked' );
+ await page.waitForSelector( toggleSelector );
+ await expect( page ).not.toMatchElement( `${ toggleSelector }:checked` );
} );
} );
diff --git a/tests/e2e/specs/amp-onboarding/done.js b/tests/e2e/specs/amp-onboarding/done.js
index 65fb400105e..5915207f2e1 100644
--- a/tests/e2e/specs/amp-onboarding/done.js
+++ b/tests/e2e/specs/amp-onboarding/done.js
@@ -2,11 +2,11 @@
/**
* Internal dependencies
*/
-import { completeWizard, testCloseButton, cleanUpWizard } from '../../utils/onboarding-wizard-utils';
+import { completeWizard, testCloseButton, cleanUpSettings } from '../../utils/onboarding-wizard-utils';
describe( 'Done', () => {
afterEach( async () => {
- await cleanUpWizard();
+ await cleanUpSettings();
} );
it( 'renders standard mode done screen', async () => {
diff --git a/tests/e2e/specs/amp-onboarding/exit-links.js b/tests/e2e/specs/amp-onboarding/exit-links.js
index 3b480076256..ff980d8e4e1 100644
--- a/tests/e2e/specs/amp-onboarding/exit-links.js
+++ b/tests/e2e/specs/amp-onboarding/exit-links.js
@@ -5,7 +5,7 @@ const { visitAdminPage } = require( '@wordpress/e2e-test-utils/build/visit-admin
/**
* Internal dependencies
*/
-const { goToOnboardingWizard, completeWizard, cleanUpWizard } = require( '../../utils/onboarding-wizard-utils' );
+const { goToOnboardingWizard, completeWizard, cleanUpSettings } = require( '../../utils/onboarding-wizard-utils' );
describe( 'Onboarding wizard exit links', () => {
it( 'if no previous page, returns to settings when clicking close', async () => {
@@ -20,9 +20,9 @@ describe( 'Onboarding wizard exit links', () => {
await page.waitForSelector( '.wp-admin' );
await page.evaluate( () => {
- document.querySelector( 'a[href="admin.php?page=amp-setup"]' ).click();
+ document.querySelector( 'a[href="admin.php?page=amp-onboarding-wizard"]' ).click();
} );
- await page.waitForSelector( '#amp-setup' );
+ await page.waitForSelector( '#amp-onboarding-wizard' );
await expect( page ).toClick( 'a', { text: 'Close' } );
await page.waitForSelector( '.wp-admin' );
await expect( page ).toMatchElement( 'h1', { text: 'Dashboard' } );
@@ -34,7 +34,6 @@ describe( 'Onboarding wizard exit links', () => {
await page.waitForSelector( '.wp-admin' );
await expect( page ).toMatchElement( 'h1', { text: 'AMP Settings' } );
- await goToOnboardingWizard();
- await cleanUpWizard();
+ await cleanUpSettings();
} );
} );
diff --git a/tests/e2e/specs/amp-onboarding/reader-themes.js b/tests/e2e/specs/amp-onboarding/reader-themes.js
index 51da5092a5d..a05df7b7859 100644
--- a/tests/e2e/specs/amp-onboarding/reader-themes.js
+++ b/tests/e2e/specs/amp-onboarding/reader-themes.js
@@ -19,13 +19,13 @@ describe( 'Reader themes', () => {
it( 'should allow different themes to be selected', async () => {
await selectReaderTheme( 'legacy' );
- await expect( page ).toMatchElement( '.selectable--selected h2', { text: 'AMP Legacy' } );
+ await expect( page ).toMatchElement( '.selectable--selected h3', { text: 'AMP Legacy' } );
await selectReaderTheme( 'twentynineteen' );
- await expect( page ).toMatchElement( '.selectable--selected h2', { text: 'Twenty Nineteen' } );
+ await expect( page ).toMatchElement( '.selectable--selected h3', { text: 'Twenty Nineteen' } );
await selectReaderTheme( 'twentysixteen' );
- await expect( page ).toMatchElement( '.selectable--selected h2', { text: 'Twenty Sixteen' } );
+ await expect( page ).toMatchElement( '.selectable--selected h3', { text: 'Twenty Sixteen' } );
testNextButton( { text: 'Next' } );
} );
diff --git a/tests/e2e/specs/amp-onboarding/template-mode.js b/tests/e2e/specs/amp-onboarding/template-mode.js
index bfbcf79a894..8093dd50bc2 100644
--- a/tests/e2e/specs/amp-onboarding/template-mode.js
+++ b/tests/e2e/specs/amp-onboarding/template-mode.js
@@ -4,7 +4,7 @@
/**
* WordPress dependencies
*/
-import { moveToTemplateModeScreen, clickMode, testNextButton, testPreviousButton, cleanUpWizard } from '../../utils/onboarding-wizard-utils';
+import { moveToTemplateModeScreen, clickMode, testNextButton, testPreviousButton, cleanUpSettings } from '../../utils/onboarding-wizard-utils';
import { installTheme } from '../../utils/install-theme';
import { activateTheme } from '../../utils/activate-theme';
import { deleteTheme } from '../../utils/delete-theme';
@@ -44,24 +44,20 @@ describe( 'Template mode recommendations with reader theme active', () => {
await activateTheme( 'twentytwenty' );
} );
- it( 'makes correct recommendations when user is not technical and the current theme is a reader theme', async () => {
- await moveToTemplateModeScreen( { technical: false } );
-
- await expect( '.amp-notice--info' ).countToBe( 1 );
- await expect( '.amp-notice--success' ).countToBe( 2 );
- } );
-
- it( 'makes correct recommendations when user is technical and the current theme is a reader theme', async () => {
- await moveToTemplateModeScreen( { technical: true } );
+ it.each(
+ [ 'technical', 'nontechnical' ],
+ )( 'makes correct recommendations when user is not %s and the current theme is a reader theme', async ( technical ) => {
+ await moveToTemplateModeScreen( { technical: technical === 'technical' } );
- await expect( '.amp-notice--info' ).countToBe( 1 );
- await expect( '.amp-notice--success' ).countToBe( 2 );
+ await expect( page ).toMatchElement( '#template-mode-standard-container .amp-notice--info' );
+ await expect( page ).toMatchElement( '#template-mode-transitional-container .amp-notice--success' );
+ await expect( page ).toMatchElement( '#template-mode-reader-container .amp-notice--success' );
} );
} );
describe( 'Template mode recommendations with non-reader-theme active', () => {
beforeAll( async () => {
- await cleanUpWizard();
+ await cleanUpSettings();
await installTheme( 'astra' );
await activateTheme( 'astra' );
} );
@@ -73,13 +69,8 @@ describe( 'Template mode recommendations with non-reader-theme active', () => {
it( 'makes correct recommendations when user is not technical and the current theme is not a reader theme', async () => {
await moveToTemplateModeScreen( { technical: false } );
- await expect( '.amp-notice--info' ).countToBe( 2 );
- await expect( '.amp-notice--success' ).countToBe( 1 );
- } );
-
- it( 'makes correct recommendations when user is technical and the current theme is not a reader theme', async () => {
- await moveToTemplateModeScreen( { technical: true } );
-
- await expect( '.amp-notice--info' ).countToBe( 3 );
+ await expect( page ).toMatchElement( '#template-mode-standard-container .amp-notice--info' );
+ await expect( page ).toMatchElement( '#template-mode-transitional-container .amp-notice--info' );
+ await expect( page ).toMatchElement( '#template-mode-reader-container .amp-notice--success' );
} );
} );
diff --git a/tests/e2e/specs/amp-onboarding/welcome.js b/tests/e2e/specs/amp-onboarding/welcome.js
index 4fd779a02c8..8bf99d649f3 100644
--- a/tests/e2e/specs/amp-onboarding/welcome.js
+++ b/tests/e2e/specs/amp-onboarding/welcome.js
@@ -10,8 +10,8 @@ import { testPreviousButton, testNextButton } from '../../utils/onboarding-wizar
describe( 'welcome', () => {
beforeEach( async () => {
- await visitAdminPage( 'admin.php', 'page=amp-setup' );
- await page.waitForSelector( '.amp-setup-nav__prev-next' );
+ await visitAdminPage( 'admin.php', 'page=amp-onboarding-wizard' );
+ await page.waitForSelector( '.onboarding-wizard-nav__prev-next' );
} );
it( 'should contain content', async () => {
diff --git a/tests/e2e/utils/delete-theme.js b/tests/e2e/utils/delete-theme.js
index dfde24d7638..ebc1a84e2b1 100644
--- a/tests/e2e/utils/delete-theme.js
+++ b/tests/e2e/utils/delete-theme.js
@@ -8,6 +8,7 @@ import { switchUserToAdmin, switchUserToTest, visitAdminPage } from '@wordpress/
*/
import { installTheme } from './install-theme';
import { activateTheme } from './activate-theme';
+import { themeInstalled } from './theme-installed';
/**
* Deletes a theme from the site, activating another theme if necessary.
@@ -26,6 +27,11 @@ export async function deleteTheme( slug, newThemeSlug, newThemeSearchTerm ) {
await visitAdminPage( 'themes.php' );
}
+ if ( ! await themeInstalled( slug ) ) {
+ await switchUserToTest();
+ return;
+ }
+
await page.click( `[data-slug="${ slug }"]` );
await page.waitForSelector( '.theme-actions .delete-theme' );
await page.click( '.theme-actions .delete-theme' );
diff --git a/tests/e2e/utils/onboarding-wizard-utils.js b/tests/e2e/utils/onboarding-wizard-utils.js
index 083983392d1..8f98886108c 100644
--- a/tests/e2e/utils/onboarding-wizard-utils.js
+++ b/tests/e2e/utils/onboarding-wizard-utils.js
@@ -3,14 +3,14 @@
*/
import { visitAdminPage, isCurrentURL } from '@wordpress/e2e-test-utils';
-export const NEXT_BUTTON_SELECTOR = '.amp-setup-nav__prev-next button.is-primary';
-export const PREV_BUTTON_SELECTOR = '.amp-setup-nav__prev-next button:not(.is-primary)';
+export const NEXT_BUTTON_SELECTOR = '.onboarding-wizard-nav__prev-next button.is-primary';
+export const PREV_BUTTON_SELECTOR = '.onboarding-wizard-nav__prev-next button:not(.is-primary)';
export async function goToOnboardingWizard() {
- if ( ! isCurrentURL( 'admin.php', 'page=amp-setup' ) ) {
- await visitAdminPage( 'admin.php', 'page=amp-setup' );
+ if ( ! isCurrentURL( 'admin.php', 'page=amp-onboarding-wizard' ) ) {
+ await visitAdminPage( 'admin.php', 'page=amp-onboarding-wizard' );
}
- await page.waitForSelector( '#amp-setup' );
+ await page.waitForSelector( '#amp-onboarding-wizard' );
}
export async function clickNextButton() {
@@ -42,8 +42,8 @@ export async function moveToTemplateModeScreen( { technical } ) {
}
export async function clickMode( mode ) {
- await page.$eval( `[for="${ mode }-mode"]`, ( el ) => el.click() );
- await page.waitForSelector( `#${ mode }-mode:checked` );
+ await page.$eval( `[for="template-mode-${ mode }"]`, ( el ) => el.click() );
+ await page.waitForSelector( `#template-mode-${ mode }:checked` );
}
export async function moveToReaderThemesScreen( { technical } ) {
@@ -62,7 +62,7 @@ export async function selectReaderTheme( theme = 'legacy' ) {
export async function moveToSummaryScreen( { technical = true, mode, readerTheme = 'legacy' } ) {
if ( mode === 'reader' ) {
- await moveToReaderThemesScreen( [ technical ] );
+ await moveToReaderThemesScreen( { technical } );
await selectReaderTheme( readerTheme );
} else {
await moveToTemplateModeScreen( { technical } );
@@ -78,14 +78,14 @@ export async function completeWizard( { technical = true, mode, readerTheme = 'l
await moveToSummaryScreen( { technical, mode, readerTheme, mobileRedirect } );
if ( 'standard' !== mode ) {
- await page.waitForSelector( '.redirect-toggle input' );
+ await page.waitForSelector( '.amp-setting-toggle input' );
- const selector = '.redirect-toggle input:checked';
+ const selector = '.amp-setting-toggle input:checked';
const checkedMobileRedirect = await page.$( selector );
if ( checkedMobileRedirect && false === mobileRedirect ) {
await expect( page ).toClick( selector );
- await page.waitForSelector( '.redirect-toggle input:not(:checked)' );
+ await page.waitForSelector( '.amp-setting-toggle input:not(:checked)' );
} else if ( ! checkedMobileRedirect && true === mobileRedirect ) {
await expect( page ).toClick( selector );
await page.waitForSelector( selector );
@@ -121,9 +121,10 @@ export function testTitle( { text, element = 'h1' } ) {
}
/**
- * Reset data modified by the setup wizard.
+ * Reset plugin configuration.
*/
-export async function cleanUpWizard() {
+export async function cleanUpSettings() {
+ await visitAdminPage( 'admin.php', 'page=amp-options' );
await page.evaluate( async () => {
await Promise.all( [
wp.apiFetch( { path: '/wp/v2/users/me', method: 'POST', data: { amp_dev_tools_enabled: true } } ),
@@ -131,7 +132,7 @@ export async function cleanUpWizard() {
mobile_redirect: false,
reader_theme: 'legacy',
theme_support: 'reader',
- wizard_completed: false,
+ plugin_configured: false,
} } ),
],
);
diff --git a/tests/e2e/utils/theme-installed.js b/tests/e2e/utils/theme-installed.js
new file mode 100644
index 00000000000..07e10e91194
--- /dev/null
+++ b/tests/e2e/utils/theme-installed.js
@@ -0,0 +1,20 @@
+/**
+ * WordPress dependencies
+ */
+import { switchUserToAdmin } from '@wordpress/e2e-test-utils/build/switch-user-to-admin';
+import { visitAdminPage } from '@wordpress/e2e-test-utils/build/visit-admin-page';
+import { switchUserToTest } from '@wordpress/e2e-test-utils/build/switch-user-to-test';
+
+/**
+ * Checks whether a theme exists on the site.
+ *
+ * @param {string} slug Theme slug to check.
+ * @return {boolean} Whether the theme exists.
+ */
+export async function themeInstalled( slug ) {
+ await switchUserToAdmin();
+ await visitAdminPage( 'themes.php' );
+ const installed = await page.$( `[data-slug="${ slug }"]` ) !== null;
+ await switchUserToTest();
+ return installed;
+}
diff --git a/tests/php/src/Unit/GoogleFontsTest.php b/tests/php/src/Unit/GoogleFontsTest.php
new file mode 100644
index 00000000000..9a9f442d050
--- /dev/null
+++ b/tests/php/src/Unit/GoogleFontsTest.php
@@ -0,0 +1,59 @@
+instance = new GoogleFonts();
+ }
+
+ /** @covers GoogleFonts::__construct() */
+ public function test__construct() {
+ $this->assertInstanceOf( GoogleFonts::class, $this->instance );
+ $this->assertInstanceOf( Delayed::class, $this->instance );
+ $this->assertInstanceOf( Service::class, $this->instance );
+ $this->assertInstanceOf( Registerable::class, $this->instance );
+ }
+
+ /**
+ * Tests OnboardingWizardSubmenu::register
+ *
+ * @covers GoogleFonts::get_handle
+ * @covers GoogleFonts::register
+ */
+ public function test_register_style() {
+ $this->instance->register_style( wp_styles() );
+
+ $this->assertTrue( wp_style_is( 'amp-admin-google-fonts', 'registered' ) );
+ }
+}
diff --git a/tests/php/src/Unit/MobileRedirectionTest.php b/tests/php/src/Unit/MobileRedirectionTest.php
index 5bd3a4226b5..2bcec1a1876 100644
--- a/tests/php/src/Unit/MobileRedirectionTest.php
+++ b/tests/php/src/Unit/MobileRedirectionTest.php
@@ -43,7 +43,6 @@ public function test__construct() {
public function test_register() {
$this->instance->register();
$this->assertEquals( 10, has_filter( 'amp_default_options', [ $this->instance, 'filter_default_options' ] ) );
- $this->assertEquals( 10, has_action( 'amp_options_menu_items', [ $this->instance, 'add_settings_field' ] ) );
$this->assertEquals( 10, has_filter( 'amp_options_updating', [ $this->instance, 'sanitize_options' ] ) );
}
@@ -63,8 +62,7 @@ public function test_filter_default_options() {
public function test_sanitize_options() {
$this->assertEquals(
[
- 'foo' => 'bar',
- Option::MOBILE_REDIRECT => false,
+ 'foo' => 'bar',
],
$this->instance->sanitize_options(
[ 'foo' => 'bar' ],
@@ -105,31 +103,6 @@ public function test_sanitize_options() {
);
}
- /** @covers MobileRedirection::add_settings_field() */
- public function test_add_settings_field() {
- global $wp_settings_fields;
-
- $this->instance->add_settings_field();
- $this->assertTrue( isset( $wp_settings_fields[ AMP_Options_Manager::OPTION_NAME ]['general'][ Option::MOBILE_REDIRECT ] ) );
- }
-
- /** @covers MobileRedirection::render_setting_field() */
- public function test_render_setting_field() {
- AMP_Options_Manager::update_option( Option::MOBILE_REDIRECT, true );
- ob_start();
- $this->instance->render_setting_field();
- $html = ob_get_clean();
- $this->assertStringContains( 'type="checkbox"', $html );
- $this->assertStringContains( 'checked=', $html );
-
- AMP_Options_Manager::update_option( Option::MOBILE_REDIRECT, false );
- ob_start();
- $this->instance->render_setting_field();
- $html = ob_get_clean();
- $this->assertStringContains( 'type="checkbox"', $html );
- $this->assertStringNotContains( 'checked=', $html );
- }
-
/** @covers MobileRedirection::get_current_amp_url() */
public function test_get_current_amp_url() {
$this->go_to( add_query_arg( QueryVars::NOAMP, QueryVars::NOAMP_MOBILE, '/foo/' ) );
diff --git a/tests/php/src/Unit/OnboardingWizardSubmenuPageTest.php b/tests/php/src/Unit/OnboardingWizardSubmenuPageTest.php
new file mode 100644
index 00000000000..d80d6fb6396
--- /dev/null
+++ b/tests/php/src/Unit/OnboardingWizardSubmenuPageTest.php
@@ -0,0 +1,101 @@
+page = new OnboardingWizardSubmenuPage( new GoogleFonts(), new ReaderThemes() );
+ }
+
+ /** @covers OnboardingWizardSubmenu::__construct() */
+ public function test__construct() {
+ $this->assertInstanceOf( OnboardingWizardSubmenuPage::class, $this->page );
+ $this->assertInstanceOf( Delayed::class, $this->page );
+ $this->assertInstanceOf( Service::class, $this->page );
+ $this->assertInstanceOf( Registerable::class, $this->page );
+ }
+
+ /**
+ * Tests OnboardingWizardSubmenuPage::register
+ *
+ * @covers OnboardingWizardSubmenuPage::register
+ */
+ public function test_register() {
+ $this->page->register();
+
+ $this->assertEquals( 10, has_action( 'admin_head-amp_page_amp-onboarding-wizard', [ $this->page, 'override_template' ] ) );
+ $this->assertEquals( 10, has_action( 'admin_enqueue_scripts', [ $this->page, 'enqueue_assets' ] ) );
+ }
+
+ /**
+ * Tests OnboardingWizardSubmenuPage::render
+ *
+ * @covers OnboardingWizardSubmenuPage::render
+ */
+ public function test_render() {
+ ob_start();
+
+ $this->page->render();
+
+ $this->assertStringContains( '
', ob_get_clean() );
+ }
+
+ /**
+ * Tests OnboardingWizardSubmenuPage::screen_handle
+ *
+ * @covers OnboardingWizardSubmenuPage::screen_handle
+ */
+ public function test_screen_handle() {
+ $this->assertEquals( $this->page->screen_handle(), 'amp_page_amp-onboarding-wizard' );
+ }
+
+ /**
+ * Tests OnboardingWizardSubmenuPage::enqueue_assets
+ *
+ * @covers OnboardingWizardSubmenuPage::enqueue_assets
+ */
+ public function test_enqueue_assets() {
+ $handle = 'amp-onboarding-wizard';
+
+ $this->page->enqueue_assets( $this->page->screen_handle() );
+ $this->assertTrue( wp_script_is( $handle ) );
+ $this->assertTrue( wp_style_is( $handle ) );
+ }
+}
diff --git a/tests/php/src/Unit/OnboardingWizardSubmenuTest.php b/tests/php/src/Unit/OnboardingWizardSubmenuTest.php
new file mode 100644
index 00000000000..0785489a301
--- /dev/null
+++ b/tests/php/src/Unit/OnboardingWizardSubmenuTest.php
@@ -0,0 +1,64 @@
+instance = new OnboardingWizardSubmenu();
+ }
+
+ /** @covers OnboardingWizardSubmenu::__construct() */
+ public function test__construct() {
+ $this->assertInstanceOf( OnboardingWizardSubmenu::class, $this->instance );
+ $this->assertInstanceOf( Delayed::class, $this->instance );
+ $this->assertInstanceOf( Service::class, $this->instance );
+ $this->assertInstanceOf( Registerable::class, $this->instance );
+ }
+
+ /**
+ * Tests OnboardingWizardSubmenu::register
+ *
+ * @covers OnboardingWizardSubmenu::register
+ */
+ public function test_register() {
+ global $submenu;
+
+ wp_set_current_user( 1 );
+
+ $this->instance->register();
+
+ $this->assertEquals( end( $submenu['amp-options'] )[2], 'amp-onboarding-wizard' );
+ }
+}
diff --git a/tests/php/test-class-amp-options-menu.php b/tests/php/src/Unit/OptionsMenuTest.php
similarity index 58%
rename from tests/php/test-class-amp-options-menu.php
rename to tests/php/src/Unit/OptionsMenuTest.php
index c16f4b5773e..b3eb071f19e 100644
--- a/tests/php/test-class-amp-options-menu.php
+++ b/tests/php/src/Unit/OptionsMenuTest.php
@@ -1,24 +1,28 @@
instance = new AMP_Options_Menu();
+ $this->instance = new OptionsMenu( new GoogleFonts(), new ReaderThemes() );
}
/**
* Test constants.
*
- * @see AMP_Options_Menu::ICON_BASE64_SVG
+ * @see OptionsMenu::ICON_BASE64_SVG
*/
public function test_constants() {
- $this->assertStringStartsWith( 'data:image/svg+xml;base64,', AMP_Options_Menu::ICON_BASE64_SVG );
+ $this->assertStringStartsWith( 'data:image/svg+xml;base64,', OptionsMenu::ICON_BASE64_SVG );
}
/**
- * Test init.
+ * Test add_hooks.
*
- * @see AMP_Options_Menu::init()
+ * @see OptionsMenu::add_hooks()
*/
- public function test_init() {
- $this->instance->init();
+ public function test_register() {
+ $this->instance->register();
$this->assertEquals( 9, has_action( 'admin_menu', [ $this->instance, 'add_menu_items' ] ) );
$this->assertEquals( 10, has_action( 'admin_post_amp_analytics_options', 'AMP_Options_Manager::handle_analytics_submit' ) );
+
+ $this->assertEquals( 10, has_filter( 'plugin_action_links_amp/amp.php', [ $this->instance, 'add_plugin_action_links' ] ) );
+
+ $this->assertEquals( 10, has_action( 'admin_enqueue_scripts', [ $this->instance, 'enqueue_assets' ] ) );
}
/**
* Test admin_menu.
*
- * @covers AMP_Options_Menu::add_menu_items()
+ * @covers OptionsMenu::add_menu_items()
*/
public function test_add_menu_items() {
- global $_parent_pages, $submenu, $wp_settings_sections, $wp_settings_fields;
+ global $_parent_pages, $submenu, $wp_settings_fields;
wp_set_current_user(
self::factory()->user->create(
@@ -75,25 +83,20 @@ public function test_add_menu_items() {
$this->assertEquals( 'amp-options', $_parent_pages['amp-analytics-options'] );
$this->assertArrayHasKey( 'amp-options', $submenu );
- $this->assertCount( amp_should_use_new_onboarding() ? 3 : 2, $submenu['amp-options'] );
- $this->assertEquals( 'amp-options', $submenu['amp-options'][0][2] );
- $this->assertEquals( 'amp-analytics-options', $submenu['amp-options'][1][2] );
-
- // Test add_setting_section().
- $this->assertArrayHasKey( 'amp-options', $wp_settings_sections );
- $this->assertArrayHasKey( 'general', $wp_settings_sections['amp-options'] );
+ $this->assertCount( 4, $submenu['amp-options'] );
+ $this->assertEquals( 'edit-tags.php?taxonomy=amp_validation_error&post_type=amp_validated_url', $submenu['amp-options'][0][2] );
+ $this->assertEquals( 'amp-onboarding-wizard', $submenu['amp-options'][1][2] );
// Test add_setting_field().
$this->assertArrayHasKey( 'amp-options', $wp_settings_fields );
$this->assertArrayHasKey( 'general', $wp_settings_fields['amp-options'] );
- $this->assertArrayHasKey( Option::SUPPORTED_TEMPLATES, $wp_settings_fields['amp-options']['general'] );
$this->assertArrayNotHasKey( 'stories_settings', $wp_settings_fields['amp-options']['general'] );
}
/**
* Test render_screen for admin users.
*
- * @covers AMP_Options_Menu::render_screen()
+ * @covers OptionsMenu::render_screen()
*/
public function test_render_screen_for_admin_user() {
wp_set_current_user(
diff --git a/tests/php/test-class-plugin-activation-notice.php b/tests/php/src/Unit/PluginActivationNoticeTest.php
similarity index 88%
rename from tests/php/test-class-plugin-activation-notice.php
rename to tests/php/src/Unit/PluginActivationNoticeTest.php
index 4b4a40e9dd6..6696ca6221a 100644
--- a/tests/php/test-class-plugin-activation-notice.php
+++ b/tests/php/src/Unit/PluginActivationNoticeTest.php
@@ -17,7 +17,7 @@
*
* @covers PluginActivationNotice
*/
-class Test_PluginActivationNotice extends WP_UnitTestCase {
+class PluginActivationNoticeTest extends WP_UnitTestCase {
/**
* Test instance.
@@ -75,9 +75,9 @@ public function test_user_can_dismiss_notice() {
* @covers PluginActivationNotice::render_notice
*/
public function test_notice_doesnt_show_if_wizard_completed() {
- $original_option = AMP_Options_Manager::get_option( Option::WIZARD_COMPLETED );
+ $original_option = AMP_Options_Manager::get_option( Option::PLUGIN_CONFIGURED );
- AMP_Options_Manager::update_option( Option::WIZARD_COMPLETED, true );
+ AMP_Options_Manager::update_option( Option::PLUGIN_CONFIGURED, true );
set_current_screen( 'plugins' );
$this->assertEmpty( get_echo( [ $this->plugin_activation_notice, 'render_notice' ] ) );
@@ -85,7 +85,7 @@ public function test_notice_doesnt_show_if_wizard_completed() {
set_current_screen( 'toplevel_page_' . AMP_Options_Manager::OPTION_NAME );
$this->assertEmpty( get_echo( [ $this->plugin_activation_notice, 'render_notice' ] ) );
- AMP_Options_Manager::update_option( Option::WIZARD_COMPLETED, $original_option );
+ AMP_Options_Manager::update_option( Option::PLUGIN_CONFIGURED, $original_option );
$GLOBALS['current_screen'] = null;
}
diff --git a/tests/php/src/Unit/PluginSuppressionTest.php b/tests/php/src/Unit/PluginSuppressionTest.php
index 4e34520be72..d3537c42756 100644
--- a/tests/php/src/Unit/PluginSuppressionTest.php
+++ b/tests/php/src/Unit/PluginSuppressionTest.php
@@ -13,10 +13,10 @@
use AmpProject\AmpWP\Tests\PrivateAccess;
use AmpProject\AmpWP\Tests\ThemesApiRequestMocking;
use AMP_Options_Manager;
-use AMP_Reader_Themes;
use AMP_Theme_Support;
use AMP_Validated_URL_Post_Type;
use AMP_Validation_Manager;
+use AmpProject\AmpWP\Admin\ReaderThemes;
use AmpProject\AmpWP\Tests\WithoutBlockPreRendering;
use Exception;
use WP_Block_Type_Registry;
@@ -220,7 +220,7 @@ public function test_is_reader_theme_request() {
$this->assertFalse( $instance->is_reader_theme_request() );
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG );
- AMP_Options_Manager::update_option( Option::READER_THEME, AMP_Reader_Themes::DEFAULT_READER_THEME );
+ AMP_Options_Manager::update_option( Option::READER_THEME, ReaderThemes::DEFAULT_READER_THEME );
$this->assertFalse( $instance->is_reader_theme_request() );
$_GET[ amp_get_slug() ] = 1;
$this->assertFalse( $instance->is_reader_theme_request() );
@@ -486,7 +486,7 @@ public function test_add_settings_field_with_suppressible_plugins() {
$this->assertEqualSets( $bad_plugin_file_slugs, $this->call_private_method( $instance, 'get_suppressible_plugins' ) );
$wp_settings_fields = [];
$instance->add_settings_field();
- $this->assertTrue( isset( $wp_settings_fields[ AMP_Options_Manager::OPTION_NAME ]['general'][ Option::SUPPRESSED_PLUGINS ] ) );
+ $this->assertTrue( isset( $wp_settings_fields[ AMP_Options_Manager::OPTION_NAME ]['validation'][ Option::SUPPRESSED_PLUGINS ] ) );
}
/**
diff --git a/tests/php/src/Unit/ReaderThemeLoaderTest.php b/tests/php/src/Unit/ReaderThemeLoaderTest.php
index e4df0dcefc3..e5008830529 100644
--- a/tests/php/src/Unit/ReaderThemeLoaderTest.php
+++ b/tests/php/src/Unit/ReaderThemeLoaderTest.php
@@ -3,8 +3,8 @@
namespace AmpProject\AmpWP\Tests\Unit;
use AMP_Options_Manager;
-use AMP_Reader_Themes;
use AMP_Theme_Support;
+use AmpProject\AmpWP\Admin\ReaderThemes;
use AmpProject\AmpWP\Infrastructure\Conditional;
use AmpProject\AmpWP\Infrastructure\Registerable;
use AmpProject\AmpWP\Infrastructure\Service;
@@ -49,7 +49,7 @@ public function test_is_needed() {
$this->assertFalse( ReaderThemeLoader::is_needed() );
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG );
- AMP_Options_Manager::update_option( Option::READER_THEME, AMP_Reader_Themes::DEFAULT_READER_THEME );
+ AMP_Options_Manager::update_option( Option::READER_THEME, ReaderThemes::DEFAULT_READER_THEME );
$this->assertFalse( ReaderThemeLoader::is_needed() );
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG );
diff --git a/tests/php/test-class-amp-reader-themes.php b/tests/php/src/Unit/ReaderThemesTest.php
similarity index 77%
rename from tests/php/test-class-amp-reader-themes.php
rename to tests/php/src/Unit/ReaderThemesTest.php
index 8449d6ee50e..a559db941a3 100644
--- a/tests/php/test-class-amp-reader-themes.php
+++ b/tests/php/src/Unit/ReaderThemesTest.php
@@ -1,11 +1,12 @@
add_reader_themes_request_filter();
switch_theme( 'twentytwenty' );
- $this->reader_themes = new AMP_Reader_Themes();
+ $this->reader_themes = new ReaderThemes();
}
/**
* Test for get_themes.
*
- * @covers AMP_Reader_Themes::get_themes
- * @covers AMP_Reader_Themes::get_default_reader_themes
- * @covers AMP_Reader_Themes::get_classic_mode
- * @covers AMP_Reader_Themes::get_default_raw_reader_themes
+ * @covers ReaderThemes::get_themes
+ * @covers ReaderThemes::get_default_reader_themes
+ * @covers ReaderThemes::get_classic_mode
+ * @covers ReaderThemes::get_default_raw_reader_themes
*/
public function test_get_themes() {
$themes = $this->reader_themes->get_themes();
@@ -76,7 +77,7 @@ public function test_get_themes() {
/**
* Test for get_reader_theme_by_slug.
*
- * @covers AMP_Reader_Themes::get_reader_theme_by_slug
+ * @covers ReaderThemes::get_reader_theme_by_slug
*/
public function test_get_reader_theme_by_slug() {
$this->assertFalse( $this->reader_themes->get_reader_theme_by_slug( 'some-theme' ) );
@@ -95,7 +96,7 @@ public function get_availability_test_themes() {
return [
'twentysixteen_from_wp_future' => [
- $is_installed( 'twentysixteen' ) ? AMP_Reader_Themes::STATUS_INSTALLED : AMP_Reader_Themes::STATUS_NON_INSTALLABLE,
+ $is_installed( 'twentysixteen' ) ? ReaderThemes::STATUS_INSTALLED : ReaderThemes::STATUS_NON_INSTALLABLE,
false,
[
'name' => 'Some Theme',
@@ -105,7 +106,7 @@ public function get_availability_test_themes() {
],
],
'twentysixteen_from_php_future' => [
- $is_installed( 'twentysixteen' ) ? AMP_Reader_Themes::STATUS_INSTALLED : AMP_Reader_Themes::STATUS_NON_INSTALLABLE,
+ $is_installed( 'twentysixteen' ) ? ReaderThemes::STATUS_INSTALLED : ReaderThemes::STATUS_NON_INSTALLABLE,
false,
[
'name' => 'Some Theme',
@@ -115,7 +116,7 @@ public function get_availability_test_themes() {
],
],
'non_reader_theme' => [
- AMP_Reader_Themes::STATUS_NON_INSTALLABLE,
+ ReaderThemes::STATUS_NON_INSTALLABLE,
false,
[
'name' => 'Some Theme',
@@ -125,7 +126,7 @@ public function get_availability_test_themes() {
],
],
'twentytwelve_not_requiring_wp_version' => [
- $is_installed( 'twentytwelve' ) ? AMP_Reader_Themes::STATUS_INSTALLED : AMP_Reader_Themes::STATUS_INSTALLABLE,
+ $is_installed( 'twentytwelve' ) ? ReaderThemes::STATUS_INSTALLED : ReaderThemes::STATUS_INSTALLABLE,
true,
[
'name' => 'Some Theme',
@@ -135,7 +136,7 @@ public function get_availability_test_themes() {
],
],
'twentytwelve_not_requiring_php_version' => [
- $is_installed( 'twentysixteen' ) ? AMP_Reader_Themes::STATUS_INSTALLED : AMP_Reader_Themes::STATUS_INSTALLABLE,
+ $is_installed( 'twentysixteen' ) ? ReaderThemes::STATUS_INSTALLED : ReaderThemes::STATUS_INSTALLABLE,
true,
[
'name' => 'Some Theme',
@@ -145,7 +146,7 @@ public function get_availability_test_themes() {
],
],
'twentytwenty_active' => [
- AMP_Reader_Themes::STATUS_ACTIVE,
+ ReaderThemes::STATUS_ACTIVE,
true,
[
'name' => 'WordPress Default',
@@ -160,8 +161,8 @@ public function get_availability_test_themes() {
/**
* Test for get_theme_availability.
*
- * @covers AMP_Reader_Themes::get_theme_availability
- * @covers AMP_Reader_Themes::can_install_theme
+ * @covers ReaderThemes::get_theme_availability
+ * @covers ReaderThemes::can_install_theme
*
* @dataProvider get_availability_test_themes
*
@@ -178,7 +179,7 @@ public function test_get_theme_availability( $expected, $can_install, $theme ) {
/**
* Tests for can_install_theme.
*
- * @covers AMP_Reader_Themes::can_install_theme
+ * @covers ReaderThemes::can_install_theme
*/
public function test_can_install_theme() {
$installable_theme = [
diff --git a/tests/php/test-class-amp-options-manager.php b/tests/php/test-class-amp-options-manager.php
index 9665fe727d7..afe84db0bfc 100644
--- a/tests/php/test-class-amp-options-manager.php
+++ b/tests/php/test-class-amp-options-manager.php
@@ -58,7 +58,6 @@ public function test_constants() {
*/
public function test_init() {
AMP_Options_Manager::init();
- $this->assertEquals( 10, has_action( 'admin_notices', [ AMP_Options_Manager::class, 'render_welcome_notice' ] ) );
$this->assertEquals( 10, has_action( 'admin_notices', [ AMP_Options_Manager::class, 'render_php_css_parser_conflict_notice' ] ) );
$this->assertEquals( 10, has_action( 'admin_notices', [ AMP_Options_Manager::class, 'insecure_connection_notice' ] ) );
}
@@ -145,7 +144,8 @@ public function test_get_and_set_options() {
Option::VERSION => AMP__VERSION,
Option::MOBILE_REDIRECT => false,
Option::READER_THEME => 'legacy',
- Option::WIZARD_COMPLETED => false,
+ Option::MOBILE_REDIRECT => false,
+ Option::PLUGIN_CONFIGURED => false,
],
AMP_Options_Manager::get_options()
);
@@ -472,33 +472,6 @@ public function test_check_supported_post_type_update_errors() {
$wp_settings_errors = [];
}
- /**
- * Test for render_welcome_notice()
- *
- * @covers AMP_Options_Manager::render_welcome_notice()
- */
- public function test_render_welcome_notice() {
- // If this is not the main 'AMP Settings' page, this should not render the notice.
- wp_set_current_user( self::factory()->user->create() );
- set_current_screen( 'edit.php' );
- $output = get_echo( [ 'AMP_Options_Manager', 'render_welcome_notice' ] );
- $this->assertEmpty( $output );
-
- // This is the correct page, but the notice was dismissed, so it should not display.
- $GLOBALS['current_screen']->id = 'toplevel_page_' . AMP_Options_Manager::OPTION_NAME;
- $id = 'amp-welcome-notice-1';
- update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $id );
- $output = get_echo( [ 'AMP_Options_Manager', 'render_welcome_notice' ] );
- $this->assertEmpty( $output );
-
- // This is the correct page, and the notice has not been dismissed, so it should display.
- delete_user_meta( get_current_user_id(), 'dismissed_wp_pointers' );
- $output = get_echo( [ 'AMP_Options_Manager', 'render_welcome_notice' ] );
- $this->assertStringContains( 'Welcome to AMP for WordPress', $output );
- $this->assertStringContains( 'Bring the speed and features of the open source AMP project to your site, complete with the tools to support content authoring and website development.', $output );
- $this->assertStringContains( $id, $output );
- }
-
/**
* Test handle_updated_theme_support_option for reader mode.
*
diff --git a/tests/php/test-class-amp-options-rest-controller.php b/tests/php/test-class-amp-options-rest-controller.php
index 5132a236b3e..62f23973591 100644
--- a/tests/php/test-class-amp-options-rest-controller.php
+++ b/tests/php/test-class-amp-options-rest-controller.php
@@ -5,6 +5,7 @@
* @package AMP
*/
+use AmpProject\AmpWP\Admin\ReaderThemes;
use AmpProject\AmpWP\Tests\ThemesApiRequestMocking;
/**
@@ -38,7 +39,7 @@ public function setUp() {
$this->add_reader_themes_request_filter();
do_action( 'rest_api_init' );
- $this->controller = new AMP_Options_REST_Controller( new AMP_Reader_Themes() );
+ $this->controller = new AMP_Options_REST_Controller( new ReaderThemes() );
}
/**
@@ -78,7 +79,8 @@ public function test_get_items() {
'theme_support',
'reader_theme',
'mobile_redirect',
- 'wizard_completed',
+ 'plugin_configured',
+ 'all_templates_supported',
'preview_permalink',
]
);
diff --git a/tests/php/test-class-amp-reader-themes-rest-controller.php b/tests/php/test-class-amp-reader-themes-rest-controller.php
index d8d8d20b3cd..da81bd8065c 100644
--- a/tests/php/test-class-amp-reader-themes-rest-controller.php
+++ b/tests/php/test-class-amp-reader-themes-rest-controller.php
@@ -6,6 +6,8 @@
* @since 1.6
*/
+use AmpProject\AmpWP\Admin\ReaderThemes;
+
/**
* Tests for AMP_Reader_Theme_REST_Controller.
*
@@ -34,7 +36,7 @@ public function setUp() {
}
do_action( 'rest_api_init' );
- $this->controller = new AMP_Reader_Theme_REST_Controller( new AMP_Reader_Themes() );
+ $this->controller = new AMP_Reader_Theme_REST_Controller( new ReaderThemes() );
}
/**
@@ -68,7 +70,7 @@ public function test_get_items() {
};
// Test that a theme with no screenshot_url is filtered out.
- $this->controller = new AMP_Reader_Theme_REST_Controller( new AMP_Reader_Themes() );
+ $this->controller = new AMP_Reader_Theme_REST_Controller( new ReaderThemes() );
add_filter( 'amp_reader_themes', $filter );
$this->assertEquals( 0, count( $this->controller->get_items( new WP_REST_Request( 'GET', 'amp/v1' ) )->data ) );
remove_filter( 'amp_reader_themes', $filter );
diff --git a/tests/php/test-class-amp-setup-wizard-submenu-page.php b/tests/php/test-class-amp-setup-wizard-submenu-page.php
deleted file mode 100644
index fe921d18461..00000000000
--- a/tests/php/test-class-amp-setup-wizard-submenu-page.php
+++ /dev/null
@@ -1,86 +0,0 @@
-page = new AMP_Setup_Wizard_Submenu_Page();
- }
-
- /**
- * Tests AMP_Setup_Wizard_Submenu_Page::init
- *
- * @covers AMP_Setup_Wizard_Submenu_Page::init
- */
- public function test_init() {
- $this->page->init();
-
- $this->assertEquals( 10, has_action( 'admin_head-amp_page_amp-setup', [ $this->page, 'override_template' ] ) );
- $this->assertEquals( 10, has_action( 'admin_enqueue_scripts', [ $this->page, 'enqueue_assets' ] ) );
- }
-
- /**
- * Tests AMP_Setup_Wizard_Submenu_Page::render
- *
- * @covers AMP_Setup_Wizard_Submenu_Page::render
- */
- public function test_render() {
- ob_start();
-
- $this->page->render();
-
- $this->assertStringContains( '
', ob_get_clean() );
- }
-
- /**
- * Tests AMP_Setup_Wizard_Submenu_Page::screen_handle
- *
- * @covers AMP_Setup_Wizard_Submenu_Page::screen_handle
- */
- public function test_screen_handle() {
- $this->assertEquals( $this->page->screen_handle(), 'amp_page_amp-setup' );
- }
-
- /**
- * Tests AMP_Setup_Wizard_Submenu_Page::enqueue_assets
- *
- * @covers AMP_Setup_Wizard_Submenu_Page::enqueue_assets
- */
- public function test_enqueue_assets() {
- $handle = 'amp-setup';
-
- $this->page->enqueue_assets( $this->page->screen_handle() );
- $this->assertTrue( wp_script_is( $handle ) );
- }
-}
diff --git a/tests/php/test-class-amp-setup-wizard-submenu.php b/tests/php/test-class-amp-setup-wizard-submenu.php
deleted file mode 100644
index 095eebc1ead..00000000000
--- a/tests/php/test-class-amp-setup-wizard-submenu.php
+++ /dev/null
@@ -1,51 +0,0 @@
-wizard = new AMP_Setup_Wizard_Submenu( 'amp-options' );
- }
-
- /**
- * Tests AMP_Setup_Wizard_Submenu::init
- *
- * @covers AMP_Setup_Wizard_Submenu::init
- */
- public function test_init() {
- global $submenu;
-
- wp_set_current_user( 1 );
-
- $this->wizard->init();
-
- $this->assertEquals( end( $submenu['amp-options'] )[2], 'amp-setup' );
- }
-}
diff --git a/tests/php/test-class-amp-theme-support.php b/tests/php/test-class-amp-theme-support.php
index c1cd1e937f3..ff938805aad 100644
--- a/tests/php/test-class-amp-theme-support.php
+++ b/tests/php/test-class-amp-theme-support.php
@@ -6,6 +6,7 @@
* @since 0.7
*/
+use AmpProject\AmpWP\Admin\ReaderThemes;
use AmpProject\AmpWP\ConfigurationArgument;
use AmpProject\AmpWP\MobileRedirection;
use AmpProject\AmpWP\Option;
@@ -207,7 +208,7 @@ public function test_finish_init() {
// Test legacy Reader mode.
add_theme_support( 'amp' );
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG );
- AMP_Options_Manager::update_option( Option::READER_THEME, AMP_Reader_Themes::DEFAULT_READER_THEME );
+ AMP_Options_Manager::update_option( Option::READER_THEME, ReaderThemes::DEFAULT_READER_THEME );
$this->go_to( amp_get_permalink( $post_id ) );
AMP_Theme_Support::finish_init();
$this->assertFalse( current_theme_supports( 'amp' ) );
@@ -2345,6 +2346,23 @@ public function test_amend_header_image_with_video_header() {
AMP_Theme_Support::amend_header_image_with_video_header( $mock_image )
);
}
+
+ /**
+ * Tests for the get_theme_support_args method.
+ *
+ * @covers AMP_Theme_Support::get_theme_support_args
+ */
+ public function test_get_theme_support_args() {
+ remove_theme_support( 'amp' );
+
+ $this->assertFalse( AMP_Theme_Support::get_theme_support_args() );
+
+ add_theme_support( 'amp' );
+ $this->assertEquals( [ 'paired' => false ], AMP_Theme_Support::get_theme_support_args() );
+
+ add_theme_support( 'amp', [ 'paired' => true ] );
+ $this->assertEquals( [ 'paired' => true ], AMP_Theme_Support::get_theme_support_args() );
+ }
}
// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
diff --git a/tests/php/test-includes-admin-functions.php b/tests/php/test-includes-admin-functions.php
index 615d02ca1c3..65be158c369 100644
--- a/tests/php/test-includes-admin-functions.php
+++ b/tests/php/test-includes-admin-functions.php
@@ -5,6 +5,7 @@
* @package AMP
*/
+use AmpProject\AmpWP\Admin\ReaderThemes;
use AmpProject\AmpWP\Option;
/**
@@ -30,7 +31,7 @@ public function tearDown() {
/** @covers ::amp_init_customizer() */
public function test_amp_init_customizer_legacy_reader() {
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG );
- AMP_Options_Manager::update_option( Option::READER_THEME, AMP_Reader_Themes::DEFAULT_READER_THEME );
+ AMP_Options_Manager::update_option( Option::READER_THEME, ReaderThemes::DEFAULT_READER_THEME );
amp_init_customizer();
$this->assertTrue( amp_is_legacy() );
$this->assertEquals( 500, has_action( 'customize_register', [ 'AMP_Template_Customizer', 'init' ] ) );
diff --git a/webpack.config.js b/webpack.config.js
index 392062af098..c3679d3164b 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -225,12 +225,12 @@ const wpPolyfills = {
const setup = {
...sharedConfig,
entry: {
- 'amp-setup': [
- './assets/src/setup',
+ 'amp-onboarding-wizard': [
+ './assets/src/onboarding-wizard',
],
},
externals: {
- 'amp-setup': 'ampSetup',
+ 'amp-settings': 'ampSettings',
},
plugins: [
...sharedConfig.plugins.filter(
@@ -244,6 +244,7 @@ const setup = {
case '@wordpress/api-fetch':
case '@wordpress/dom-ready':
case '@wordpress/html-entities':
+ case '@wordpress/url':
return defaultRequestToHandle( handle );
default:
@@ -255,6 +256,7 @@ const setup = {
case '@wordpress/api-fetch':
case '@wordpress/dom-ready':
case '@wordpress/html-entities':
+ case '@wordpress/url':
return defaultRequestToExternal( external );
default:
@@ -263,12 +265,59 @@ const setup = {
},
} ),
new WebpackBar( {
- name: 'Setup',
+ name: 'Onboarding wizard',
color: '#1773a8',
} ),
],
};
+const settingsPage = {
+ ...sharedConfig,
+ entry: {
+ 'amp-settings': [
+ './assets/src/settings-page',
+ ],
+ },
+ externals: {
+ 'amp-settings': 'ampSettings',
+ },
+ plugins: [
+ ...sharedConfig.plugins.filter(
+ ( plugin ) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin',
+ ),
+ new DependencyExtractionWebpackPlugin( {
+ useDefaults: false,
+ // Most dependencies will be bundled for the AMP setup screen for compatibility across WP versions.
+ requestToHandle: ( handle ) => {
+ switch ( handle ) {
+ case '@wordpress/api-fetch':
+ case '@wordpress/dom-ready':
+ case '@wordpress/html-entities':
+ return defaultRequestToHandle( handle );
+
+ default:
+ return undefined;
+ }
+ },
+ requestToExternal: ( external ) => {
+ switch ( external ) {
+ case '@wordpress/api-fetch':
+ case '@wordpress/dom-ready':
+ case '@wordpress/html-entities':
+ return defaultRequestToExternal( external );
+
+ default:
+ return undefined;
+ }
+ },
+ } ),
+ new WebpackBar( {
+ name: 'Settings page',
+ color: '#67b255',
+ } ),
+ ],
+};
+
const mobileRedirection = {
...sharedConfig,
entry: {
@@ -291,5 +340,6 @@ module.exports = [
customizer,
wpPolyfills,
setup,
+ settingsPage,
mobileRedirection,
];