#!/usr/bin/env php db = new stdClass(); } } include dirname(__FILE__, 2) . '/lib/model.class.php'; // 2. 用户登录(选择合适角色) // 如果完整环境可用,使用标准用户切换 if($useFullEnvironment && function_exists('su')) { try { su('admin'); } catch (Exception $e) { // 登录失败,继续测试 } } // 3. 创建测试实例(变量名与模块名一致) $pivotTest = new pivotModelTest(); // 4. 准备测试数据 $records = array( array('id' => 1, 'score' => 10, 'status' => 'active'), array('id' => 2, 'score' => 20, 'status' => 'active'), array('id' => 3, 'score' => 5, 'status' => 'inactive') ); $emptyRecords = array(); $singleRecord = array( array('id' => 1, 'score' => 15, 'status' => 'active') ); // 5. 🔴 强制要求:必须包含至少5个测试步骤 r($pivotTest->getCellDataTest('col1', $records, array('field' => 'score', 'stat' => 'sum'))) && p('value') && e('35'); // 步骤1:sum统计 r($pivotTest->getCellDataTest('col2', $records, array('field' => 'score', 'stat' => 'count'))) && p('value') && e('3'); // 步骤2:count统计 r($pivotTest->getCellDataTest('col3', $records, array('field' => 'score', 'stat' => 'max'))) && p('value') && e('20'); // 步骤3:max统计 r($pivotTest->getCellDataTest('col4', $records, array('field' => 'score', 'stat' => 'min'))) && p('value') && e('5'); // 步骤4:min统计 r($pivotTest->getCellDataTest('col5', $records, array('field' => 'score', 'showOrigin' => 1))) && p('isGroup') && e('~~'); // 步骤5:showOrigin=1返回原始数据 r($pivotTest->getCellDataTest('col6', $emptyRecords, array('field' => 'score', 'stat' => 'count'))) && p('value') && e('0'); // 步骤6:空数组处理 r($pivotTest->getCellDataTest('col7', $singleRecord, array('field' => 'score', 'stat' => 'avg'))) && p('value') && e('15'); // 步骤7:单条记录求平均值