/**
  * @group bp_docs_unlink_from_group
  */
 function test_bp_docs_remove_group_related_doc_access_settings()
 {
     $group = $this->factory->group->create();
     $doc_id = $this->factory->doc->create(array('group' => $group));
     $settings = bp_docs_get_doc_settings($doc_id);
     // These are doc default settings:
     // $default_settings = array(
     // 	'read'          => 'anyone',
     // 	'edit'          => 'loggedin',
     // 	'read_comments' => 'anyone',
     // 	'post_comments' => 'anyone',
     // 	'view_history'  => 'anyone',
     // 	'manage'        => 'creator',
     // );
     $settings['edit'] = 'group-members';
     $settings['post_comments'] = 'admins-mods';
     update_post_meta($doc_id, 'bp_docs_settings', $settings);
     bp_docs_remove_group_related_doc_access_settings($doc_id);
     $expected_settings = array('read' => 'anyone', 'edit' => 'creator', 'read_comments' => 'anyone', 'post_comments' => 'creator', 'view_history' => 'anyone', 'manage' => 'creator');
     $modified_settings = bp_docs_get_doc_settings($doc_id);
     $this->assertEqualSetsWithIndex($expected_settings, $modified_settings);
 }
/**
 * Process group-doc unlinking requests.
 * Allows group mods & admins to remove docs from groups they moderate.
 *
 * @since 1.9.0
 *
 * @param int $doc_id ID of the doc to remove from the group
 * @param int $group_id ID of the group the doc should be removed from
 * @return bool true if the term is removed
 */
function bp_docs_unlink_from_group($doc_id, $group_id = 0)
{
    if ($group_id) {
        $term = bp_docs_get_group_term($group_id);
    }
    if (empty($doc_id) || empty($term)) {
        return false;
    }
    do_action('bp_docs_before_doc_unlink_from_group', $doc_id, $group_id, $term);
    $removed = wp_remove_object_terms($doc_id, $term, bp_docs_get_associated_item_tax_name());
    // wp_remove_object_terms returns true on success, false or WP_Error on failure.
    $retval = $removed == true ? true : false;
    if ($removed) {
        do_action('bp_docs_doc_unlinked_from_group', $doc_id, $group_id, $term);
    }
    // If the doc is no longer associated with any group, make sure it doesn't become public.
    $assoc_group_id = bp_docs_get_associated_group_id($doc_id);
    if (empty($assoc_group_id)) {
        bp_docs_remove_group_related_doc_access_settings($doc_id);
    }
    // Recalculate the number of docs in the affected group.
    if ($retval) {
        bp_docs_update_doc_count($group_id, 'group');
    }
    return $retval;
}