Add PhpOffice\PhpSpreadsheet\Cell\DataType::checkString unit test
This commit is contained in:
parent
f2bba73510
commit
73c79a90a8
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||||
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DataTypeTest extends TestCase
|
class DataTypeTest extends TestCase
|
||||||
|
@ -14,4 +15,47 @@ class DataTypeTest extends TestCase
|
||||||
self::assertGreaterThan(0, count($result));
|
self::assertGreaterThan(0, count($result));
|
||||||
self::assertArrayHasKey('#NULL!', $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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue