mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-07 17:27:16 +02:00
Merge pull request #5385 from rubencm/ticket/15043
[ticket/15043] Rewrite get_context()
This commit is contained in:
@@ -146,7 +146,7 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
|
||||
|
||||
foreach (['', 'a', 't', 'f', 'i', 's'] as $sort_key)
|
||||
{
|
||||
$this->assert_search_found('phpbb3+installation', 1, 3, $sort_key);
|
||||
$this->assert_search_found('phpbb3+installation', 1, 4, $sort_key);
|
||||
$this->assert_search_found('foosubject+barsearch', 1, 2, $sort_key);
|
||||
$this->assert_search_found('barsearch-testing', 1, 2, $sort_key); // test hyphen ignored
|
||||
$this->assert_search_found('barsearch+-+testing', 1, 2, $sort_key); // test hyphen wrapped with space ignored
|
||||
|
127
tests/functions_content/get_context_test.php
Normal file
127
tests/functions_content/get_context_test.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class phpbb_functions_content_get_context_test extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for get_context test cases.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function data_get_context(): array
|
||||
{
|
||||
return [
|
||||
'text contains words and length greater than text' => [
|
||||
'text' => 'This is a sample text containing several words, including sample, text, and words.',
|
||||
'words' => ['sample', 'words'],
|
||||
'length' => 100,
|
||||
'expected' => 'This is a sample text containing several words, including sample, text, and words.',
|
||||
],
|
||||
'text contains words and length less than text' => [
|
||||
'text' => 'This is a sample text containing several words, including sample, text, and words.',
|
||||
'words' => ['sample', 'words'],
|
||||
'length' => 50,
|
||||
'expected' => 'This is a sample text containing several words ...',
|
||||
],
|
||||
'text does not contain words' => [
|
||||
'text' => 'This is a sample text containing several words, but none of them match the given words.',
|
||||
'words' => ['nonexistent'],
|
||||
'length' => 50,
|
||||
'expected' => 'This is a sample text containing several words ...',
|
||||
],
|
||||
'desired length equal to text length' => [
|
||||
'text' => 'Exact length text.',
|
||||
'words' => ['Exact', 'text'],
|
||||
'length' => 18,
|
||||
'expected' => 'Exact length text.',
|
||||
],
|
||||
'text with html entities' => [
|
||||
'text' => 'This is a sample text containing & and < and > entities.',
|
||||
'words' => ['sample', 'containing'],
|
||||
'length' => 50,
|
||||
'expected' => 'This is a sample text containing & and < and ...',
|
||||
],
|
||||
'text with html entities and contains last word' => [
|
||||
'text' => 'This is a sample text containing & and < and > entities.',
|
||||
'words' => ['sample', 'entities'],
|
||||
'length' => 50,
|
||||
'expected' => 'This is a sample text ... and < and > entities.',
|
||||
],
|
||||
'text with multiple spaces and special characters' => [
|
||||
'text' => 'This is a sample text containing several words.',
|
||||
'words' => ['sample', 'several'],
|
||||
'length' => 50,
|
||||
'expected' => 'This is a sample text containing several words.',
|
||||
],
|
||||
'empty text' => [
|
||||
'text' => '',
|
||||
'words' => ['sample', 'words'],
|
||||
'length' => 50,
|
||||
'expected' => '',
|
||||
],
|
||||
'empty words array' => [
|
||||
'text' => 'This is a sample text containing several words.',
|
||||
'words' => [],
|
||||
'length' => 50,
|
||||
'expected' => 'This is a sample text containing several words.',
|
||||
],
|
||||
'zero length' => [
|
||||
'text' => 'This is a sample text.',
|
||||
'words' => ['sample'],
|
||||
'length' => 0,
|
||||
'expected' => '...',
|
||||
],
|
||||
'negative length' => [
|
||||
'text' => 'This is a sample text.',
|
||||
'words' => ['sample'],
|
||||
'length' => -10,
|
||||
'expected' => '...',
|
||||
],
|
||||
'ellipses_beginning' => [
|
||||
'text' => 'foo foo foo foo foo foo foo foo bar',
|
||||
'words' => ['bar'],
|
||||
'length' => 10,
|
||||
'expected' => '... foo foo bar',
|
||||
],
|
||||
'ellipsis_end' => [
|
||||
'text' => 'bar foo foo foo foo foo foo foo foo',
|
||||
'words' => ['bar'],
|
||||
'length' => 10,
|
||||
'expected' => 'bar foo foo ...',
|
||||
],
|
||||
'ellipsis_middle' => [
|
||||
'text' => 'foo word1 foo foo foo foo foo foo foo foo foo word2 foo',
|
||||
'words' => ['word1', 'word2'],
|
||||
'length' => 10,
|
||||
'expected' => '... word1 ... word2 ...',
|
||||
],
|
||||
'ellipsis_middle2' => [
|
||||
'text' => 'word1 foo foo foo foo foo foo foo foo foo word2',
|
||||
'words' => ['word1', 'word2'],
|
||||
'length' => 10,
|
||||
'expected' => 'word1 ... word2',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_get_context
|
||||
*/
|
||||
public function test_get_context($text, $words, $length, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, get_context($text, $words, $length));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user