WordPress.org

Make WordPress Core

Ticket #21319: 21319.2.diff

File 21319.2.diff, 1.8 KB (added by ocean90, 6 years ago)
  • src/wp-includes/l10n.php

     
    793793 */
    794794function get_translations_for_domain( $domain ) {
    795795        global $l10n;
    796         if ( !isset( $l10n[$domain] ) ) {
    797                 $l10n[$domain] = new NOOP_Translations;
     796        if ( isset( $l10n[ $domain ] ) ) {
     797                return $l10n[ $domain ];
    798798        }
    799         return $l10n[$domain];
     799
     800        static $noop_translations = null;
     801        if ( ! $noop_translations ) {
     802                $noop_translations = new NOOP_Translations;
     803        }
     804
     805        return $noop_translations;
    800806}
    801807
    802808/**
  • tests/phpunit/tests/l10n.php

     
    2626                $this->assertEquals( 'first-before-bar|second-before-bar', before_last_bar( 'first-before-bar|second-before-bar|after-last-bar' ) );
    2727        }
    2828
     29        /**
     30         * @ticket 21319
     31         */
     32        function test_is_textdomain_loaded_for_no_translations() {
     33                $this->assertFalse( load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/non-existent-file' ) );
     34                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
     35                $this->assertInstanceOf( 'NOOP_Translations', get_translations_for_domain( 'wp-tests-domain' ) );
     36                // Ensure that we don't confuse NOOP_Translations to be a loaded text domain.
     37                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
     38                $this->assertFalse( unload_textdomain( 'wp-tests-domain' ) );
     39        }
     40
     41        /**
     42         * @ticket 21319
     43         */
     44        function test_is_textdomain_is_not_loaded_after_gettext_call_with_no_translations() {
     45                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
     46                __( 'just some string', 'wp-tests-domain' );
     47                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
     48        }
    2949}