@wordpress/e2e-tests 10.0.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/package.json +4 -4
  3. package/plugins/content-security-policy.php +43 -0
  4. package/plugins/entity-actions-api.php +1 -1
  5. package/plugins/footnotes-locked-template.php +47 -0
  6. package/plugins/image-picture-wrapper.php +30 -0
  7. package/plugins/interactive-blocks/directive-context/render.php +2 -2
  8. package/plugins/interactive-blocks/directive-html/render.php +66 -1
  9. package/plugins/interactive-blocks/directive-html/view.js +99 -0
  10. package/plugins/interactive-blocks/router-html/block.json +3 -1
  11. package/plugins/interactive-blocks/router-html/render.php +16 -0
  12. package/plugins/interactive-blocks/router-html/view.js +25 -3
  13. package/plugins/interactive-blocks/router-html-regions/block.json +17 -0
  14. package/plugins/interactive-blocks/router-html-regions/render.php +77 -0
  15. package/plugins/interactive-blocks/router-html-regions/view.asset.php +15 -0
  16. package/plugins/interactive-blocks/router-html-regions/view.js +36 -0
  17. package/plugins/interactive-blocks/router-html-server/block.json +20 -0
  18. package/plugins/interactive-blocks/router-html-server/render.php +67 -0
  19. package/plugins/interactive-blocks/router-html-server/view.asset.php +9 -0
  20. package/plugins/interactive-blocks/router-html-server/view.js +47 -0
  21. package/plugins/interactive-blocks/router-navigation-lifecycle/render.php +1 -1
  22. package/plugins/interactive-blocks/router-overlapping-navigations/block.json +15 -0
  23. package/plugins/interactive-blocks/router-overlapping-navigations/render.php +62 -0
  24. package/plugins/interactive-blocks/router-overlapping-navigations/view.asset.php +9 -0
  25. package/plugins/interactive-blocks/router-overlapping-navigations/view.js +50 -0
  26. package/plugins/interactive-blocks/store-tag/render.php +3 -3
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 10.2.0 (2026-11-18)
6
+
7
+ ## 10.1.0 (2026-11-04)
8
+
5
9
  ## 10.0.0 (2026-10-20)
6
10
 
7
11
  ### Breaking Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "10.0.0",
3
+ "version": "10.2.0",
4
4
  "description": "Test plugins and mu-plugins for E2E tests in WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -23,8 +23,8 @@
23
23
  "node": ">=22.13.0"
24
24
  },
25
25
  "dependencies": {
26
- "@wordpress/interactivity": "^8.0.0",
27
- "@wordpress/interactivity-router": "^3.0.0"
26
+ "@wordpress/interactivity": "^8.2.0",
27
+ "@wordpress/interactivity-router": "^3.2.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "y-websocket": "^3.0.0"
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
39
+ "gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
40
40
  }
@@ -0,0 +1,43 @@
1
+ <?php
2
+ /**
3
+ * Plugin Name: Gutenberg Test Content Security Policy
4
+ * Plugin URI: https://github.com/WordPress/gutenberg
5
+ * Author: Gutenberg Team
6
+ *
7
+ * Sends a Content Security Policy that allows neither 'unsafe-eval' nor
8
+ * 'wasm-unsafe-eval' when the `csp` query parameter is `nonce` or `allowlist`.
9
+ * The nonce policy relies on the filters that WordPress provides to add the
10
+ * nonce to the scripts it prints.
11
+ *
12
+ * @package gutenberg-test-content-security-policy
13
+ */
14
+
15
+ add_action(
16
+ 'init',
17
+ static function () {
18
+ $name = isset( $_GET['csp'] ) && is_string( $_GET['csp'] ) ? sanitize_key( wp_unslash( $_GET['csp'] ) ) : '';
19
+
20
+ if ( 'nonce' === $name ) {
21
+ $nonce = base64_encode( random_bytes( 16 ) );
22
+ $script_src = "'nonce-$nonce' 'strict-dynamic'";
23
+
24
+ $add_nonce = static function ( $attributes ) use ( $nonce ) {
25
+ $attributes['nonce'] = $nonce;
26
+ return $attributes;
27
+ };
28
+ add_filter( 'wp_script_attributes', $add_nonce );
29
+ add_filter( 'wp_inline_script_attributes', $add_nonce );
30
+ } elseif ( 'allowlist' === $name ) {
31
+ $script_src = "'self' 'unsafe-inline' blob:";
32
+ } else {
33
+ return;
34
+ }
35
+
36
+ add_action(
37
+ 'send_headers',
38
+ static function () use ( $script_src ) {
39
+ header( "Content-Security-Policy: script-src $script_src; object-src 'none'; base-uri 'none'" );
40
+ }
41
+ );
42
+ }
43
+ );
@@ -87,7 +87,7 @@ function gutenberg_test_entity_actions_api_replace_action() {
87
87
  array_merge(
88
88
  $removed[0],
89
89
  array(
90
- 'label' => 'Move to bin…',
90
+ 'label' => 'Move to bin',
91
91
  'isPrimary' => false,
92
92
  )
93
93
  ),
@@ -0,0 +1,47 @@
1
+ <?php
2
+ /**
3
+ * Plugin Name: Gutenberg Test Footnotes Locked Template
4
+ * Plugin URI: https://github.com/WordPress/gutenberg
5
+ * Author: Gutenberg Team
6
+ *
7
+ * @package gutenberg-test-footnotes-locked-template
8
+ */
9
+
10
+ /**
11
+ * Registers two post types with a locked template, one without and one with
12
+ * a Footnotes block. Both support custom fields and revisions, which the
13
+ * footnotes post meta needs.
14
+ */
15
+ function gutenberg_test_footnotes_locked_template() {
16
+ $supports = array( 'title', 'editor', 'custom-fields', 'revisions' );
17
+
18
+ register_post_type(
19
+ 'locked-paragraph',
20
+ array(
21
+ 'public' => true,
22
+ 'label' => 'Locked Paragraph',
23
+ 'show_in_rest' => true,
24
+ 'supports' => $supports,
25
+ 'template' => array(
26
+ array( 'core/paragraph' ),
27
+ ),
28
+ 'template_lock' => 'all',
29
+ )
30
+ );
31
+
32
+ register_post_type(
33
+ 'locked-footnotes',
34
+ array(
35
+ 'public' => true,
36
+ 'label' => 'Locked Footnotes',
37
+ 'show_in_rest' => true,
38
+ 'supports' => $supports,
39
+ 'template' => array(
40
+ array( 'core/paragraph' ),
41
+ array( 'core/footnotes' ),
42
+ ),
43
+ 'template_lock' => 'all',
44
+ )
45
+ );
46
+ }
47
+ add_action( 'init', 'gutenberg_test_footnotes_locked_template' );
@@ -0,0 +1,30 @@
1
+ <?php
2
+ /**
3
+ * Plugin Name: Gutenberg Test Image Picture Wrapper
4
+ * Plugin URI: https://github.com/WordPress/gutenberg
5
+ * Author: Gutenberg Team
6
+ *
7
+ * @package gutenberg-test-image-picture-wrapper
8
+ */
9
+
10
+ /**
11
+ * Wraps the `img` of an Image block in a `picture` element, the way the Modern
12
+ * Image Formats plugin does when its picture element setting is enabled.
13
+ *
14
+ * @param string $block_content Rendered block content.
15
+ * @param array $block Parsed block.
16
+ * @return string Filtered block content.
17
+ */
18
+ function gutenberg_test_wrap_image_in_picture( $block_content, $block ) {
19
+ if ( 'core/image' !== $block['blockName'] || ! str_contains( $block_content, '<img' ) ) {
20
+ return $block_content;
21
+ }
22
+
23
+ return preg_replace(
24
+ '/<img[^>]+>/',
25
+ '<picture style="display: contents;">$0</picture>',
26
+ $block_content,
27
+ 1
28
+ );
29
+ }
30
+ add_filter( 'render_block', 'gutenberg_test_wrap_image_in_picture', 10, 2 );
@@ -12,7 +12,7 @@
12
12
  >
13
13
  <pre
14
14
  data-testid="parent context"
15
- data-wp-bind--children="state.renderContext"
15
+ data-wp-text="state.renderContext"
16
16
  >
17
17
  <!-- rendered during hydration -->
18
18
  </pre>
@@ -62,7 +62,7 @@
62
62
  >
63
63
  <pre
64
64
  data-testid="child context"
65
- data-wp-bind--children="state.renderContext"
65
+ data-wp-text="state.renderContext"
66
66
  >
67
67
  <!-- rendered during hydration -->
68
68
  </pre>
@@ -8,9 +8,38 @@
8
8
  wp_interactivity_state(
9
9
  'directive-html',
10
10
  array(
11
- 'serverHtml' => array( 'wpServerHtml' => true ),
11
+ 'serverHtml' => array( 'wpServerHtml' => true ),
12
+ 'lazy' => static function () {
13
+ return null;
14
+ },
15
+ /**
16
+ * Leaves the list pending until its client fixture getter is registered.
17
+ *
18
+ * @return null Pending list value.
19
+ */
20
+ 'pendingHydrationList' => static function () {
21
+ return null;
22
+ },
12
23
  )
13
24
  );
25
+
26
+ add_filter(
27
+ 'script_module_data_@wordpress/interactivity',
28
+ /**
29
+ * Marks client-only values as pending until their fixture actions register.
30
+ *
31
+ * @param array|null $data Serialized Interactivity API server data.
32
+ * @return array Server data with the pending fixture value declarations.
33
+ */
34
+ static function ( $data ) {
35
+ $data = $data ?? array();
36
+ $data['derivedStateClosures']['directive-html'] = array_merge(
37
+ $data['derivedStateClosures']['directive-html'] ?? array(),
38
+ array( 'state.lazy', 'state.pendingHydrationList' )
39
+ );
40
+ return $data;
41
+ }
42
+ );
14
43
  ?>
15
44
 
16
45
  <div data-wp-interactive="directive-html">
@@ -28,7 +57,43 @@ wp_interactivity_state(
28
57
  <ul data-testid="created items">
29
58
  <template data-wp-each="state.list"><li><div data-wp-html="state.empty"></div></li></template>
30
59
  </ul>
60
+ <button data-wp-on--click="actions.addFallback" data-testid="add fallback">Add fallback</button>
61
+ <button data-wp-on--click="actions.addTwoFallbacks" data-testid="add two fallbacks">Add two fallbacks</button>
62
+ <button data-wp-on--click="actions.addLazyItem" data-testid="add lazy item">Add lazy item</button>
63
+ <button data-wp-on--click="actions.registerLazy" data-testid="register lazy">Register lazy value</button>
64
+ <button data-wp-on--click="actions.addScriptItems" data-testid="add script items">Add script items</button>
65
+ <button data-wp-on--click="actions.addValueItems" data-testid="add value items">Add value items</button>
66
+ <button data-wp-on--click="actions.addEmptyItem" data-testid="add empty item">Add empty item</button>
67
+ <button data-wp-on--click="actions.rejectFirstItem" data-testid="reject first item">Reject first item</button>
68
+ <button data-wp-on--click="actions.addRejectedItem" data-testid="add rejected item">Add rejected item</button>
69
+ <button data-wp-on--click="actions.resolvePendingList" data-testid="resolve pending list">Resolve pending list</button>
70
+ <ul data-testid="fallback items">
71
+ <template data-wp-each="state.fallbackItems"><li><div data-wp-html="context.item.html"><p>Loading</p></div></li></template>
72
+ </ul>
73
+ <ul data-testid="lazy items">
74
+ <template data-wp-each="state.lazyItems"><li><div data-wp-html="state.lazy"><p>Loading</p></div></li></template>
75
+ </ul>
76
+ <ul data-testid="script items">
77
+ <template data-wp-each="state.scriptItems"><li><div data-wp-html="context.item.html"><p>Loading</p><script>window.fallbackRuns = ( window.fallbackRuns || 0 ) + 1;</script></div></li></template>
78
+ </ul>
79
+ <ul data-testid="value items">
80
+ <template data-wp-each="state.valueItems"><li><div data-wp-html="context.item.html"><p>Loading</p></div></li></template>
81
+ </ul>
82
+ <ul data-testid="empty fallback items">
83
+ <template data-wp-each="state.emptyItems"><li><div data-wp-html="context.item.html"></div></li></template>
84
+ </ul>
85
+ <ul data-testid="hydration items">
86
+ <template data-wp-each="state.hydrationList"><li><span data-wp-html="context.item.html"><i>Fallback</i></span></li></template>
87
+ <li data-wp-each-child><span data-wp-html="context.item.html"><b>one</b></span></li>
88
+ <li data-wp-each-child><span data-wp-html="context.item.html"><b>two</b></span></li>
89
+ </ul>
90
+ <ul data-testid="pending hydration items">
91
+ <template data-wp-each="state.pendingHydrationList"><li><span data-wp-html="context.item.html"><i>Fallback</i></span></li></template>
92
+ <li data-wp-each-child><span data-wp-html="context.item.html"><b>pending one</b></span></li>
93
+ <li data-wp-each-child><span data-wp-html="context.item.html"><b>pending two</b></span></li>
94
+ </ul>
31
95
  <button data-wp-on--click="actions.setRejected" data-testid="set rejected html">Set Rejected HTML</button>
96
+ <button data-wp-on--click="actions.setRejectedTrusted" data-testid="set rejected trusted html">Set Rejected Trusted HTML</button>
32
97
 
33
98
  <button data-wp-on--click="actions.setHtml" data-testid="set html">
34
99
  Set HTML
@@ -4,6 +4,11 @@ const policy = window.trustedTypes?.createPolicy( 'directive-html', {
4
4
  createHTML: ( html ) => html,
5
5
  } );
6
6
 
7
+ // Matches the server's token representation for fallback creation cases.
8
+ const serverHTML = { wpServerHtml: true };
9
+ // Supplies unique item IDs for the created list items.
10
+ let itemId = 0;
11
+
7
12
  const { state } = store( 'directive-html', {
8
13
  state: {
9
14
  html: null,
@@ -16,8 +21,98 @@ const { state } = store( 'directive-html', {
16
21
  empty: null,
17
22
  list: [ 'a', 'b' ],
18
23
  hydration: 'hydrated',
24
+ /** Items whose individual values are server HTML representations. */
25
+ fallbackItems: [],
26
+ /** Items bound to the client getter registered by the fixture. */
27
+ lazyItems: [],
28
+ /** Items whose fallback contains an inert script fixture. */
29
+ scriptItems: [],
30
+ /** Items covering null, invalid, and explicitly trusted values. */
31
+ valueItems: [],
32
+ /** Items bound to an element with no fallback content. */
33
+ emptyItems: [],
34
+ /** Values matching the server-rendered items and one new item. */
35
+ hydrationList: [
36
+ { html: serverHTML },
37
+ { html: serverHTML },
38
+ { html: serverHTML },
39
+ ],
19
40
  },
20
41
  actions: {
42
+ /** Adds one item whose pending representation should show its fallback. */
43
+ addFallback() {
44
+ state.fallbackItems.push( {
45
+ id: ++itemId,
46
+ html: serverHTML,
47
+ } );
48
+ },
49
+ /** Adds two fallback items in the same reactive update. */
50
+ addTwoFallbacks() {
51
+ state.fallbackItems.push(
52
+ { id: ++itemId, html: serverHTML },
53
+ { id: ++itemId, html: serverHTML }
54
+ );
55
+ },
56
+ /** Adds an item whose value remains pending until its getter is registered. */
57
+ addLazyItem() {
58
+ state.lazyItems.push( { id: ++itemId } );
59
+ },
60
+ /** Registers the late trusted HTML getter for the pending item. */
61
+ registerLazy() {
62
+ store( 'directive-html', {
63
+ state: {
64
+ /** Resolves the pending value to trusted markup. */
65
+ get lazy() {
66
+ return asDangerousHTML(
67
+ policy.createHTML( '<b>Late</b>' )
68
+ );
69
+ },
70
+ },
71
+ } );
72
+ },
73
+ /** Adds two items whose fallback includes a script that must stay inert. */
74
+ addScriptItems() {
75
+ state.scriptItems.push(
76
+ { id: ++itemId, html: serverHTML },
77
+ { id: ++itemId, html: serverHTML }
78
+ );
79
+ },
80
+ /** Adds null, invalid-string, and trusted-token values for enforcement. */
81
+ addValueItems() {
82
+ state.valueItems = [
83
+ { html: null },
84
+ { html: '<b>x</b>' },
85
+ {
86
+ html: asDangerousHTML( policy.createHTML( '<b>t</b>' ) ),
87
+ },
88
+ ];
89
+ },
90
+ /** Adds a representation to the list with an empty template fallback. */
91
+ addEmptyItem() {
92
+ state.emptyItems.push( { html: serverHTML } );
93
+ },
94
+ /** Replaces the first displayed fallback with a rejected plain-string token. */
95
+ rejectFirstItem() {
96
+ state.fallbackItems[ 0 ].html = asDangerousHTML( '<b>x</b>' );
97
+ },
98
+ /** Adds a token that enforcement rejects at element creation. */
99
+ addRejectedItem() {
100
+ state.fallbackItems.push( {
101
+ id: ++itemId,
102
+ html: asDangerousHTML( '<b>y</b>' ),
103
+ } );
104
+ },
105
+ /** Resolves the list whose server value stayed pending through hydration. */
106
+ resolvePendingList() {
107
+ store( 'directive-html', {
108
+ state: {
109
+ /** Supplies two server-representation items after hydration. */
110
+ get pendingHydrationList() {
111
+ return [ { html: serverHTML }, { html: serverHTML } ];
112
+ },
113
+ },
114
+ } );
115
+ },
21
116
  setHtml() {
22
117
  state.html = asDangerousHTML(
23
118
  '<strong data-testid="rendered-strong">Rendered HTML</strong>'
@@ -32,6 +127,10 @@ const { state } = store( 'directive-html', {
32
127
  setRejected() {
33
128
  state.rejected = asDangerousHTML( '<b>x</b>' );
34
129
  },
130
+ /** Replaces the rejected string with a policy value of the same markup. */
131
+ setRejectedTrusted() {
132
+ state.rejected = asDangerousHTML( policy.createHTML( '<b>x</b>' ) );
133
+ },
35
134
  setServerHtml() {
36
135
  state.serverHtml = asDangerousHTML( '<p>Client HTML</p>' );
37
136
  },
@@ -8,7 +8,9 @@
8
8
  "attributes": {
9
9
  "page": { "type": "string" },
10
10
  "value": { "type": "string", "default": "null" },
11
- "next": { "type": "string" }
11
+ "next": { "type": "string" },
12
+ "resource": { "type": "string" },
13
+ "prefetch": { "type": "boolean", "default": false }
12
14
  },
13
15
  "supports": {
14
16
  "interactivity": true
@@ -7,6 +7,9 @@
7
7
 
8
8
  $attributes = get_defined_vars()['attributes'];
9
9
  $page = $attributes['page'];
10
+ $resource = is_string( $attributes['resource'] ?? null )
11
+ ? sanitize_key( $attributes['resource'] )
12
+ : '';
10
13
 
11
14
  if ( 'pending' === $attributes['value'] ) {
12
15
  wp_interactivity_state(
@@ -55,10 +58,23 @@ if ( 'pending' === $attributes['value'] ) {
55
58
  <p data-testid="page-content">content from <?php echo esc_html( $page ); ?></p>
56
59
  <div data-testid="kept-html" data-wp-html="state.html"><i><?php echo 'one' === $page ? 'one' : 'two'; ?></i></div>
57
60
  <div data-testid="never-html" data-wp-html="state.never"><i><?php echo 'one' === $page ? 'never one' : 'never two'; ?></i></div>
61
+ <?php if ( $resource ) : ?>
62
+ <div data-testid="fallback-media" data-wp-html="state.media">
63
+ <p>Media fallback</p>
64
+ <video preload="metadata" src="<?php echo esc_url( home_url( '/wp-content/uploads/router-html-' . $resource . '.mp4' ) ); ?>"></video>
65
+ </div>
66
+ <?php endif; ?>
67
+ <?php if ( 'two' === $page && 'pending' === $attributes['value'] ) : ?>
68
+ <div data-testid="added-html" data-wp-html="state.late"><p>B fallback</p><script>window.fallbackRuns = ( window.fallbackRuns || 0 ) + 1;</script></div>
69
+ <?php endif; ?>
58
70
  <p data-testid="value" data-wp-text="state.value">not hydrated</p>
59
71
  <button data-wp-on--click="actions.resolve">Resolve HTML</button>
60
72
  <?php if ( ! empty( $attributes['next'] ) ) : ?>
61
73
  <a href="<?php echo esc_url( $attributes['next'] ); ?>" data-wp-on--click="actions.navigate">Next</a>
62
74
  <?php endif; ?>
75
+ <?php if ( ! empty( $attributes['prefetch'] ) && ! empty( $attributes['next'] ) ) : ?>
76
+ <button data-prefetch-url="<?php echo esc_attr( $attributes['next'] ); ?>" data-testid="prefetch-next" data-wp-on--click="actions.prefetch">Prefetch next page</button>
77
+ <span data-testid="prefetching" data-wp-text="state.prefetching">false</span>
78
+ <?php endif; ?>
63
79
  </div>
64
80
  </div>
@@ -16,16 +16,24 @@ const tokens = {
16
16
 
17
17
  const { state } = store( 'router-html', {
18
18
  state: {
19
+ /** The server's token representation used by the fallback-media fixture. */
20
+ media: { wpServerHtml: true },
21
+ /** Indicates that the fixture's router prefetch action is in progress. */
22
+ prefetching: false,
19
23
  /** Always empty, including on a kept node. */
20
24
  never: null,
21
- /** Returns the destination token, null, or a pending derived value. */
25
+ /** Returns the destination token, representation, null, or pending value. */
22
26
  get html() {
23
- if ( getServerContext().value === 'pending' ) {
27
+ const value = getServerContext().value;
28
+ if ( value === 'pending' ) {
24
29
  return state.late;
25
30
  }
31
+ if ( value === 'representation' ) {
32
+ return { wpServerHtml: true };
33
+ }
26
34
  return getContext().resolved
27
35
  ? tokens.U
28
- : ( tokens[ getServerContext().value ] ?? null );
36
+ : ( tokens[ value ] ?? null );
29
37
  },
30
38
  /** Reports the destination's own serialized value selection. */
31
39
  get value() {
@@ -40,6 +48,20 @@ const { state } = store( 'router-html', {
40
48
  yield import( '@wordpress/interactivity-router' );
41
49
  yield actions.navigate( event.target.href );
42
50
  } ),
51
+ /** Prefetches the destination URL selected by the test fixture. */
52
+ prefetch: withSyncEvent( function* ( event ) {
53
+ event.preventDefault();
54
+ state.prefetching = true;
55
+ try {
56
+ const { actions } =
57
+ yield import( '@wordpress/interactivity-router' );
58
+ yield actions.prefetch(
59
+ event.target.getAttribute( 'data-prefetch-url' )
60
+ );
61
+ } finally {
62
+ state.prefetching = false;
63
+ }
64
+ } ),
43
65
  /** Resolves null HTML or registers the pending derived getter. */
44
66
  resolve() {
45
67
  getContext().resolved = true;
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "test/router-html-regions",
5
+ "title": "E2E Interactivity tests - HTML router regions",
6
+ "category": "text",
7
+ "supports": { "interactivity": true },
8
+ "attributes": {
9
+ "letter": { "type": "string", "default": "A" },
10
+ "next": { "type": "string", "default": "" },
11
+ "mode": { "type": "string", "default": "fallback" },
12
+ "before": { "type": "boolean", "default": false },
13
+ "copy": { "type": "boolean", "default": true }
14
+ },
15
+ "viewScriptModule": "file:./view.js",
16
+ "render": "file:./render.php"
17
+ }
@@ -0,0 +1,77 @@
1
+ <?php
2
+ /**
3
+ * Markup for navigation around inert HTML content.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ // Block rendering supplies attributes; standalone inclusion uses defaults.
9
+ $fixture_attributes = get_defined_vars()['attributes'] ?? array();
10
+ $letter = $fixture_attributes['letter'] ?? 'A';
11
+ $mode = $fixture_attributes['mode'] ?? 'fallback';
12
+ $has_copy = $fixture_attributes['copy'] ?? true;
13
+ $copy_before = $fixture_attributes['before'] ?? false;
14
+ $region_value = 'attach' === $mode ? wp_json_encode(
15
+ array(
16
+ 'id' => 'html/o',
17
+ 'attachTo' => 'body',
18
+ )
19
+ ) : 'html/r';
20
+
21
+ // Derived server state keeps fallback content without defining a client value.
22
+ wp_interactivity_state(
23
+ 'router-html-regions',
24
+ array(
25
+ /**
26
+ * Computes the fallback's pending server value.
27
+ *
28
+ * @return null The client getter is intentionally unavailable.
29
+ */
30
+ 'pending' => static function () {
31
+ return null;
32
+ },
33
+ )
34
+ );
35
+
36
+ add_filter(
37
+ 'script_module_data_@wordpress/interactivity',
38
+ /**
39
+ * Declares the server getter referenced by the HTML directive.
40
+ *
41
+ * @param array|null $data Serialized runtime data.
42
+ * @return array Runtime data with the pending getter declaration.
43
+ */
44
+ static function ( $data ) {
45
+ $data = $data ?? array();
46
+ $data['derivedStateClosures']['router-html-regions'][] = 'state.pending';
47
+ return $data;
48
+ }
49
+ );
50
+
51
+ $copy_markup = $has_copy ? sprintf(
52
+ '<div data-testid="html-owner" data-wp-html="state.pending"><div data-testid="copy" data-wp-interactive="router-html-regions" data-wp-router-region="%s" data-wp-init="actions.mark"><p>copy</p></div></div>',
53
+ esc_attr( $region_value )
54
+ ) : '';
55
+ ?>
56
+ <div data-wp-interactive="router-html-regions">
57
+ <a data-testid="next" data-wp-on--click="actions.navigate" href="<?php echo esc_url( $fixture_attributes['next'] ?? '' ); ?>">Next</a>
58
+ <output data-testid="marks" data-wp-text="state.marks">0</output>
59
+ <?php
60
+ if ( $copy_before && 'fallback' === $mode ) {
61
+ echo $copy_markup;
62
+ }
63
+ ?>
64
+ <?php if ( 'attach' !== $mode || 'B' === $letter ) : ?>
65
+ <div data-testid="real" data-wp-interactive="router-html-regions" data-wp-router-region="<?php echo esc_attr( $region_value ); ?>">
66
+ <p><?php echo esc_html( 'attach' === $mode ? 'overlay ' . $letter : $letter ); ?></p>
67
+ </div>
68
+ <?php endif; ?>
69
+ <?php
70
+ if ( ! $copy_before && 'inserted' !== $mode ) {
71
+ echo $copy_markup;
72
+ }
73
+ ?>
74
+ <?php if ( 'inserted' === $mode && 'A' === $letter ) : ?>
75
+ <div data-testid="html-owner" data-wp-html="state.inserted"></div>
76
+ <?php endif; ?>
77
+ </div>
@@ -0,0 +1,15 @@
1
+ <?php
2
+ /**
3
+ * Script module dependencies for HTML router regions.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+ return array(
8
+ 'dependencies' => array(
9
+ '@wordpress/interactivity',
10
+ array(
11
+ 'id' => '@wordpress/interactivity-router',
12
+ 'import' => 'dynamic',
13
+ ),
14
+ ),
15
+ );
@@ -0,0 +1,36 @@
1
+ import {
2
+ asDangerousHTML,
3
+ store,
4
+ withSyncEvent,
5
+ } from '@wordpress/interactivity';
6
+
7
+ const { state } = store( 'router-html-regions', {
8
+ state: {
9
+ /** Number of directives initialized inside inert copies. */
10
+ marks: 0,
11
+ /** HTML supplied during hydration, outside every router region. */
12
+ inserted: asDangerousHTML(
13
+ '<div data-wp-interactive="router-html-regions" data-wp-router-region="html/r"><p>inserted</p></div>'
14
+ ),
15
+ },
16
+ actions: {
17
+ /** Records an initialization that must not occur inside HTML content. */
18
+ mark() {
19
+ state.marks++;
20
+ },
21
+ /**
22
+ * Navigates from a fixture link without a document reload.
23
+ *
24
+ * @param {MouseEvent} event Link click.
25
+ * @return {Object} Iterator yielding navigation completion.
26
+ */
27
+ navigate: withSyncEvent( function* ( event ) {
28
+ event.preventDefault();
29
+ // currentTarget is only available during synchronous event dispatch.
30
+ const href = event.currentTarget.href;
31
+ const { actions } =
32
+ yield import( '@wordpress/interactivity-router' );
33
+ yield actions.navigate( href );
34
+ } ),
35
+ },
36
+ } );
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "test/router-html-server",
5
+ "title": "E2E Interactivity tests - router server-rendered HTML",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "attributes": {
9
+ "page": { "type": "string" },
10
+ "label": { "type": "string" },
11
+ "next": { "type": "string" },
12
+ "syncedNull": { "type": "boolean" }
13
+ },
14
+ "supports": {
15
+ "interactivity": true
16
+ },
17
+ "textdomain": "e2e-interactivity",
18
+ "viewScriptModule": "file:./view.js",
19
+ "render": "file:./render.php"
20
+ }
@@ -0,0 +1,67 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing kept HTML elements whose value the server renders.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ $attributes = get_defined_vars()['attributes'];
9
+ $page = $attributes['page'];
10
+ $html = '<p>' . esc_html( ucfirst( $attributes['label'] ?? $page ) ) . '</p>';
11
+ // The value that data-wp-watch callbacks copy from this page's server data.
12
+ $synced = empty( $attributes['syncedNull'] ) ? wp_interactivity_as_dangerous_html( $html ) : null;
13
+
14
+ wp_interactivity_state(
15
+ 'router-html-server',
16
+ array(
17
+ 'html' => wp_interactivity_as_dangerous_html( $html ),
18
+ /**
19
+ * Supplies this page's HTML as derived state the client doesn't define.
20
+ *
21
+ * @return WP_Interactivity_Dangerous_HTML The page's HTML.
22
+ */
23
+ 'late' => function () use ( $html ) {
24
+ return wp_interactivity_as_dangerous_html( $html );
25
+ },
26
+ 'same' => wp_interactivity_as_dangerous_html( '<p>Same</p>' ),
27
+ /**
28
+ * Supplies HTML shared by every page as derived state the client
29
+ * doesn't define.
30
+ *
31
+ * @return WP_Interactivity_Dangerous_HTML The shared HTML.
32
+ */
33
+ 'sameLate' => function () {
34
+ return wp_interactivity_as_dangerous_html( '<p>Same</p>' );
35
+ },
36
+ 'synced' => $synced,
37
+ /**
38
+ * Supplies the HTML of the value the client reads from context, since
39
+ * the server never resolves a context value to a token.
40
+ *
41
+ * @return WP_Interactivity_Dangerous_HTML|null The page's HTML, if any.
42
+ */
43
+ 'syncedContext' => function () use ( $synced ) {
44
+ return $synced;
45
+ },
46
+ )
47
+ );
48
+ ?>
49
+
50
+ <div data-wp-interactive="router-html-server">
51
+ <div data-wp-interactive="router-html-server" data-wp-router-region="router-html-server" data-wp-watch="callbacks.syncState">
52
+ <p data-testid="page-content">content from <?php echo esc_html( $page ); ?></p>
53
+ <div data-testid="state-html" data-wp-html="state.html"></div>
54
+ <div data-testid="pending-html" data-wp-html="state.late"></div>
55
+ <div data-testid="same-html" data-wp-html="state.same"></div>
56
+ <div data-testid="same-pending-html" data-wp-html="state.sameLate"></div>
57
+ <div data-testid="synced-state-html" data-wp-html="state.synced"></div>
58
+ <div <?php echo wp_interactivity_data_wp_context( array( 'synced' => $synced ) ); ?> data-wp-watch="callbacks.syncContext">
59
+ <div data-testid="synced-context-html" data-wp-html="state.syncedContext"></div>
60
+ </div>
61
+ <p data-testid="hydrated" data-wp-text="state.hydrated">no</p>
62
+ <?php if ( ! empty( $attributes['next'] ) ) : ?>
63
+ <a href="<?php echo esc_url( $attributes['next'] ); ?>" data-wp-on--click="actions.navigate">Next</a>
64
+ <?php endif; ?>
65
+ <button data-wp-on--click="actions.refresh">Refresh</button>
66
+ </div>
67
+ </div>
@@ -0,0 +1,9 @@
1
+ <?php return array(
2
+ 'dependencies' => array(
3
+ '@wordpress/interactivity',
4
+ array(
5
+ 'id' => '@wordpress/interactivity-router',
6
+ 'import' => 'dynamic',
7
+ ),
8
+ ),
9
+ );
@@ -0,0 +1,47 @@
1
+ import {
2
+ store,
3
+ getContext,
4
+ getServerContext,
5
+ getServerState,
6
+ withSyncEvent,
7
+ } from '@wordpress/interactivity';
8
+
9
+ const { state } = store( 'router-html-server', {
10
+ state: {
11
+ /** Shows that the page has hydrated. */
12
+ hydrated: 'yes',
13
+ /**
14
+ * Reads the value from the element's context.
15
+ *
16
+ * @return {unknown} The value the context holds.
17
+ */
18
+ get syncedContext() {
19
+ return getContext().synced;
20
+ },
21
+ },
22
+ actions: {
23
+ /** Navigates using the router without a document reload. */
24
+ navigate: withSyncEvent( function* ( event ) {
25
+ event.preventDefault();
26
+ const { actions } =
27
+ yield import( '@wordpress/interactivity-router' );
28
+ yield actions.navigate( event.target.href );
29
+ } ),
30
+ /** Fetches the current page again and renders it. */
31
+ *refresh() {
32
+ const { actions } =
33
+ yield import( '@wordpress/interactivity-router' );
34
+ yield actions.navigate( window.location.href, { force: true } );
35
+ },
36
+ },
37
+ callbacks: {
38
+ /** Copies the page's server state into the client state. */
39
+ syncState() {
40
+ state.synced = getServerState().synced;
41
+ },
42
+ /** Copies the page's server context into the element's context. */
43
+ syncContext() {
44
+ getContext().synced = getServerContext().synced;
45
+ },
46
+ },
47
+ } );
@@ -52,7 +52,7 @@ if ( isset( $attributes['secondRegionId'] ) ) {
52
52
  'id' => $attributes['secondRegionId'],
53
53
  // The second region's own "navigate" link targets `other`, not
54
54
  // `next` -- deliberately, so a cross-region flow has two distinct
55
- // hrefs for the router's `navigatingTo` bail to separate. "Same
55
+ // hrefs whose requests a test can hold separately. "Same
56
56
  // structure as the first" stops here: every other link below keeps
57
57
  // its usual meaning for both regions.
58
58
  'navigate_href' => $other_href,
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "test/router-overlapping-navigations",
5
+ "title": "E2E Interactivity tests - router overlapping navigations",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScriptModule": "file:./view.js",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,62 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing what reaches the page when client-side navigations
4
+ * overlap: the router region, the document title, the stylesheets, the
5
+ * server state and context, and the scroll to a URL fragment. Its in-page
6
+ * link and its readouts of `core/router`'s URL and lifecycle test what an
7
+ * in-page link click does to a navigation in flight.
8
+ *
9
+ * @package gutenberg-test-interactive-blocks
10
+ */
11
+
12
+ $attributes = get_defined_vars()['attributes'];
13
+ $page = $attributes['page'] ?? '';
14
+
15
+ // A stylesheet that only the pages with the `stylesheet` attribute carry.
16
+ if ( ! empty( $attributes['stylesheet'] ) ) {
17
+ add_action(
18
+ 'wp_enqueue_scripts',
19
+ function () {
20
+ wp_register_style( 'test-router-overlapping-navigations', false );
21
+ wp_enqueue_style( 'test-router-overlapping-navigations' );
22
+ wp_add_inline_style(
23
+ 'test-router-overlapping-navigations',
24
+ '.router-overlapping-navigations-styled { color: rgb(255, 0, 0); }'
25
+ );
26
+ }
27
+ );
28
+ }
29
+
30
+ wp_interactivity_state(
31
+ 'router-overlapping-navigations',
32
+ array( 'page' => $page )
33
+ );
34
+ ?>
35
+ <div data-wp-interactive="router-overlapping-navigations">
36
+ <p data-testid="server state" data-wp-text="state.serverStatePage"></p>
37
+ <p data-testid="resolved" data-wp-text="state.resolved"></p>
38
+ <p data-testid="router url" data-wp-text="state.routerUrl"></p>
39
+ <p data-testid="lifecycle" data-wp-text="state.lifecycle"></p>
40
+ <a data-testid="in-page link" href="#target">in-page link</a>
41
+ <p data-testid="styled" class="router-overlapping-navigations-styled">styled</p>
42
+
43
+ <div
44
+ data-wp-interactive="router-overlapping-navigations"
45
+ data-wp-router-region="router-overlapping-navigations"
46
+ <?php echo wp_interactivity_data_wp_context( array( 'page' => $page ) ); ?>
47
+ >
48
+ <p data-testid="page"><?php echo esc_html( $page ); ?></p>
49
+ <p data-testid="server context" data-wp-text="state.serverContextPage"></p>
50
+ <?php if ( isset( $attributes['link'] ) ) : ?>
51
+ <a
52
+ data-testid="link"
53
+ data-wp-on--click="actions.navigate"
54
+ href="<?php echo esc_url( $attributes['link'] ); ?>"
55
+ >link</a>
56
+ <?php endif; ?>
57
+ </div>
58
+
59
+ <?php // Leaves the fragment target below the fold, so scrolling to it shows. ?>
60
+ <div style="height: 200vh"></div>
61
+ <p id="target" data-testid="target">target</p>
62
+ </div>
@@ -0,0 +1,9 @@
1
+ <?php return array(
2
+ 'dependencies' => array(
3
+ '@wordpress/interactivity',
4
+ array(
5
+ 'id' => '@wordpress/interactivity-router',
6
+ 'import' => 'dynamic',
7
+ ),
8
+ ),
9
+ );
@@ -0,0 +1,50 @@
1
+ import {
2
+ store,
3
+ getElement,
4
+ getServerContext,
5
+ getServerState,
6
+ watch,
7
+ withSyncEvent,
8
+ } from '@wordpress/interactivity';
9
+
10
+ // Read, not imported, so the readouts work before the router module loads.
11
+ const { state: routerState } = store( 'core/router' );
12
+
13
+ const { state } = store( 'router-overlapping-navigations', {
14
+ state: {
15
+ // The `href` of the last navigation whose promise resolved.
16
+ resolved: '',
17
+ // Every value `state.navigating` and `state.initiator` of `core/router`
18
+ // have taken, in order.
19
+ lifecycle: '',
20
+ get routerUrl() {
21
+ return routerState.url;
22
+ },
23
+ get serverStatePage() {
24
+ return getServerState().page;
25
+ },
26
+ get serverContextPage() {
27
+ return getServerContext().page;
28
+ },
29
+ },
30
+ actions: {
31
+ navigate: withSyncEvent( function* ( event ) {
32
+ event.preventDefault();
33
+ const { href } = getElement().ref;
34
+ const { actions } =
35
+ yield import( '@wordpress/interactivity-router' );
36
+ yield actions.navigate( href );
37
+ state.resolved = href;
38
+ } ),
39
+ },
40
+ } );
41
+
42
+ const lifecycle = [];
43
+ watch( () => {
44
+ lifecycle.push(
45
+ `${ routerState.navigating ? 'navigating' : 'idle' } ${
46
+ routerState.initiator
47
+ }`
48
+ );
49
+ state.lifecycle = lifecycle.join( ', ' );
50
+ } );
@@ -16,14 +16,14 @@ $test_store_tag_double = $test_store_tag_counter * 2;
16
16
  <div>
17
17
  Counter:
18
18
  <span
19
- data-wp-bind--children="state.counter.value"
19
+ data-wp-text="state.counter.value"
20
20
  data-testid="counter value"
21
21
  ><?php echo $test_store_tag_counter; ?></span
22
22
  >
23
23
  <br />
24
24
  Double:
25
25
  <span
26
- data-wp-bind--children="state.counter.double"
26
+ data-wp-text="state.counter.double"
27
27
  data-testid="counter double"
28
28
  ><?php echo $test_store_tag_double; ?></span
29
29
  >
@@ -35,7 +35,7 @@ $test_store_tag_double = $test_store_tag_counter * 2;
35
35
  +1
36
36
  </button>
37
37
  <span
38
- data-wp-bind--children="state.counter.clicks"
38
+ data-wp-text="state.counter.clicks"
39
39
  data-testid="counter clicks"
40
40
  >0</span
41
41
  >