diff --git a/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php b/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php index 1e1b5ecc..f0ce32fb 100644 --- a/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Cell; use PhpOffice\PhpSpreadsheet\Cell\DataType; +use PhpOffice\PhpSpreadsheet\RichText\RichText; use PHPUnit\Framework\TestCase; class DataTypeTest extends TestCase @@ -14,4 +15,47 @@ class DataTypeTest extends TestCase self::assertGreaterThan(0, count($result)); self::assertArrayHasKey('#NULL!', $result); } + + public function testCheckString() + { + $richText = new RichText(); + $result1 = DataType::checkString($richText); + self::assertSame($richText, $result1); + + $stringLimit = 32767; + $randString = $this->randr($stringLimit + 10); + $result2 = DataType::checkString($randString); + self::assertSame($stringLimit, strlen($result2)); + + $dirtyString = "bla bla\r\n bla\r test\n"; + $expected = "bla bla\n bla\n test\n"; + $result3 = DataType::checkString($dirtyString); + self::assertSame($expected, $result3); + } + + /** + * @param int $length + * + * @return string + */ + private function randr($length = 8) + { + $string = ''; + for ($i = 0; $i < $length; ++$i) { + $x = mt_rand(0, 2); + switch ($x) { + case 0: $string .= chr(mt_rand(97, 122)); + + break; + case 1: $string .= chr(mt_rand(65, 90)); + + break; + case 2: $string .= chr(mt_rand(48, 57)); + + break; + } + } + + return $string; + } }