/** * アンインストールのテスト */ public function test_uninstall() { $post_ids = $this->factory->post->create_many(5, array('post_type' => MWF_Config::NAME)); foreach ($post_ids as $post_id) { update_option(MWF_Config::NAME . '-chart-' . $post_id, 1); $data_post_ids = $this->factory->post->create_many(5, array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id))); } $MW_WP_Form_File = new MW_WP_Form_File(); $temp_dir = $MW_WP_Form_File->get_temp_dir(); $temp_dir = $temp_dir['dir']; system("sudo chmod 777 " . WP_CONTENT_DIR . '/uploads'); $MW_WP_Form_File->create_temp_dir(); $this->assertEquals(true, file_exists($temp_dir)); update_option(MWF_Config::NAME, 1); MW_WP_Form::uninstall(); $posts = get_posts(array('post_type' => MWF_Config::NAME, 'posts_per_page' => -1)); $this->assertEquals(0, count($posts)); foreach ($post_ids as $post_id) { $option = get_option(MWF_Config::NAME . '-chart-' . $post_id); $this->assertEquals(null, $option); $data_posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id), 'posts_per_page' => -1)); $this->assertEquals(0, count($data_posts)); } $this->assertEquals(false, file_exists($temp_dir)); $option = get_option(MWF_Config::NAME); $this->assertEquals(null, $option); }
/** * setUp */ public function setUp() { parent::setUp(); $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME)); $Setting = new MW_WP_Form_Setting($post_id); $Setting->set('usedb', 1); $post_ids = $this->factory->post->create_many(50, array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($Setting->get('post_id')))); $this->post_type = get_post_type($post_ids[0]); $this->CSV = new MW_WP_Form_CSV($this->post_type); }
/** * パースした Mail オブジェクトの取得とデータベースへの保存 * * @param bool $do_update * @return MW_WP_Form_Mail */ public function get_parsed_mail_object($do_update = false) { if ($do_update) { $form_id = $this->Setting->get('post_id'); $insert_contact_data_id = wp_insert_post(array('post_title' => $this->parse_mail_content($this->Mail->subject), 'post_status' => 'publish', 'post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($form_id))); // 添付ファイルをメディアに保存 // save_mail_body 内のフックで添付ファイルの情報を使えるように、 // save_mail_body より前にこのブロックを実行する if (!empty($insert_contact_data_id)) { MWF_Functions::save_attachments_in_media($insert_contact_data_id, $this->Mail->attachments, $form_id); } $this->insert_contact_data_id = $insert_contact_data_id; } return $this->parse_mail_object($do_update); }
/** * setUp */ public function setUp() { parent::setUp(); // 問い合わせデータをデータベースに保存する設定のフォームを作成 $post_ids = $this->factory->post->create_many(5, array('post_type' => MWF_Config::NAME)); foreach ($post_ids as $post_id) { $meta = array('usedb' => 1); update_post_meta($post_id, MWF_Config::NAME, $meta); } // 問い合わせデータを保存(最初のフォームに1件だけ) foreach ($post_ids as $post_id) { $post_id = $this->factory->post->create(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id))); update_post_meta($post_id, MWF_config::CONTACT_DATA_NAME, array('test-1' => 'aaa', 'test-2' => 'bbb')); $Setting = new MW_WP_Form_Contact_Data_Setting($post_id); $this->settings[] = $Setting; $this->post_id = $post_id; break; } }
/** * @group get_parsed_mail_object * @backupStaticAttributes enabled */ public function test_get_parsed_mail_object_Nullでもデータベースに保存_ただし添付の場合は保存しない() { $MW_WP_Form_File = new MW_WP_Form_File(); $temp_dir = $MW_WP_Form_File->get_temp_dir(); $temp_dir = $temp_dir['dir']; system("sudo chmod 777 " . WP_CONTENT_DIR . '/uploads'); $MW_WP_Form_File->create_temp_dir(); file_put_contents($temp_dir . '/attachment_1.txt', 'hoge'); file_put_contents($temp_dir . '/attachment_2.txt', 'fuga'); $this->Data->set('attachment_1', null); $this->Mail->body = '{attachment_1}'; $this->Mail->attachments = array('attachment_1' => $temp_dir . '/attachment_1.txt', 'attachment_2' => $temp_dir . '/attachment_2.txt'); $Mail_Parser = new MW_WP_Form_Mail_Parser($this->Mail, $this->Setting); $Mail_Parser->get_parsed_mail_object(true); $posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($this->Setting->get('post_id')))); foreach ($posts as $post) { $post_metas = get_post_meta($post->ID); $this->assertFalse(isset($post_metas['attachment_1'])); break; } }
/** * アンインストールした時の処理 */ public static function uninstall() { $plugin_dir_path = plugin_dir_path(__FILE__); include_once $plugin_dir_path . 'classes/models/class.admin.php'; $Admin = new MW_WP_Form_Admin(); $forms = $Admin->get_forms(); $data_post_ids = array(); foreach ($forms as $form) { $data_post_ids[] = $form->ID; wp_delete_post($form->ID, true); } foreach ($data_post_ids as $data_post_id) { delete_option(MWF_Config::NAME . '-chart-' . $data_post_id); $data_posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($data_post_id), 'posts_per_page' => -1)); if (empty($data_posts)) { continue; } foreach ($data_posts as $data_post) { wp_delete_post($data_post->ID, true); } } include_once plugin_dir_path(__FILE__) . 'classes/models/class.file.php'; $File = new MW_WP_Form_File(); $File->remove_temp_dir(); delete_option(MWF_Config::NAME); }
/** * @backupStaticAttributes enabled */ public function test_データベースに保存() { $this->Setting->set('usedb', 1); $Mail_Service = new MW_WP_Form_Mail_Service($this->Mail, $this->form_key, $this->Setting); $Mail_Service->send_admin_mail(); $Mail_Service->send_reply_mail(); $this->assertEquals(1, count(get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($this->Setting->get('post_id')), 'posts_per_page' => -1)))); }
/** * @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; } }
/** * データベースに保存に設定されているフォーム(投稿)を取得 * * @return array */ public static function get_posts() { if (self::$contact_data_post_types !== null) { return self::$contact_data_post_types; } $contact_data_post_types = array(); $Admin = new MW_WP_Form_Admin(); $forms = $Admin->get_forms_using_database(); foreach ($forms as $form) { $post_type = MWF_Functions::get_contact_data_post_type_from_form_id($form->ID); $contact_data_post_types[] = $post_type; } $raw_post_types = $contact_data_post_types; $new_post_types = array(); $contact_data_post_types = apply_filters('mwform_contact_data_post_types', $contact_data_post_types); // もともとの配列に含まれていない値は削除する foreach ($contact_data_post_types as $post_type) { if (in_array($post_type, $raw_post_types)) { $new_post_types[] = $post_type; } } self::$contact_data_post_types = $new_post_types; return self::$contact_data_post_types; }