Make WordPress Core


Ignore:
Timestamp:
09/01/2016 11:59:59 PM (8 years ago)
Author:
pento
Message:

Smilies: Add the smilies filter.

This new filter allows the smilies array to be modified with a filter, instead of having to directly access the global.

Props mte90, jorbin.
Fixes #35905.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/Smilies.php

    r37296 r38504  
    313313        update_option( 'use_smilies', 0 );
    314314    }
     315
     316    /**
     317     * Test to ensure smilies can be removed with a filter
     318     *
     319     * @ticket 35905
     320     */
     321    public function test_smilies_filter_removes_smilies() {
     322        add_filter( 'smilies', array( $this, '_filter_remove_smilies' ) );
     323        smilies_init();
     324        remove_filter( 'smilies', array( $this, '_filter_remove_smilies' ) );
     325
     326        $txt = ':oops: I did it again';
     327
     328        $this->assertEquals( $txt, convert_smilies( $txt ) );
     329    }
     330
     331    /**
     332     * Test to ensure smilies can be added with a filter
     333     *
     334     * @ticket 35905
     335     */
     336    public function test_smilies_filter_adds_smilies() {
     337        add_filter( 'smilies', array( $this, '_filter_add_smilies' ) );
     338        smilies_init();
     339        remove_filter( 'smilies', array( $this, '_filter_add_smilies' ) );
     340
     341        $txt = 'You played with my <3';
     342        $expected_txt = 'You played with my \xe2\x9d\xa4';
     343
     344        $this->assertEquals( $expected_txt, convert_smilies( $txt ) );
     345    }
     346
     347
     348     public function _filter_remove_smilies( $wpsmiliestrans ) {
     349        unset( $wpsmiliestrans[':oops:'] );
     350        return $wpsmiliestrans;
     351     }
     352
     353     public function _filter_add_smilies( $wpsmiliestrans ) {
     354        $wpsmiliestrans['<3'] = '\xe2\x9d\xa4';
     355        return $wpsmiliestrans;
     356     }
    315357}
Note: See TracChangeset for help on using the changeset viewer.