/** * @group shrink * @group avatars */ public function test_bp_attachment_avatar_shrink_not_needed() { $shrink = BP_Attachment_Avatar::shrink($this->image_file); $this->assertTrue(empty($shrink)); }
/** * Crop an uploaded avatar. * * $args has the following parameters: * object - What component the avatar is for, e.g. "user" * avatar_dir The absolute path to the avatar * item_id - Item ID * original_file - The absolute path to the original avatar file * crop_w - Crop width * crop_h - Crop height * crop_x - The horizontal starting point of the crop * crop_y - The vertical starting point of the crop * * @param array|string $args { * Array of function parameters. * * @type string $object Object type of the item whose avatar you're * handling. 'user', 'group', 'blog', or custom. * Default: 'user'. * @type string $avatar_dir Subdirectory where avatar should be stored. * Default: 'avatars'. * @type bool|int $item_id ID of the item that the avatar belongs to. * @type bool|string $original_file Absolute path to the original avatar file. * @type int $crop_w Crop width. Default: the global 'full' avatar width, * as retrieved by bp_core_avatar_full_width(). * @type int $crop_h Crop height. Default: the global 'full' avatar height, * as retrieved by bp_core_avatar_full_height(). * @type int $crop_x The horizontal starting point of the crop. Default: 0. * @type int $crop_y The vertical starting point of the crop. Default: 0. * } * * @return bool True on success, false on failure. */ function bp_core_avatar_handle_crop($args = '') { $r = wp_parse_args($args, array('object' => 'user', 'avatar_dir' => 'avatars', 'item_id' => false, 'original_file' => false, 'crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0)); /** * Filters whether or not to handle cropping. * * If you want to override this function, make sure you return false. * * @since 1.2.4 * * @param bool $value Whether or not to crop. * @param array $r Array of parsed arguments for function. */ if (!apply_filters('bp_core_pre_avatar_handle_crop', true, $r)) { return true; } // Crop the file $avatar_attachment = new BP_Attachment_Avatar(); $cropped = $avatar_attachment->crop($r); // Check for errors if (empty($cropped['full']) || empty($cropped['thumb']) || is_wp_error($cropped['full']) || is_wp_error($cropped['thumb'])) { return false; } return true; }
/** * @group upload * @group avatar */ public function test_bp_attachment_avatar_group_upload() { $bp = buddypress(); $reset_files = $_FILES; $reset_post = $_POST; $reset_current_group = $bp->groups->current_group; $g = $this->factory->group->create(); $bp->groups->current_group = groups_get_group(array('group_id' => $g, 'populate_extras' => true)); // Upload the file $avatar_attachment = new BP_Attachment_Avatar(); $_POST['action'] = $avatar_attachment->action; $_FILES[$avatar_attachment->file_input] = array('tmp_name' => $this->image_file, 'name' => 'mystery-man.jpg', 'type' => 'image/jpeg', 'error' => 0, 'size' => filesize($this->image_file)); $group_avatar = $avatar_attachment->upload($_FILES, 'groups_avatar_upload_dir'); $this->assertEquals($group_avatar['file'], $bp->avatar->upload_path . '/group-avatars/' . $g . '/mystery-man.jpg'); // clean up! $this->clean_avatars('group'); $bp->groups->current_group = $reset_current_group; $_FILES = $reset_files; $_POST = $reset_post; }