WordPress.org

Make WordPress Core

Ticket #35073: 35073.diff

File 35073.diff, 1.1 KB (added by realloc, 4 years ago)

WordPress coding standards and unit test for before_last_bar

  • src/wp-includes/l10n.php

     
    118118 */
    119119function before_last_bar( $string ) {
    120120        $last_bar = strrpos( $string, '|' );
    121         if ( false === $last_bar )
     121        if ( false === $last_bar ) {
    122122                return $string;
    123         else
     123        } else {
    124124                return substr( $string, 0, $last_bar );
     125        }
    125126}
    126127
    127128/**
  • tests/phpunit/tests/l10n.php

     
    1616                $this->assertTrue( unload_textdomain( 'wp-tests-domain' ) );
    1717                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
    1818        }
     19
     20        function test_before_last_bar() {
     21                $this->assertEquals( 'no-bar-at-all', before_last_bar( 'no-bar-at-all' ) );
     22                $this->assertEquals( 'before-last-bar', before_last_bar( 'before-last-bar|after-bar' ) );
     23                $this->assertEquals( 'first-before-bar|second-before-bar', before_last_bar( 'first-before-bar|second-before-bar|after-last-bar' ) );
     24        }
     25
    1926}