assertEquals( $trimmed, wp_trim_words( $this->long_text ) ); } function test_trims_to_10() { $trimmed = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius…'; $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 10 ) ); } function test_trims_to_5_and_uses_custom_more() { $trimmed = 'Lorem ipsum dolor sit amet,[...] Read on!'; $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 5, '[...] Read on!' ) ); } function test_strips_tags_before_trimming() { $text = 'This text contains a link to WordPress.org!'; $trimmed = 'This text contains a link…'; $this->assertEquals( $trimmed, wp_trim_words( $text, 5 ) ); } // #18726 function test_strips_script_and_style_content() { $trimmed = 'This text contains. It should go.'; $text = 'This text contains. It should go.'; $this->assertEquals( $trimmed, wp_trim_words( $text ) ); $text = 'This text contains. It should go.'; $this->assertEquals( $trimmed, wp_trim_words( $text ) ); } function test_doesnt_trim_short_text() { $text = 'This is some short text.'; $this->assertEquals( $text, wp_trim_words( $text ) ); } /** * @ticket 44541 */ function test_trims_to_20_counted_by_chars() { switch_to_locale( 'ja_JP' ); $expected = substr( $this->long_text, 0, 20 ) . '…'; $actual = wp_trim_words( $this->long_text, 20 ); restore_previous_locale(); $this->assertEquals( $expected, $actual ); } /** * @ticket 44541 */ function test_trims_to_20_counted_by_chars_with_double_width_chars() { switch_to_locale( 'ja_JP' ); $text = str_repeat( 'あ', 100 ); $expected = str_repeat( 'あ', 19 ) . '…'; $actual = wp_trim_words( $text, 19 ); restore_previous_locale(); $this->assertEquals( $expected, $actual ); } }