/** * アンインストールのテスト */ 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); }
/** * メール送信 */ public function send() { if (!$this->to) { return; } $sender = $this->sender; $from = $this->from; $subject = $this->subject; $body = $this->body; add_action('phpmailer_init', array($this, 'set_return_path')); add_filter('wp_mail_from', array($this, 'set_mail_from')); add_filter('wp_mail_from_name', array($this, 'set_mail_from_name')); if (defined('MWFORM_DEBUG') && MWFORM_DEBUG === true) { $File = new MW_WP_Form_File(); $File->create_temp_dir(); $temp_dir = $File->get_temp_dir(); $temp_dir = trailingslashit($temp_dir['dir']); $temp_dir = apply_filters('mwform_log_directory', $temp_dir); } $tos = explode(',', $this->to); foreach ($tos as $to) { $headers = array(); if ($this->cc) { $headers[] = 'Cc: ' . $this->cc; } if ($this->bcc) { $headers[] = 'Bcc: ' . $this->bcc; } $to = trim($to); if (!empty($File)) { $contents = sprintf("====================\n\nSend Date: %s\nTo: %s\nSender: %s\nFrom: %s\nSubject: %s\nheaders:%s\n-----\n%s\n-----\nattachments:\n%s\n\n", date('M j Y, H:i:s'), $to, $sender, $from, $subject, implode("\n", $headers), $body, implode("\n", $this->attachments)); file_put_contents($temp_dir . '/mw-wp-form-debug.log', $contents, FILE_APPEND); } else { @wp_mail($to, $subject, $body, $headers, $this->attachments); } } remove_action('phpmailer_init', array($this, 'set_return_path')); remove_filter('wp_mail_from', array($this, 'set_mail_from')); remove_filter('wp_mail_from_name', array($this, 'set_mail_from_name')); }
/** * @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; } }
/** * @group get_temp_dir */ public function test_get_temp_dir() { $this->assertEquals(array('dir' => ABSPATH . 'wp-content/uploads/mw-wp-form_uploads', 'url' => home_url('/wp-content/uploads/mw-wp-form_uploads')), $this->File->get_temp_dir()); }