1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-22 20:56:55 +08:00
buddypress/tests/phpunit/testcases/core/template/bpCreateExcerpt.php
Boone B Gorges 7af7bf8df4 The continuing adventures of bp_create_excerpt().
This changeset fixes a bug introduced in [9963] that caused excerpts to be
truncated too much in some cases. It also fixes some potential issues with
multibyte strings when `html=true`.

Fixes #6517.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@9967 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2015-06-25 18:46:16 +00:00

90 lines
2.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @group core
* @group bp_create_excerpt
*/
class BP_Tests_Core_Template_BPCreateExcerpt extends BP_UnitTestCase {
public function test_should_ignore_html_tag_when_html_true() {
$text = 'foo <hr> bar baz';
$expected = 'foo <hr /> bar';
$this->assertSame( $expected, bp_create_excerpt( $text, 8, array(
'ending' => '',
'html' => true,
'exact' => true,
) ) );
}
/**
* @ticket BP3680
*/
public function test_should_ignore_single_word_html_comments_when_html_true() {
$text = 'foo <!--more--> bar baz';
$expected = 'foo <!--more--> bar';
$this->assertSame( $expected, bp_create_excerpt( $text, 8, array(
'ending' => '',
'html' => true,
'exact' => true,
) ) );
}
/**
* @ticket BP3680
*/
public function test_should_ignore_multiple_word_html_comments_when_html_true() {
$text = 'foo <!--one two three--> bar baz';
$expected = 'foo <!--one two three--> bar';
$this->assertSame( $expected, bp_create_excerpt( $text, 8, array(
'ending' => '',
'html' => true,
'exact' => true,
) ) );
}
public function test_should_break_on_prior_word_boundary_when_exact_is_false() {
$text = 'aaaaa aaaaaa';
$expected = 'aaaaa';
$this->assertSame( $expected, bp_create_excerpt( $text, 7, array(
'exact' => false,
'ending' => '',
) ) );
}
/**
* @ticket BP6517
*/
public function test_exact_false_should_properly_account_for_accented_characters() {
$text = 'Toutes les connaissances que les hommes avaient mis sur Internet lui étaient accessible. Les grandes bibliothèques du monde entier navaient plus de secret pour lui. Il pouvait apprendre très vite, beaucoup plus vite que nimporte quel humain.
Il avait appris toutes les connaissances du monde entier, visiter tout les pays. Cest lui qui avait fait en sorte quInternet se déploie ainsi.';
$expected = 'Toutes les connaissances que les hommes avaient mis sur Internet lui étaient accessible. Les';
$this->assertSame( $expected, bp_create_excerpt( $text, 98, array(
'ending' => '',
'exact' => false,
) ) );
}
/**
* @ticket BP6254
*/
public function test_should_trim_too_long_first_word_to_max_characters_even_when_exact_is_false() {
$text = 'aaaaaaaaaaa';
$expected = 'aaa';
$this->assertSame( $expected, bp_create_excerpt( $text, 3, array(
'exact' => false,
'ending' => '',
) ) );
}
/**
* @ticket BP6517
*/
public function test_string_should_not_be_cut_mid_tag_when_exact_is_false() {
$text = '<p><span>Foo</span> <a href="http://example.com">Bar</a> Baz.</p><p>Foo Bar Baz</p>';
$actual = bp_create_excerpt( $text, 7, array(
'html' => true,
'ending' => '',
'exact' => false,
) );
$this->assertSame( '<p><span>Foo</span> <a href="http://example.com">Bar</a></p>', $actual );
}
}