/** * setUp */ public function setUp() { parent::setUp(); $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME)); $form_key = MWF_Functions::get_form_key_from_form_id($post_id); $this->Data = MW_WP_Form_Data::getInstance($form_key); }
public function setUp() { parent::setUp(); $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME)); $this->form_key = MWF_Config::NAME . '-' . $post_id; $this->Mail = new MW_WP_Form_Mail(); $this->Setting = new MW_WP_Form_Setting($post_id); $this->Data = MW_WP_Form_Data::getInstance(MWF_Functions::get_form_key_from_form_id($post_id)); }
/** * ショートコード mwform_formkey をもとにフォームの実行に必須のデータを設定 * * @param array $attributes|'' */ public function set_settings_by_mwform_formkey($attributes) { $post_id = $this->get_form_id_by_mwform_formkey($attributes); $this->post_id = $post_id; $settings = array(); if (!empty($post_id)) { $Setting = new MW_WP_Form_Setting($post_id); foreach ($this->settings as $key => $value) { $settings[$key] = $Setting->get($key); } $settings['key'] = MWF_Functions::get_form_key_from_form_id($post_id); } $this->set_settings($settings); }
/** * $this->_parse_mail_content(), $this->_save_mail_content の本体 * 第2引数でDB保存するか判定 * * @param array $matches * @param bool $do_update * @return string $value */ protected function parse($matches, $do_update = false) { $match = $matches[1]; $form_id = $this->Setting->get('post_id'); // MWF_Config::TRACKINGNUMBER のときはお問い合せ番号を参照する if ($match === MWF_Config::TRACKINGNUMBER) { if ($form_id) { $value = $this->Setting->get_tracking_number($form_id); } } else { $form_key = MWF_Functions::get_form_key_from_form_id($form_id); $value = $this->Data->get($match); $value = $this->apply_filters_mwform_custom_mail_tag($form_key, $value, $match); } // 値が null でも保存(チェッボックス未チェックで直送信でも保存させるため) // ただし、画像の場合はURLが保存されないように調整がはいるため除外が必要 if ($do_update) { if (!array_key_exists($match, $this->Mail->attachments)) { update_post_meta($this->insert_contact_data_id, $match, $value); } } return $value; }
/** * @group parse * @backupStaticAttributes enabled */ public function test_parse_データベースに保存() { $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME)); $Setting = new MW_WP_Form_Setting($post_id); $Data = MW_WP_Form_Data::getInstance(MWF_Functions::get_form_key_from_form_id($post_id)); $Data->set('example', 'example'); $this->Mail->body = '{example}'; $this->Mail->parse($Setting, true); $posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id))); foreach ($posts as $post) { $this->assertEquals('example', get_post_meta($post->ID, 'example', true)); break; } }