htmlContent = file_get_contents($caseFile); } if (file_exists($mobileCaseFile)) { $this->mobileHtmlContent = file_get_contents($mobileCaseFile); } 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 规范:案例页含筛选、挑战方案结果、数据 $hasFilter = (strpos($this->htmlContent, 'nhc-case-filter') !== false || strpos($this->htmlContent, '全部案例') !== false); $this->assert($hasFilter, "案例页必须包含【筛选】(多维业务/行业分类筛选器)板块"); $hasChallenge = (strpos($this->htmlContent, '遇到的问题') !== false || strpos($this->htmlContent, '业务挑战') !== false || strpos($this->htmlContent, 'CHALLENGE') !== false); $hasSolution = (strpos($this->htmlContent, '我们的做法') !== false || strpos($this->htmlContent, '技术方案') !== false || strpos($this->htmlContent, '实施方案') !== false || strpos($this->htmlContent, 'SOLUTION') !== false || strpos($this->htmlContent, '解决方案') !== false); $hasResult = (strpos($this->htmlContent, '交付结果') !== false || strpos($this->htmlContent, '成果验证') !== false || strpos($this->htmlContent, '交付内容') !== false || strpos($this->htmlContent, 'RESULT') !== false || strpos($this->htmlContent, '交付成效') !== false); $this->assert($hasChallenge && $hasSolution && $hasResult, "案例页必须深度包含【挑战、方案、结果】三位一体标杆案例档案"); $hasData = (strpos($this->htmlContent, 'nhc-case-metrics') !== false || strpos($this->htmlContent, '数据验证') !== false || strpos($this->htmlContent, '成果指标') !== false); $this->assert($hasData, "案例页必须包含【数据】(可量化业务数据指标墙)板块"); } public function testNoAiCharacteristics() { // 必须具备真实可信的业务机制与指标(不使用无出处的百分比/单量) $hasMetrics = (strpos($this->htmlContent, 'nhc-case-metrics') !== false && (strpos($this->htmlContent, '自动分单') !== false || strpos($this->htmlContent, '动态 BOM') !== false || strpos($this->htmlContent, '断网断电仍可收银') !== false)); $this->assert($hasMetrics, "去AI味道:案例必须具备真实可信的业务机制与指标"); // 覆盖重点实体行业(商贸零售、智能制造、政企服务等) $hasRealIndustries = (strpos($this->htmlContent, '商贸') !== false || strpos($this->htmlContent, '零售') !== false || strpos($this->htmlContent, '制造') !== false); $this->assert($hasRealIndustries, "去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, 'nhc-case-filter') !== false, "移动端模板必须包含多维案例筛选器"); $this->assert(strpos($this->mobileHtmlContent, '遇到的问题') !== false || strpos($this->mobileHtmlContent, 'CHALLENGE') !== false || strpos($this->mobileHtmlContent, '业务挑战') !== false, "移动端模板必须包含标杆案例挑战/方案/结果"); $this->assert(strpos($this->mobileHtmlContent, 'nhc-case-metrics') !== false, "移动端模板必须包含数据指标墙"); } } $test = new CasesPageTest(); $test->run();