1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
<?php
namespace Illuminate\Tests\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
use Illuminate\Http\Request;
use PHPUnit\Framework\TestCase;
class TrimStringsTest extends TestCase
{
/**
* Test no zero-width space character returns the same string.
*/
public function test_no_zero_width_space_character_returns_the_same_string()
{
$request = new Request;
$request->merge([
'title' => 'This title does not contain any zero-width space',
]);
$middleware = new TrimStrings;
$middleware->handle($request, function ($req) {
$this->assertEquals('This title does not contain any zero-width space', $req->title);
});
}
/**
* Test leading zero-width space character is trimmed [ZWSP].
*/
public function test_leading_zero_width_space_character_is_trimmed()
{
$request = new Request;
$request->merge([
'title' => 'This title contains a zero-width space at the beginning',
]);
$middleware = new TrimStrings;
$middleware->handle($request, function ($req) {
$this->assertEquals('This title contains a zero-width space at the beginning', $req->title);
});
}
/**
* Test trailing zero-width space character is trimmed [ZWSP].
*/
public function test_trailing_zero_width_space_character_is_trimmed()
{
$request = new Request;
$request->merge([
'title' => 'This title contains a zero-width space at the end',
]);
$middleware = new TrimStrings;
$middleware->handle($request, function ($req) {
$this->assertEquals('This title contains a zero-width space at the end', $req->title);
});
}
/**
* Test leading zero-width non-breakable space character is trimmed [ZWNBSP].
*/
public function test_leading_zero_width_non_breakable_space_character_is_trimmed()
{
$request = new Request;
$request->merge([
'title' => 'This title contains a zero-width non-breakable space at the beginning',
]);
$middleware = new TrimStrings;
$middleware->handle($request, function ($req) {
$this->assertEquals('This title contains a zero-width non-breakable space at the beginning', $req->title);
});
}
/**
* Test leading multiple zero-width non-breakable space characters are trimmed [ZWNBSP].
*/
public function test_leading_multiple_zero_width_non_breakable_space_characters_are_trimmed()
{
$request = new Request;
$request->merge([
'title' => 'This title contains a zero-width non-breakable space at the beginning',
]);
$middleware = new TrimStrings;
$middleware->handle($request, function ($req) {
$this->assertEquals('This title contains a zero-width non-breakable space at the beginning', $req->title);
});
}
/**
* Test a combination of leading and trailing zero-width non-breakable space and zero-width space characters are trimmed [ZWNBSP], [ZWSP].
*/
public function test_combination_of_leading_and_trailing_zero_width_non_breakable_space_and_zero_width_space_characters_are_trimmed()
{
$request = new Request;
$request->merge([
'title' => 'This title contains a combination of zero-width non-breakable space and zero-width spaces characters at the beginning and the end',
]);
$middleware = new TrimStrings;
$middleware->handle($request, function ($req) {
$this->assertEquals('This title contains a combination of zero-width non-breakable space and zero-width spaces characters at the beginning and the end', $req->title);
});
}
}
|