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, '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, 'assert(strpos($this->mobileHtmlContent, '13984036826') !== false || strpos($this->mobileHtmlContent, 'tel:') !== false, "移动端模板必须包含电话直拨"); } } $test = new ContactPageTest(); $test->run();