feat(contact): 实现大公司品牌级联系我们独立页(结构化需求表单、物理双基地地址、架构师直连热线与地图视窗)
这个提交包含在:
128
tests/ContactPageTest.php
普通文件
128
tests/ContactPageTest.php
普通文件
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* 联系我们独立页改版规范与内容完整性测试 (TDD 模式)
|
||||
* 验证联系我们必备板块:表单、地图、电话,以及色彩体系、去AI味道与禁止项
|
||||
*/
|
||||
|
||||
class ContactPageTest
|
||||
{
|
||||
private $passed = 0;
|
||||
private $failed = 0;
|
||||
private $htmlContent = '';
|
||||
private $mobileHtmlContent = '';
|
||||
private $cssContent = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$baseDir = dirname(__DIR__);
|
||||
$contactFile = $baseDir . '/addons/official/view/web/official_online_message/list.html';
|
||||
$mobileContactFile = $baseDir . '/addons/official/view/web/official_online_message/list_e.html';
|
||||
$cssFile = $baseDir . '/public/assets/addons/official/css/modern_nhc.css';
|
||||
|
||||
if (file_exists($contactFile)) {
|
||||
$this->htmlContent = file_get_contents($contactFile);
|
||||
}
|
||||
if (file_exists($mobileContactFile)) {
|
||||
$this->mobileHtmlContent = file_get_contents($mobileContactFile);
|
||||
}
|
||||
if (file_exists($cssFile)) {
|
||||
$this->cssContent = file_get_contents($cssFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
echo "=== 开始执行联系我们独立页设计规范与内容完整性测试 (TDD) ===\n";
|
||||
|
||||
// 1. 品牌名称必须为纳海川
|
||||
$this->testBrandName();
|
||||
|
||||
// 2. 必备板块测试:表单、地图、电话 (AGENTS.md 规范)
|
||||
$this->testEssentialSections();
|
||||
|
||||
// 3. 去除 AI 味道:真实具体的办公地址、电话号码与架构师对接承诺
|
||||
$this->testNoAiCharacteristics();
|
||||
|
||||
// 4. 禁止项测试(严禁 emoji)
|
||||
$this->testForbiddenElements();
|
||||
|
||||
// 5. 色彩与设计规范
|
||||
$this->testDesignTokens();
|
||||
|
||||
// 6. 移动端模板完整性
|
||||
$this->testMobileTemplate();
|
||||
|
||||
echo "\n测试结果: {$this->passed} 通过, {$this->failed} 失败\n";
|
||||
if ($this->failed > 0) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private function assert($condition, $message)
|
||||
{
|
||||
if ($condition) {
|
||||
echo " [PASS] {$message}\n";
|
||||
$this->passed++;
|
||||
} else {
|
||||
echo " [FAIL] {$message}\n";
|
||||
$this->failed++;
|
||||
}
|
||||
}
|
||||
|
||||
public function testBrandName()
|
||||
{
|
||||
$this->assert(strpos($this->htmlContent, '纳海川') !== false, "联系我们页面必须明确包含品牌名称【纳海川】");
|
||||
$hasWrongAbbr = preg_match('/纳川(?![海])/u', $this->htmlContent);
|
||||
$this->assert(!$hasWrongAbbr, "联系我们页面严禁错误简称为【纳川】");
|
||||
}
|
||||
|
||||
public function testEssentialSections()
|
||||
{
|
||||
// 按照 AGENTS.md 规范:联系我们含表单、地图、电话
|
||||
$hasForm = (strpos($this->htmlContent, '<form') !== false && strpos($this->htmlContent, 'name="phone"') !== false && strpos($this->htmlContent, 'name="title"') !== false);
|
||||
$this->assert($hasForm, "联系我们页面必须包含【表单】(包含对接人、电话、需求与提交按钮)板块");
|
||||
|
||||
$hasMap = (strpos($this->htmlContent, 'nhc-contact-map') !== false || strpos($this->htmlContent, '地图') !== false || strpos($this->htmlContent, '园区') !== false || strpos($this->htmlContent, '大厦') !== false);
|
||||
$this->assert($hasMap, "联系我们页面必须包含【地图】(办公地址与交通指引/地图视窗)板块");
|
||||
|
||||
$hasPhone = (strpos($this->htmlContent, '13984036826') !== false || strpos($this->htmlContent, 'tel:') !== false);
|
||||
$this->assert($hasPhone, "联系我们页面必须包含【电话】(业务直通电话)板块");
|
||||
}
|
||||
|
||||
public function testNoAiCharacteristics()
|
||||
{
|
||||
// 必须具备真实的落地实体地址(南明区花果园、经开区等真实地址)
|
||||
$hasRealAddress = (strpos($this->htmlContent, '南明区') !== false || strpos($this->htmlContent, '花果园') !== false || strpos($this->htmlContent, '经开区') !== false);
|
||||
$this->assert($hasRealAddress, "去AI味道:必须展示具体的真实物理实体地址");
|
||||
|
||||
// 必须具备真实的电子邮箱与服务时间承诺
|
||||
$hasContactDetails = (strpos($this->htmlContent, 'server@gynhc.com') !== false || strpos($this->htmlContent, '09:00') !== false || strpos($this->htmlContent, 'SLA') !== false || strpos($this->htmlContent, '小时') !== false);
|
||||
$this->assert($hasContactDetails, "去AI味道:必须具备真实企业邮箱与明确的响应时效服务承诺");
|
||||
}
|
||||
|
||||
public function testForbiddenElements()
|
||||
{
|
||||
$hasEmoji = preg_match('/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}]/u', $this->htmlContent);
|
||||
$this->assert(!$hasEmoji, "联系我们页面严禁使用任何 emoji 表情符号");
|
||||
}
|
||||
|
||||
public function testDesignTokens()
|
||||
{
|
||||
$hasSerif = (stripos($this->cssContent, 'SimSun') !== false || stripos($this->cssContent, 'Songti') !== false || stripos($this->cssContent, 'Noto Serif SC') !== false);
|
||||
$this->assert($hasSerif, "必须沿用宋体标题规范");
|
||||
|
||||
$hasPrimary = (stripos($this->cssContent, '#2563EB') !== false || stripos($this->cssContent, '#2563eb') !== false);
|
||||
$this->assert($hasPrimary, "必须沿用科技蓝 #2563EB 主色规范");
|
||||
}
|
||||
|
||||
public function testMobileTemplate()
|
||||
{
|
||||
$this->assert(!empty($this->mobileHtmlContent), "移动端联系我们模板 list_e.html 文件必须存在");
|
||||
$this->assert(strpos($this->mobileHtmlContent, '纳海川') !== false, "移动端模板必须包含品牌名【纳海川】");
|
||||
$this->assert(strpos($this->mobileHtmlContent, '<form') !== false, "移动端模板必须包含需求提交表单");
|
||||
$this->assert(strpos($this->mobileHtmlContent, '13984036826') !== false || strpos($this->mobileHtmlContent, 'tel:') !== false, "移动端模板必须包含电话直拨");
|
||||
}
|
||||
}
|
||||
|
||||
$test = new ContactPageTest();
|
||||
$test->run();
|
||||
@@ -177,13 +177,50 @@ def test_about_page():
|
||||
|
||||
return res.summary()
|
||||
|
||||
def test_contact_page():
|
||||
res = TestResult("联系我们独立页 (ContactPage)")
|
||||
contact_path = os.path.join(BASE_DIR, 'addons', 'official', 'view', 'web', 'official_online_message', 'list.html')
|
||||
contact_e_path = os.path.join(BASE_DIR, 'addons', 'official', 'view', 'web', 'official_online_message', 'list_e.html')
|
||||
css_path = os.path.join(BASE_DIR, 'public', 'assets', 'addons', 'official', 'css', 'modern_nhc.css')
|
||||
|
||||
html = open(contact_path, 'r', encoding='utf-8').read() if os.path.exists(contact_path) else ''
|
||||
mobile_html = open(contact_e_path, 'r', encoding='utf-8').read() if os.path.exists(contact_e_path) else ''
|
||||
css = open(css_path, 'r', encoding='utf-8').read() if os.path.exists(css_path) else ''
|
||||
|
||||
res.assert_true('纳海川' in html, "PC 联系我们页必须明确包含品牌名称【纳海川】")
|
||||
res.assert_true(not re.search(r'纳川(?!海)', html), "PC 联系我们页严禁错误简称为【纳川】")
|
||||
|
||||
has_form = '<form' in html and 'name="phone"' in html and 'name="title"' in html
|
||||
res.assert_true(has_form, "必须包含【表单】板块")
|
||||
has_map = 'nhc-contact-map' in html or '地图' in html or '园区' in html or '大厦' in html
|
||||
res.assert_true(has_map, "必须包含【地图】(办公地址与交通指引/地图视窗)板块")
|
||||
has_phone = '13984036826' in html or 'tel:' in html
|
||||
res.assert_true(has_phone, "必须包含【电话】板块")
|
||||
|
||||
has_addr = '南明区' in html or '花果园' in html or '经开区' in html
|
||||
res.assert_true(has_addr, "去AI味道:展示具体真实物理实体地址")
|
||||
has_details = 'server@gynhc.com' in html or '09:00' in html or 'SLA' in html
|
||||
res.assert_true(has_details, "去AI味道:真实企业邮箱与明确响应时效承诺")
|
||||
|
||||
has_emoji = bool(re.search(r'[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\u2600-\u26FF\u2700-\u27BF]', html))
|
||||
res.assert_true(not has_emoji, "严禁使用任何 emoji 表情符号")
|
||||
|
||||
res.assert_true(bool(mobile_html), "移动端联系我们模板 list_e.html 必须存在")
|
||||
if mobile_html:
|
||||
res.assert_true('纳海川' in mobile_html, "移动端模板包含品牌名【纳海川】")
|
||||
res.assert_true('<form' in mobile_html, "移动端模板包含需求提交表单")
|
||||
res.assert_true('13984036826' in mobile_html or 'tel:' in mobile_html, "移动端模板包含电话直拨")
|
||||
|
||||
return res.summary()
|
||||
|
||||
def main():
|
||||
results = [
|
||||
test_cases_page(),
|
||||
test_services_page(),
|
||||
test_products_page(),
|
||||
test_nav_megamenu(),
|
||||
test_about_page()
|
||||
test_about_page(),
|
||||
test_contact_page()
|
||||
]
|
||||
sys.exit(0 if all(results) else 1)
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户