Files
cms-SiteForge/tests/test_wordpress_baseline.py
浅念 601451f22b upgrade: adopt V8.21.3 (V8.13→8.21.3: P5 SFTP/S3, P6 multilingual, editor overhaul, enterprise hardening)
Overlay ~150 upstream items onto our V8.12 base, preserving trade-pro
theme, registry tests, and design docs. Re-applied our patch set
(discovery/env_for/blocks.css/type-mapping/theme_color/frontend entries,
test_theme_pro_v3 mods) — all anchors survived upstream evolution.

New platform enhancement (fixes upgrade-introduced regression):
multilingual.site_locale now honors settings_json.locale, plus
PUT /api/i18n/sites/{id}/locale — standalone English sites get
<html lang='en'> under the V8.15 locale-rewrite pipeline.

compose: adopt V8.21.3 (image 8.21.3-dev.1, /api/ready probes, MySQL/S3
env) with project name pinned to siteforge-v8-10 (data volumes).

Tests: 356 passed / 11 failed — all 11 confirmed pre-existing in
pristine V8.21.3 on this host (10 upstream Windows env + our build test
now green after locale fix). Patch registry updated in plan doc.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-23 12:31:03 +08:00

48 lines
2.5 KiB
Python

import importlib.util
import tempfile
import unittest
from pathlib import Path
import sys
p = Path(__file__).resolve().parents[1] / 'scripts' / 'export_wordpress_url_baseline.py'
spec = importlib.util.spec_from_file_location('url_baseline', p)
a = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = a
spec.loader.exec_module(a)
class Tests(unittest.TestCase):
def test_legacy_url_route(self):
self.assertEqual(a.route_from_url('https://example.com/pickup-truck/', {'example.com'}), '/pickup-truck/')
def test_query_legacy_requires_manual_mapping(self):
self.assertIsNone(a.route_from_url('https://example.com/?p=22', {'example.com'}))
def test_foreign_host_excluded(self):
self.assertIsNone(a.route_from_url('https://bad.example.com/x/', {'example.com'}))
def test_wxr_only_published_not_attachments(self):
with tempfile.TemporaryDirectory() as d:
f = Path(d)/'wp.xml'
f.write_text('''<?xml version="1.0" encoding="UTF-8"?><rss xmlns:wp="http://wordpress.org/export/1.2/"><channel>
<item><link>https://example.com/p1/</link><wp:post_type>page</wp:post_type><wp:status>publish</wp:status></item>
<item><link>https://example.com/p2/</link><wp:post_type>page</wp:post_type><wp:status>draft</wp:status></item>
<item><link>https://example.com/upload/</link><wp:post_type>attachment</wp:post_type><wp:status>publish</wp:status></item>
</channel></rss>''')
out=Path(d)/'old.txt'
self.assertEqual(a.main([str(f),'--host','example.com','--output',str(out)]),0)
self.assertIn('/p1/',out.read_text())
self.assertNotIn('/p2/',out.read_text())
self.assertNotIn('/upload/',out.read_text())
def test_sitemap_support(self):
with tempfile.TemporaryDirectory() as d:
f=Path(d)/'s.xml'
f.write_text('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/about/</loc></url></urlset>')
out=Path(d)/'urls.txt'
self.assertEqual(a.main([str(f),'--host','example.com','--output',str(out)]),0)
self.assertIn('/about/',out.read_text())
def test_dtd_rejected(self):
with tempfile.TemporaryDirectory() as d:
f=Path(d)/'s.xml'
f.write_text('<!DOCTYPE urlset [<!ENTITY hacked "HACK">]><urlset>&hacked;</urlset>')
self.assertNotEqual(a.main([str(f),'--host','example.com','--output',str(Path(d)/'urls.txt')]),0)
if __name__=='__main__': unittest.main()