/** * @group upload * @group cover_images */ public function test_bp_attachment_upload_dir_filter_arg() { $reset_files = $_FILES; $reset_post = $_POST; $attachment_class = new BPTest_Attachment_Extension(array('action' => 'attachment_action', 'file_input' => 'attachment_file_input', 'base_dir' => 'attachment_base_dir', 'upload_dir_filter_args' => 1)); $_POST['action'] = $attachment_class->action; $_FILES[$attachment_class->file_input] = array('tmp_name' => $this->image_file, 'name' => 'mystery-man.jpg', 'type' => 'image/jpeg', 'error' => 0, 'size' => filesize($this->image_file)); // Simulate an upload $attachment_class->upload($_FILES); // Remove the filter used to fake uploads remove_filter('upload_dir', array($this, 'filter_upload_dir'), 20, 1); $this->assertSame($attachment_class->original_upload_dir, wp_upload_dir()); // Restore the filter used to fake uploads add_filter('upload_dir', array($this, 'filter_upload_dir'), 20, 1); $this->assertTrue(1 === $attachment_class->upload_dir_filter_args); $cover_image_class = new BP_Attachment_Cover_Image(); // Simulate an upload $cover_image_class->upload($_FILES); // Should be empty $this->assertEmpty($this->original_upload_dir); $this->assertTrue(0 === $cover_image_class->upload_dir_filter_args); $_FILES = $reset_files; $_POST = $reset_post; }
/** * @group upload */ public function test_bp_attachment_upload_no_base_dir_specific_time() { $reset_files = $_FILES; $reset_post = $_POST; $attachment_class = new BPTest_Attachment_Extension(array('action' => 'attachment_action', 'file_input' => 'attachment_file_input')); $_POST['action'] = $attachment_class->action; $_FILES[$attachment_class->file_input] = array('tmp_name' => $this->image_file, 'name' => 'mystery-man.jpg', 'type' => 'image/jpeg', 'error' => 0, 'size' => filesize($this->image_file)); $time = '2015/01'; $upload = $attachment_class->upload($_FILES, '', $time); // If no base_dir was provided, default WordPress uploads dir should be used. $this->assertEquals($upload['file'], $attachment_class->upload_path . '/' . $time . '/mystery-man.jpg'); // clean up! $_FILES = $reset_files; $_POST = $reset_post; }