public function testPostModelValidates() { //arrange $post = new Posts(); $post->title = 'GGC Test Post!'; $post->message = 'This is a fake data blah blah blah'; //act $result = $post->validate(); //assert $this->assertTrue($result); }
public static function addPost($uid) { $model = new Posts(); $colid = zmf::filterInput($_POST['Posts']['colid']); $_colid = zmf::filterInput($_POST['colid']); $columnid = zmf::filterInput($_POST['columnid']); if ($colid == '0' or !$colid) { $colid = $columnid; } if (!$columnid) { $colid = $_colid; } $_POST['Posts']['colid'] = $colid; $intoData = $_POST['Posts']; if (!empty($_POST['tagname'])) { $tagNames = array_unique(array_filter($_POST['tagname'])); } $intoKeyid = zmf::filterInput($_POST['Posts']['id'], 't', 1); $intoData['status'] = 1; $content = $_POST['Posts']['content']; $pattern = "/<[img|IMG].*?data=[\\'|\"](.*?)[\\'|\"].*?[\\/]?>/i"; preg_match_all($pattern, $content, $match); if (!empty($match[0])) { $arr = array(); foreach ($match[0] as $key => $val) { $_key = $match[1][$key]; $arr[$_key] = $val; $arr_attachids[] = $match[1][$key]; } if (!empty($arr)) { foreach ($arr as $thekey => $imgsrc) { $content = str_ireplace("{$imgsrc}", '[attach]' . $thekey . '[/attach]', $content); } } } $attachid = zmf::filterInput($_POST['Posts']['attachid'], 't', 1); $intoData['content'] = $content; $intoData['attachid'] = $attachid; if ($_POST['Posts']['secretinfo'] != '') { $_POST['Posts']['secretinfo'] = tools::jiaMi($_POST['Posts']['secretinfo']); } $model->attributes = $intoData; if ($model->validate()) { if ($model->updateByPk($intoKeyid, $intoData)) { if (!empty($arr_attachids)) { $ids = join(',', $arr_attachids); if ($ids != '') { Attachments::model()->updateAll(array('status' => Posts::STATUS_DELED), "logid={$intoKeyid} AND uid={$uid} AND classify='posts'"); Attachments::model()->updateAll(array('status' => Posts::STATUS_PASSED), "id IN({$ids})"); } } zmf::delFCache("notSavePosts{$uid}"); return true; } else { $info = $_POST['Posts']; } } else { $info = $_POST['Posts']; } return $info; }