Skip to:
Content

BuddyPress.org

Ticket #6936: 6936.diff

File 6936.diff, 4.9 KB (added by boonebgorges, 8 years ago)
  • src/bp-core/admin/bp-core-admin-schema.php

    diff --git src/bp-core/admin/bp-core-admin-schema.php src/bp-core/admin/bp-core-admin-schema.php
    index 523a4db..f916b2d 100644
    function bp_core_install_emails() { 
    538538                'post_type'   => bp_get_email_post_type(),
    539539        );
    540540
    541         $emails = array(
     541        $emails       = bp_core_email_schema();
     542        $descriptions = bp_core_email_type_schema();
     543
     544        // Add these emails to the database.
     545        foreach ( $emails as $id => $email ) {
     546                $post_id = wp_insert_post( bp_parse_args( $email, $defaults, 'install_email_' . $id ) );
     547                if ( ! $post_id ) {
     548                        continue;
     549                }
     550
     551                $tt_ids = wp_set_object_terms( $post_id, $id, bp_get_email_tax_type() );
     552                foreach ( $tt_ids as $tt_id ) {
     553                        $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
     554                        wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
     555                                'description' => $descriptions[ $id ],
     556                        ) );
     557                }
     558        }
     559
     560        /**
     561         * Fires after BuddyPress adds the posts for its emails.
     562         *
     563         * @since 2.5.0
     564         */
     565        do_action( 'bp_core_install_emails' );
     566}
     567
     568/**
     569 * Get a list of emails for populating the email post type.
     570 *
     571 * @since 2.5.1
     572 *
     573 * @return array
     574 */
     575function bp_core_email_schema() {
     576        return array(
    542577                'activity-comment' => array(
    543578                        /* translators: do not remove {} brackets or translate its contents. */
    544579                        'post_title'   => __( '[{{{site.name}}}] {{poster.name}} replied to one of your updates', 'buddypress' ),
    function bp_core_install_emails() { 
    668703                        'post_excerpt' => __( "Your membership request for the group "{{group.name}}" has been rejected.\n\nTo request membership again, visit: {{{group.url}}}", 'buddypress' ),
    669704                ),
    670705        );
     706}
    671707
    672         $descriptions = array(
     708/**
     709 * Get a list of emails for populating email type taxonomy terms.
     710 *
     711 * @since 2.5.1
     712 *
     713 * @return array
     714 */
     715function bp_core_email_type_schema() {
     716        return array(
    673717                'activity-comment'                   => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
    674718                'activity-comment-author'            => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
    675719                'activity-at-message'                => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
    function bp_core_install_emails() { 
    687731                'groups-membership-request-accepted' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
    688732                'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
    689733        );
    690 
    691         // Add these emails to the database.
    692         foreach ( $emails as $id => $email ) {
    693                 $post_id = wp_insert_post( bp_parse_args( $email, $defaults, 'install_email_' . $id ) );
    694                 if ( ! $post_id ) {
    695                         continue;
    696                 }
    697 
    698                 $term_ids = wp_set_post_terms( $post_id, $id, bp_get_email_tax_type() );
    699                 foreach ( $term_ids as $term_id ) {
    700                         wp_update_term( (int) $term_id, bp_get_email_tax_type(), array(
    701                                 'description' => $descriptions[ $id ],
    702                         ) );
    703                 }
    704         }
    705 
    706         /**
    707          * Fires after BuddyPress adds the posts for its emails.
    708          *
    709          * @since 2.5.0
    710          */
    711         do_action( 'bp_core_install_emails' );
    712734}
  • tests/phpunit/testcases/admin/functions.php

    diff --git tests/phpunit/testcases/admin/functions.php tests/phpunit/testcases/admin/functions.php
    index 75e12b9..af3c5d4 100644
    class BP_Tests_Admin_Functions extends BP_UnitTestCase { 
    218218                $bp->pages = $reset_bp_pages;
    219219                $bp->admin->notices = $reset_admin_notices;
    220220        }
     221
     222        /**
     223         * @ticket BP6936
     224         */
     225        public function test_email_type_descriptions_should_match_when_split_terms_exist() {
     226                global $wpdb;
     227
     228                // Delete all existing email types and descriptions.
     229                $emails = get_posts( array(
     230                        'fields' => 'ids',
     231                        'post_type' => bp_get_email_post_type(),
     232                ) );
     233                foreach ( $emails as $email ) {
     234                        wp_delete_post( $email, true );
     235                }
     236
     237                $descriptions = get_terms( bp_get_email_tax_type(), array(
     238                        'fields' => 'ids',
     239                        'hide_empty' => false,
     240                ) );
     241                foreach ( $descriptions as $description ) {
     242                        wp_delete_term( (int) $description, bp_get_email_tax_type() );
     243                }
     244
     245                // Fake the existence of split terms by offsetting the term_taxonomy table.
     246                $wpdb->insert( $wpdb->term_taxonomy, array( 'term_id' => 9999, 'taxonomy' => 'post_tag', 'description' => 'foo description', 'parent' => 0, 'count' => 0 ) );
     247
     248                require_once( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin-schema.php' );
     249                bp_core_install_emails();
     250
     251                $d_terms = get_terms( bp_get_email_tax_type(), array(
     252                        'hide_empty' => false,
     253                ) );
     254
     255                $correct_descriptions = bp_core_email_type_schema();
     256                foreach ( $d_terms as $d_term ) {
     257                        $correct_description = $correct_descriptions[ $d_term->slug ];
     258                        $this->assertSame( $correct_description, $d_term->description );
     259                }
     260        }
    221261}