navContent = file_get_contents($navFile); } if (file_exists($cssFile)) { $this->cssContent = file_get_contents($cssFile); } } public function run() { echo "=== 开始执行导航栏二级卡片面板规范测试 (TDD) ===\n"; // 1. 基础结构测试 $this->testMegaMenuStructure(); // 2. 服务二级卡片面板业务内容测试 $this->testServicesMegaMenu(); // 3. 产品二级卡片面板业务内容测试 $this->testProductsMegaMenu(); // 4. CSS 交互与现代中式质感测试 $this->testMegaMenuCss(); // 5. 禁止项测试(严禁使用 emoji) $this->testForbiddenElements(); 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 testMegaMenuStructure() { $hasDropdownClass = (strpos($this->navContent, 'nhc-has-dropdown') !== false); $this->assert($hasDropdownClass, "导航栏必须具备 nhc-has-dropdown 下拉菜单触发类"); $hasMegaPanel = (strpos($this->navContent, 'nhc-mega-panel') !== false); $this->assert($hasMegaPanel, "导航栏必须具备高端大气的 nhc-mega-panel 二级卡片面板容器"); } public function testServicesMegaMenu() { $this->assert(strpos($this->navContent, '软件开发') !== false, "服务二级面板必须包含【软件开发】卡片"); $this->assert(strpos($this->navContent, 'APP与小程序定制') !== false || (strpos($this->navContent, 'APP') !== false && strpos($this->navContent, '小程序') !== false), "服务二级面板必须包含【APP与小程序定制】卡片"); $this->assert(strpos($this->navContent, '智能体开发') !== false, "服务二级面板必须包含【智能体开发】卡片"); } public function testProductsMegaMenu() { $this->assert(strpos($this->navContent, '商城') !== false, "产品二级面板必须包含【商城】卡片"); $this->assert(strpos($this->navContent, '收银') !== false, "产品二级面板必须包含【收银】卡片"); $this->assert(strpos($this->navContent, '进销存') !== false, "产品二级面板必须包含【进销存】卡片"); $this->assert(strpos($this->navContent, 'SaaS') !== false, "产品二级面板必须包含【SaaS版本】卡片"); } public function testMegaMenuCss() { $hasPanelStyle = (strpos($this->cssContent, '.nhc-mega-panel') !== false); $this->assert($hasPanelStyle, "CSS 中必须包含 .nhc-mega-panel 卡片面板样式"); $hasHoverTrigger = (strpos($this->cssContent, '.nhc-has-dropdown:hover') !== false || strpos($this->cssContent, '.nhc-mega-panel.active') !== false); $this->assert($hasHoverTrigger, "CSS 中必须包含鼠标划过悬停展开交互样式"); } 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->navContent); $this->assert(!$hasEmoji, "导航栏及二级卡片面板严禁使用任何 emoji 表情"); } } $test = new NavMegaMenuTest(); $test->run();