Tests: move utf8CharBoundary test to own file (#2389)
* Tests/reorganize: move utf8CharBoundary test to own file * Utf8CharBoundaryTest: reorganize to use data providers This: * Renames the test method and moves the description to the docblock. * Decouples the test from the PHPMailer `TestCase` as it doesn't need the complete `set_up()` and `tear_down()`. * Moves the test cases to a data provider. * Adds a `@covers` tag. * Utf8CharBoundaryTest: add `@todo` reminder This really could do with some more test cases to properly cover all paths and branching in the method. Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
This commit is contained in:
parent
6477e1a6d7
commit
a55b8b68af
|
|
@ -1744,15 +1744,4 @@ EOT;
|
|||
$this->assertSame($expectedqp, $this->Mail->wrapText($message, 50, true));
|
||||
$this->assertSame($expected, $this->Mail->wrapText($message, 50, false));
|
||||
}
|
||||
|
||||
public function testEncodedText_utf8CharBoundary_returnsCorrectMaxLength()
|
||||
{
|
||||
$encodedWordWithMultiByteCharFirstByte = 'H=E4tten';
|
||||
$encodedSingleByteCharacter = '=0C';
|
||||
$encodedWordWithMultiByteCharMiddletByte = 'L=C3=B6rem';
|
||||
|
||||
$this->assertSame(1, $this->Mail->utf8CharBoundary($encodedWordWithMultiByteCharFirstByte, 3));
|
||||
$this->assertSame(3, $this->Mail->utf8CharBoundary($encodedSingleByteCharacter, 3));
|
||||
$this->assertSame(1, $this->Mail->utf8CharBoundary($encodedWordWithMultiByteCharMiddletByte, 6));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPMailer - PHP email transport unit tests.
|
||||
* PHP version 5.5.
|
||||
*
|
||||
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
||||
* @author Andy Prevost
|
||||
* @copyright 2012 - 2020 Marcus Bointon
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
namespace PHPMailer\Test\PHPMailer;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
|
||||
|
||||
/**
|
||||
* Test UTF8 character boundary functionality.
|
||||
*
|
||||
* @covers \PHPMailer\PHPMailer\PHPMailer::utf8CharBoundary
|
||||
*
|
||||
* @todo Add more testcases to properly cover all paths in the method!
|
||||
*/
|
||||
final class Utf8CharBoundaryTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Verify that the utf8CharBoundary() returns the correct last character boundary for encoded text.
|
||||
*
|
||||
* @dataProvider dataUtf8CharBoundary
|
||||
*
|
||||
* @param string $encodedText UTF-8 QP text to use as input string.
|
||||
* @param int $maxLength Max length to pass to the function.
|
||||
* @param int $expected Expected function output.
|
||||
*/
|
||||
public function testUtf8CharBoundary($encodedText, $maxLength, $expected)
|
||||
{
|
||||
$mail = new PHPMailer();
|
||||
$this->assertSame($expected, $mail->utf8CharBoundary($encodedText, $maxLength));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataUtf8CharBoundary()
|
||||
{
|
||||
return [
|
||||
'Encoded word with multibyte char first byte' => [
|
||||
'encodedText' => 'H=E4tten',
|
||||
'maxLength' => 3,
|
||||
'expected' => 1,
|
||||
],
|
||||
'Encoded single byte char' => [
|
||||
'encodedText' => '=0C',
|
||||
'maxLength' => 3,
|
||||
'expected' => 3,
|
||||
],
|
||||
'Encoded word with multi byte char middle byte' => [
|
||||
'encodedText' => 'L=C3=B6rem',
|
||||
'maxLength' => 6,
|
||||
'expected' => 1,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue