/** * @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 crop */ public function test_bp_attachment_crop() { $crop_args = array('original_file' => $this->image_file, 'crop_x' => 0, 'crop_y' => 0, 'crop_w' => 150, 'crop_h' => 150, 'dst_w' => 150, 'dst_h' => 150); $attachment_class = new BPTest_Attachment_Extension(array('action' => 'attachment_action', 'file_input' => 'attachment_file_input', 'base_dir' => 'attachment_base_dir')); $cropped = $attachment_class->crop($crop_args); // Image must come from the upload basedir $this->assertTrue(is_wp_error($cropped)); $crop_args['original_file'] = $attachment_class->upload_path . '/mystery-man.jpg'; // Image must stay in the upload basedir $crop_args['dst_file'] = BP_TESTS_DIR . 'assets/error.jpg'; $cropped = $attachment_class->crop($crop_args); // Image must stay in the upload basedir $this->assertTrue(is_wp_error($cropped)); // clean up! $this->clean_files(); }