WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/20/2016 09:43:51 PM (5 years ago)
Author:
ocean90
Message:

i18n-tools: Respect the coding standards when adding textdomains with add-textdomain.php.

Props GaryJ, groovecoder.
Fixes #21616.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/i18n/t/AddTextdomainTest.php

    r36389 r36603  
    1111class AddTextDomainTest extends PHPUnit_Framework_TestCase {
    1212
    13     function __construct() {
    14         $this->atd = new AddTextdomain;
     13    function setUp() {
     14        parent::setUp();
     15        $this->atd = new AddTextdomain();
    1516    }
    1617
    1718    function test_add() {
    18         # copy to a new file, so that we don't corrupt the old one
     19        // Copy to a new file, so that we don't corrupt the old one.
    1920        copy( 'data/add-textdomain-0.php', 'data/add-textdomain-0-work.php' );
    2021        $this->atd->process_file( 'test-domain', 'data/add-textdomain-0-work.php', true );
     
    2223        unlink( 'data/add-textdomain-0-work.php' );
    2324    }
     25
     26    /**
     27     * @dataProvider data_textdomain_sources
     28     */
     29    function test_basic_add_textdomain( $source, $expected ) {
     30        $tokens = token_get_all( $source );
     31        $result = $this->atd->process_tokens( 'foo', $tokens );
     32        $this->assertEquals( $expected, $result );
     33    }
     34
     35    function data_textdomain_sources() {
     36        return array(
     37            array( "<?php __('string'); ?>", "<?php __('string', 'foo'); ?>" ), // Simple single quotes
     38            array( '<?php __("string"); ?>', "<?php __(\"string\", 'foo'); ?>" ), // Simple double quotes
     39            array( "<?php __( 'string' ); ?>", "<?php __( 'string', 'foo' ); ?>" ), // Simple single quotes CS
     40            array( '<?php __( "string" ); ?>', "<?php __( \"string\", 'foo' ); ?>" ), // Simple double quotes CS
     41            array( "<?php __( 'string', 'string2' ); ?>", "<?php __( 'string', 'string2', 'foo' ); ?>" ), // Multiple string args
     42            array( '<?php __( \'string\', $var ); ?>', '<?php __( \'string\', $var, \'foo\' ); ?>' ), // Multiple string / var args
     43            array( "<?php __( 'string', 'foo' ); ?>", "<?php __( 'string', 'foo' ); ?>" ), // Existing textdomain
     44        );
     45    }
    2446}
Note: See TracChangeset for help on using the changeset viewer.