Make WordPress Core


Ignore:
Timestamp:
10/22/2019 05:29:02 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Make sure wp_date() does not unnecessarily escape localized numbers, but keeps localized slashes.

Props Rarst, tmatsuur, remcotolsma, peterwilsoncc.
Reviewed by peterwilsoncc.
Fixes #48319.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/wpDate.php

    r45914 r46569  
    77class Tests_Date_WP_Date extends WP_UnitTestCase {
    88
     9    /** @var WP_Locale */
     10    private $wp_locale_original;
     11
     12    public function setUp() {
     13        global $wp_locale;
     14
     15        parent::setUp();
     16
     17        $this->wp_locale_original = clone $wp_locale;
     18    }
     19
     20    public function tearDown() {
     21        global $wp_locale;
     22
     23        $wp_locale = $this->wp_locale_original;
     24
     25        parent::tearDown();
     26    }
     27
    928    /**
    1029     * @ticket 28636
     
    1332        $this->assertFalse( wp_date( DATE_RFC3339, 'invalid' ) );
    1433    }
     34
     35    /**
     36     * @ticket 48319
     37     */
     38    public function test_should_not_escape_localized_numbers() {
     39        global $wp_locale;
     40
     41        $wp_locale->month = array( 10 => '10月' );
     42
     43        $utc      = new DateTimeZone( 'UTC' );
     44        $datetime = new DateTimeImmutable( '2019-10-17', $utc );
     45
     46        $this->assertEquals( '10月', wp_date( 'F', $datetime->getTimestamp(), $utc ) );
     47    }
     48
     49    /**
     50     * @ticket 48319
     51     */
     52    public function test_should_keep_localized_slashes() {
     53        global $wp_locale;
     54
     55        $string           = 'A \ B';
     56        $wp_locale->month = array( 10 => $string );
     57
     58        $utc      = new DateTimeZone( 'UTC' );
     59        $datetime = new DateTimeImmutable( '2019-10-17', $utc );
     60
     61        $this->assertEquals( $string, wp_date( 'F', $datetime->getTimestamp(), $utc ) );
     62    }
    1563}
Note: See TracChangeset for help on using the changeset viewer.