TitleTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Chart;
  3. use PhpOffice\PhpSpreadsheet\Chart\Title;
  4. use PhpOffice\PhpSpreadsheet\RichText\RichText;
  5. use PHPUnit\Framework\TestCase;
  6. class TitleTest extends TestCase
  7. {
  8. public function testString(): void
  9. {
  10. $title = new Title('hello');
  11. self::assertSame('hello', $title->getCaption());
  12. self::assertSame('hello', $title->getCaptionText());
  13. }
  14. public function testStringArray(): void
  15. {
  16. $title = new Title();
  17. $title->setCaption(['Hello', ', ', 'world.']);
  18. self::assertSame('Hello, world.', $title->getCaptionText());
  19. }
  20. public function testRichText(): void
  21. {
  22. $title = new Title();
  23. $richText = new RichText();
  24. $part = $richText->createTextRun('Hello');
  25. $font = $part->getFont();
  26. if ($font === null) {
  27. self::fail('Unable to retrieve font');
  28. } else {
  29. $font->setBold(true);
  30. $title->setCaption($richText);
  31. self::assertSame('Hello', $title->getCaptionText());
  32. }
  33. }
  34. public function testMixedArray(): void
  35. {
  36. $title = new Title();
  37. $richText1 = new RichText();
  38. $part1 = $richText1->createTextRun('Hello');
  39. $font1 = $part1->getFont();
  40. $richText2 = new RichText();
  41. $part2 = $richText2->createTextRun('world');
  42. $font2 = $part2->getFont();
  43. if ($font1 === null || $font2 === null) {
  44. self::fail('Unable to retrieve font');
  45. } else {
  46. $font1->setBold(true);
  47. $font2->setItalic(true);
  48. $title->setCaption([$richText1, ', ', $richText2, '.']);
  49. self::assertSame('Hello, world.', $title->getCaptionText());
  50. }
  51. }
  52. }