Skip to content

Commit 2634d8c

Browse files
committed
Gutenberg on WordPress 7.1: the editor gate and canvas; the WordPress version on record; test-env never updates itself (from 9aafefd)
1 parent 0dd01dc commit 2634d8c

3 files changed

Lines changed: 69 additions & 7 deletions

File tree

‎skills/html2wp/assets/scripts/gutenberg-editor-visual.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def size_frame(page,width):
134134
# viewport is resized; its content uses the requested responsive media queries.
135135
element=page.locator('iframe[name="editor-canvas"]')
136136
element.wait_for(state='visible',timeout=60000)
137+
grown=False
137138
for _ in range(8):
138139
element.evaluate('(e,w)=>{e.style.setProperty("width",w+"px","important");e.style.setProperty("height","900px","important");e.style.setProperty("max-width","none","important")}',width)
139140
frame=element.element_handle().content_frame()
@@ -143,7 +144,18 @@ def size_frame(page,width):
143144
if actual=={'width':width,'height':900}:
144145
# Every row of the canvas viewport must reach the screenshot.
145146
clip=element.evaluate(CLIP)
146-
if clip['visibleTop']>clip['top']+.5 or clip['visibleBottom']<clip['bottom']-.5:
147+
short=clip['bottom']-clip['visibleBottom']
148+
# The region holding the canvas is the admin window less its chrome
149+
# (WordPress 7.1 keeps its 32px toolbar in fullscreen mode and has a
150+
# taller footer: 891px for the 900px canvas). A region short at the
151+
# bottom only gets a window that much taller, once; the canvas's own
152+
# viewport is unchanged. Clipped again, or from above, it fails.
153+
if not grown and short>.5 and clip['visibleTop']<=clip['top']+.5:
154+
grown=True
155+
view=page.viewport_size
156+
page.set_viewport_size({'width':view['width'],'height':view['height']+math.ceil(short)})
157+
continue
158+
if clip['visibleTop']>clip['top']+.5 or short>.5:
147159
raise RuntimeError(f'Editor canvas is clipped by the administration layout: {clip}')
148160
return frame
149161
raise RuntimeError(f'Editor iframe viewport differs: {actual}, expected {width}x900')
@@ -168,11 +180,13 @@ def size_frame(page,width):
168180

169181
# The administration chrome around the canvas keeps its layout space but is
170182
# not painted: the admin toolbar's shadow extends one pixel over a mobile
171-
# iframe's edge. The post editor's meta box pane takes none: with it, the
172-
# region holding the canvas was 899px tall and clipped the 900px iframe's
173-
# last row, which every scroll tile ended on (the pane's border, then the
174-
# admin's white: a seam every 450px down a tall capture).
175-
ADMIN_CHROME='.interface-interface-skeleton__header,.interface-interface-skeleton__footer{visibility:hidden!important}.edit-post-meta-boxes-main{display:none!important}'
183+
# iframe's edge. Nor is WordPress's admin bar, which 7.1 keeps in fullscreen
184+
# mode: the capture's pointer, parked at 0,0, opened its WordPress menu over
185+
# the canvas; hidden, it takes no hover. The post editor's meta box pane
186+
# takes no space: with it, the region holding the canvas was 899px tall and
187+
# clipped the 900px iframe's last row, which every scroll tile ended on (the
188+
# pane's border, then the admin's white: a seam every 450px down a tall capture).
189+
ADMIN_CHROME='#wpadminbar,.interface-interface-skeleton__header,.interface-interface-skeleton__footer{visibility:hidden!important}.edit-post-meta-boxes-main{display:none!important}'
176190
# The canvas iframe's box against everything that clips it (the admin
177191
# window and every ancestor with overflow): what a tile can capture.
178192
CLIP='''e=>{const r=e.getBoundingClientRect();let top=Math.max(0,r.top),bottom=Math.min(innerHeight,r.bottom);

‎skills/html2wp/assets/scripts/gutenberg-test-verify.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def test_smoke_captures_1440_only_and_full_all_three(self):
245245
self.assertEqual(shots, ['1440-about-source.png', '1440-about-wp.png', '1440-home-source.png', '1440-home-wp.png', 'captures.json'])
246246
# Not evidence: no import, no editor. The phase itself is what ran.
247247
self.assertFalse(report['passed'])
248+
# Never signed in to wp-admin: the WordPress version is recorded as unknown.
249+
self.assertEqual(report['wordpress'], {'version': None})
248250
report, _ = self.verify()
249251
self.assertEqual(report['scope'], 'full')
250252
self.assertEqual(sorted((r['path'], r['width']) for r in report['visual']),
@@ -310,5 +312,31 @@ def test_workers_must_be_positive(self):
310312
self.assertIn('--workers', run.stderr)
311313

312314

315+
class WordPressVersionTest(unittest.TestCase):
316+
"""The report records the WordPress version the admin screen names
317+
(its `version-7-1-2` body class), and null when it cannot tell."""
318+
319+
def test_the_admin_body_class_names_the_version(self):
320+
from playwright.sync_api import sync_playwright
321+
spec = importlib.util.spec_from_file_location('h2wp_verify_under_test', VERIFY)
322+
verify = importlib.util.module_from_spec(spec)
323+
spec.loader.exec_module(verify)
324+
with sync_playwright() as pw:
325+
browser = pw.chromium.launch()
326+
page = browser.new_page()
327+
for body, version in (('wp-admin wp-core-ui js is-fullscreen-mode branch-7-1 version-7-1-2 admin-color-modern', '7.1.2'),
328+
('wp-admin branch-7 version-7-0-2 locale-en-us', '7.0.2'),
329+
('wp-admin version-7-2', '7.2'),
330+
('wp-admin my-version-7-1-2 version-x', None), ('', None)):
331+
page.set_content(f'<body class="{body}"></body>')
332+
self.assertEqual(verify.wordpress_version(page), version, body)
333+
browser.close()
334+
335+
class Gone:
336+
def wait_for_load_state(self, *a):
337+
raise RuntimeError('Target page, context or browser has been closed')
338+
self.assertIsNone(verify.wordpress_version(Gone()))
339+
340+
313341
if __name__ == '__main__':
314342
unittest.main()

‎skills/html2wp/assets/scripts/gutenberg-verify-local.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,30 @@ def new_page_gate(page,args,nonce):
188188
return result
189189

190190

191+
# Every wp-admin screen's body carries the WordPress version it runs
192+
# (`version-7-1-2`, admin-header.php); the report records it.
193+
ADMIN_VERSION=re.compile(r'(?:^|\s)version-(\d+(?:-\d+)*)(?=\s|$)')
194+
195+
196+
def wordpress_version(page):
197+
"""The WordPress version of the admin screen `page` shows ('7.1.2'), or
198+
None when it cannot be read: the version is recorded, never checked."""
199+
try:
200+
page.wait_for_load_state('domcontentloaded')
201+
found = ADMIN_VERSION.search(page.evaluate('document.body ? document.body.className : ""') or '')
202+
return found.group(1).replace('-', '.') if found else None
203+
except Exception:
204+
return None
205+
206+
191207
def sign_in(page, args):
192-
"""Log `page` in to wp-admin; returns the REST nonce of that session."""
208+
"""Log `page` in to wp-admin; returns the REST nonce of that session and
209+
notes the WordPress version it signed in to (args.wordpress_version)."""
193210
page.goto(args.site + '/wp-login.php')
194211
fill_login(page, args.user, args.password) # read back and retried: lib/capture_ready.py
195212
page.locator('#wp-submit').click()
196213
page.wait_for_url('**/wp-admin/**')
214+
args.wordpress_version = wordpress_version(page)
197215
return page.request.get(args.site + '/wp-admin/admin-ajax.php?action=rest-nonce').text().strip()
198216

199217

@@ -701,6 +719,8 @@ def visual_phase():
701719
except Exception as error:
702720
report['passed']=False
703721
report['error']=str(error)
722+
# The WordPress the gate measured (null: never signed in, or unreadable).
723+
report['wordpress']={'version':getattr(args,'wordpress_version',None)}
704724
Path(args.out).parent.mkdir(parents=True,exist_ok=True)
705725
Path(args.out).write_text(json.dumps(report,indent=2))
706726
print(json.dumps({k:v for k,v in report.items() if k not in ('editor','visual','editorVisual','import')}))

0 commit comments

Comments
 (0)