예제 #1
0
 /**
  * @group push_uploaded_file_keys
  */
 public function test_push_uploaded_file_keys()
 {
     $this->Data->set(MWF_Config::UPLOAD_FILE_KEYS, array('file1'));
     $this->Data->push_uploaded_file_keys(array('file1' => 'http://exemple.com/dummy.txt'));
     $this->assertSame(array('file1'), $this->Data->get_post_value_by_key(MWF_Config::UPLOAD_FILE_KEYS));
     $this->Data->set(MWF_Config::UPLOAD_FILE_KEYS, array('file1'));
     $this->Data->push_uploaded_file_keys(array('file2' => 'http://exemple.com/dummy.txt'));
     $this->assertSame(array('file1', 'file2'), $this->Data->get_post_value_by_key(MWF_Config::UPLOAD_FILE_KEYS));
 }
 /**
  * @backupStaticAttributes enabled
  */
 public function test_管理者宛メール関連フックのテスト_送信内容に応じてメール設定を書き換える()
 {
     $self = $this;
     add_filter('mwform_admin_mail_raw_' . $this->form_key, function ($Mail, $values) use($self) {
         $Mail->from = '{メールアドレス}';
         return $Mail;
     }, 10, 2);
     add_filter('mwform_admin_mail_' . $this->form_key, function ($Mail, $values) use($self) {
         $self->assertEquals($Mail->from, '*****@*****.**');
         return $Mail;
     }, 10, 2);
     $this->Data->set('メールアドレス', '*****@*****.**');
     $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();
 }
 /**
  * @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;
     }
 }
예제 #4
0
 /**
  * 送信されたデータをもとに添付ファイル用の配列を生成して返す
  *
  * @return array $attachments pathの配列
  */
 protected function get_attachments()
 {
     $attachments = array();
     $upload_file_keys = $this->Data->get_post_value_by_key(MWF_Config::UPLOAD_FILE_KEYS);
     if ($upload_file_keys !== null && is_array($upload_file_keys)) {
         $wp_upload_dir = wp_upload_dir();
         foreach ($upload_file_keys as $key) {
             $upload_file_url = $this->Data->get_post_value_by_key($key);
             if (!$upload_file_url) {
                 continue;
             }
             $filepath = MWF_Functions::fileurl_to_path($upload_file_url);
             if (file_exists($filepath)) {
                 $filepath = MWF_Functions::move_temp_file_to_upload_dir($filepath);
                 $new_upload_file_url = MWF_Functions::filepath_to_url($filepath);
                 $this->Data->set($key, $new_upload_file_url);
                 $attachments[$key] = $filepath;
             }
         }
     }
     return $attachments;
 }