Make WordPress Core

Ticket #41551: 41551.diff

File 41551.diff, 1.6 KB (added by bobbingwide, 8 years ago)

PHPUnit tests for translation using a $domain parameter value of null

  • new file tests/phpunit/tests/l10n/loadTextdomainNull.php

    diff --git a/tests/phpunit/tests/l10n/loadTextdomainNull.php b/tests/phpunit/tests/l10n/loadTextdomainNull.php
    new file mode 100644
    index 0000000..3a448fb
    - +  
     1<?php
     2
     3/**
     4 * @group l10n
     5 * @group i18n
     6 */
     7class Tests_L10n_loadTextdomainNull extends WP_UnitTestCase {
     8
     9        public function filter_set_locale_to_german() {
     10                return 'de_DE';
     11        }
     12
     13        /**
     14         * @ticket xxxxx
     15         *
     16         * Demonstrates that we can pass a null for the text domain parameter.
     17         */
     18        public function test_translate_null_domain() {
     19                $translated = __( "None", null );
     20                $this->assertEquals( "None", $translated );
     21        }
     22       
     23        /**
     24         * Demonstrates that we can load, translate and unload using the null text domain
     25         * 
     26         * @ticket xxxxx
     27         */
     28        public function test_translate_null_domain_loaded() {
     29                add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     30                $loaded = load_textdomain( null, DIR_TESTDATA . "/languages/plugins/internationalized-plugin-de_DE.mo" );
     31                $is_textdomain_loaded = is_textdomain_loaded( null );
     32                $this->assertTrue( $is_textdomain_loaded );
     33                $actual_output = __( 'This is a dummy plugin', null );
     34                $this->assertEquals( $actual_output, 'Das ist ein Dummy Plugin');
     35                unload_textdomain( null );
     36                $is_textdomain_loaded = is_textdomain_loaded( null );
     37                $this->assertFalse( $is_textdomain_loaded );
     38                $actual_output = __( 'This is a dummy plugin', null );
     39                $this->assertEquals( $actual_output, 'This is a dummy plugin');
     40                remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     41
     42        }
     43
     44}