Font3Test.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Shared;
  3. use PhpOffice\PhpSpreadsheet\Exception as SSException;
  4. use PhpOffice\PhpSpreadsheet\Shared\Font;
  5. use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont;
  6. use PHPUnit\Framework\TestCase;
  7. class Font3Test extends TestCase
  8. {
  9. /** @var string */
  10. private $holdDirectory;
  11. protected function setUp(): void
  12. {
  13. $this->holdDirectory = Font::getTrueTypeFontPath();
  14. }
  15. protected function tearDown(): void
  16. {
  17. Font::setTrueTypeFontPath($this->holdDirectory);
  18. }
  19. public function testGetTrueTypeException1(): void
  20. {
  21. $this->expectException(SSException::class);
  22. $this->expectExceptionMessage('Valid directory to TrueType Font files not specified');
  23. $font = new StyleFont();
  24. $font->setName('unknown');
  25. Font::getTrueTypeFontFileFromFont($font);
  26. }
  27. public function testGetTrueTypeException2(): void
  28. {
  29. Font::setTrueTypeFontPath(__DIR__);
  30. $this->expectException(SSException::class);
  31. $this->expectExceptionMessage('Unknown font name');
  32. $font = new StyleFont();
  33. $font->setName('unknown');
  34. Font::getTrueTypeFontFileFromFont($font);
  35. }
  36. public function testGetTrueTypeException3(): void
  37. {
  38. Font::setTrueTypeFontPath(__DIR__);
  39. $this->expectException(SSException::class);
  40. $this->expectExceptionMessage('TrueType Font file not found');
  41. $font = new StyleFont();
  42. $font->setName('Calibri');
  43. Font::getTrueTypeFontFileFromFont($font);
  44. }
  45. }