/** * @group mwform */ public function test_mwform_querystringが有効な場合は引数で指定された投稿情報に置換() { global $wp_query, $post; $wp_query->is_singular = true; $this->Setting->set('querystring', 1); $this->Setting->save(); $post_id = $this->factory->post->create(); $post_id_2 = $this->factory->post->create(); update_post_meta($post_id_2, 'meta', 'meta'); $ExecShortcode = $this->get_ExecShortcode_after_add_shortcode('input'); $_GET['post_id'] = $post_id_2; $content = "{ID}\n"; $content .= "{post_title}\n"; $content .= "{post_content}\n"; $content .= "{post_excerpt}\n"; $content .= "{meta}"; $post = get_post($post_id_2); $this->assertEquals("{$post->ID}\n{$post->post_title}\n{$post->post_content}\n{$post->post_excerpt}\n{$post->meta}", $ExecShortcode->get_the_content($content)); }
/** * save_post * @param int $post_id */ public function save_post($post_id) { if (!(isset($_POST['post_type']) && $_POST['post_type'] === MWF_Config::NAME)) { return $post_id; } if (!isset($_POST[MWF_Config::NAME . '_nonce'])) { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if (!wp_verify_nonce($_POST[MWF_Config::NAME . '_nonce'], MWF_Config::NAME)) { return $post_id; } if (!current_user_can(MWF_Config::CAPABILITY)) { return $post_id; } $data = $_POST[MWF_Config::NAME]; $triminglists = array('mail_from', 'mail_to', 'mail_cc', 'mail_bcc', 'admin_mail_from'); foreach ($triminglists as $name) { $data[$name] = trim(mb_convert_kana($data[$name], 's', get_option('blog_charset'))); } if (!empty($data['validation']) && is_array($data['validation'])) { $validation = array(); foreach ($data['validation'] as $_validation) { if (empty($_validation['target'])) { continue; } foreach ($_validation as $key => $value) { // between min, max if ($key == 'between') { if (!MWF_Functions::is_numeric($value['min'])) { unset($_validation[$key]['min']); } if (!MWF_Functions::is_numeric($value['max'])) { unset($_validation[$key]['max']); } } elseif ($key == 'minlength' && !MWF_Functions::is_numeric($value['min'])) { unset($_validation[$key]); } elseif ($key == 'fileType' && isset($value['types']) && !preg_match('/^[0-9A-Za-z,]+$/', $value['types'])) { unset($_validation[$key]); } elseif ($key == 'fileSize' && !MWF_Functions::is_numeric($value['bytes'])) { unset($_validation[$key]); } // 要素が空のときは削除 // 単一項目のとき if (empty($value)) { unset($_validation[$key]); } elseif (is_array($value) && !array_diff($value, array(''))) { unset($_validation[$key]); } } $validation[] = $_validation; } $data['validation'] = $validation; } // チェックボックスの項目は、未設定のときはデータが来ないのでここで処理する if (empty($data['querystring'])) { $data['querystring'] = false; } if (empty($data['usedb'])) { $data['usedb'] = false; } if (empty($data['scroll'])) { $data['scroll'] = false; } $Setting = new MW_WP_Form_Setting($post_id); $Setting->sets($data); if (isset($_POST[MWF_Config::TRACKINGNUMBER])) { $tracking_number = $_POST[MWF_Config::TRACKINGNUMBER]; $Setting->update_tracking_number($tracking_number); } $Setting->save(); }
/** * @group save */ public function test_save() { $this->Setting->set('mail_subject', 'new_mail_subject'); $this->Setting->save(); $this->assertEquals('new_mail_subject', $this->Setting->get('mail_subject')); }