Make WordPress Core


Ignore:
Timestamp:
02/16/2016 09:14:45 PM (9 years ago)
Author:
ocean90
Message:

i18n: Prevent is_textdomain_loaded() from returning true even if there are no translations for the domain.

In get_translations_for_domain() don't fill the global $l10n with NOOP_Translations instances, return a NOOP_Translations instance instead.

Props nacin, jrf.
Fixes #21319.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n.php

    r35959 r36538  
    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}
Note: See TracChangeset for help on using the changeset viewer.