TextStyleTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * This file is part of PHPPresentation - A pure PHP library for reading and writing
  4. * presentations documents.
  5. *
  6. * PHPPresentation is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
  12. *
  13. * @copyright 2009-2015 PHPPresentation contributors
  14. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  15. * @link https://github.com/PHPOffice/PHPPresentation
  16. */
  17. namespace PhpOffice\PhpPresentation\Tests\Style;
  18. use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
  19. use PhpOffice\PhpPresentation\Style\Alignment;
  20. use PhpOffice\PhpPresentation\Style\TextStyle;
  21. class TextStyleTest extends \PHPUnit_Framework_TestCase
  22. {
  23. public function testConstructDefaultTrue()
  24. {
  25. /**
  26. * @var \PhpOffice\PhpPresentation\Shape\RichText\Paragraph $oParagraph
  27. */
  28. $object = new TextStyle();
  29. $arrayBodyStyle = $object->getBodyStyle();
  30. $this->assertInternalType('array', $arrayBodyStyle);
  31. $this->assertCount(1, $arrayBodyStyle);
  32. $this->assertArrayHasKey(1, $arrayBodyStyle);
  33. $this->assertNull($object->getBodyStyleAtLvl(0));
  34. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $object->getBodyStyleAtLvl(1));
  35. $oParagraph = $object->getBodyStyleAtLvl(1);
  36. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $oParagraph);
  37. $this->assertEquals(Alignment::HORIZONTAL_CENTER, $oParagraph->getAlignment()->getHorizontal());
  38. $this->assertEquals((-324900 / 9525), $oParagraph->getAlignment()->getIndent());
  39. $this->assertEquals(0, $oParagraph->getAlignment()->getMarginLeft());
  40. $this->assertEquals(32, $oParagraph->getFont()->getSize());
  41. $this->assertInstanceOf('PhpOffice\PhpPresentation\Style\SchemeColor', $oParagraph->getFont()->getColor());
  42. $this->assertEquals('tx1', $oParagraph->getFont()->getColor()->getValue());
  43. $arrayOtherStyle = $object->getOtherStyle();
  44. $this->assertInternalType('array', $arrayOtherStyle);
  45. $this->assertCount(1, $arrayOtherStyle);
  46. $this->assertArrayHasKey(0, $arrayOtherStyle);
  47. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $object->getOtherStyleAtLvl(0));
  48. $this->assertNull($object->getOtherStyleAtLvl(1));
  49. $oParagraph = $object->getOtherStyleAtLvl(0);
  50. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $oParagraph);
  51. $this->assertEquals(Alignment::HORIZONTAL_CENTER, $oParagraph->getAlignment()->getHorizontal());
  52. $this->assertEquals(10, $oParagraph->getFont()->getSize());
  53. $this->assertInstanceOf('PhpOffice\PhpPresentation\Style\SchemeColor', $oParagraph->getFont()->getColor());
  54. $this->assertEquals('tx1', $oParagraph->getFont()->getColor()->getValue());
  55. $arrayTitleStyle = $object->getTitleStyle();
  56. $this->assertInternalType('array', $arrayTitleStyle);
  57. $this->assertCount(1, $arrayTitleStyle);
  58. $this->assertArrayHasKey(1, $arrayTitleStyle);
  59. $this->assertNull($object->getTitleStyleAtLvl(0));
  60. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $object->getTitleStyleAtLvl(1));
  61. $oParagraph = $object->getTitleStyleAtLvl(1);
  62. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $oParagraph);
  63. $this->assertEquals(Alignment::HORIZONTAL_CENTER, $oParagraph->getAlignment()->getHorizontal());
  64. $this->assertEquals(44, $oParagraph->getFont()->getSize());
  65. $this->assertInstanceOf('PhpOffice\PhpPresentation\Style\SchemeColor', $oParagraph->getFont()->getColor());
  66. $this->assertEquals('lt1', $oParagraph->getFont()->getColor()->getValue());
  67. }
  68. public function testConstructDefaultFalse()
  69. {
  70. $object = new TextStyle(false);
  71. $this->assertInternalType('array', $object->getBodyStyle());
  72. $this->assertCount(0, $object->getBodyStyle());
  73. $this->assertInternalType('array', $object->getOtherStyle());
  74. $this->assertCount(0, $object->getOtherStyle());
  75. $this->assertInternalType('array', $object->getTitleStyle());
  76. $this->assertCount(0, $object->getTitleStyle());
  77. }
  78. public function testLevel()
  79. {
  80. $value = rand(0, 9);
  81. $object = new TextStyle(false);
  82. $oParagraph = new Paragraph();
  83. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setBodyStyleAtLvl($oParagraph, ''));
  84. $this->assertNull($object->getBodyStyleAtLvl(''));
  85. $this->assertCount(0, $object->getBodyStyle());
  86. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setBodyStyleAtLvl($oParagraph, 10));
  87. $this->assertNull($object->getBodyStyleAtLvl(10));
  88. $this->assertCount(0, $object->getBodyStyle());
  89. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setBodyStyleAtLvl($oParagraph, $value));
  90. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $object->getBodyStyleAtLvl($value));
  91. $this->assertCount(1, $object->getBodyStyle());
  92. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setOtherStyleAtLvl($oParagraph, ''));
  93. $this->assertNull($object->getOtherStyleAtLvl(''));
  94. $this->assertCount(0, $object->getOtherStyle());
  95. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setOtherStyleAtLvl($oParagraph, 10));
  96. $this->assertNull($object->getOtherStyleAtLvl(10));
  97. $this->assertCount(0, $object->getOtherStyle());
  98. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setOtherStyleAtLvl($oParagraph, $value));
  99. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $object->getOtherStyleAtLvl($value));
  100. $this->assertCount(1, $object->getOtherStyle());
  101. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setTitleStyleAtLvl($oParagraph, ''));
  102. $this->assertNull($object->getTitleStyleAtLvl(''));
  103. $this->assertCount(0, $object->getTitleStyle());
  104. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setTitleStyleAtLvl($oParagraph, 10));
  105. $this->assertNull($object->getTitleStyleAtLvl(10));
  106. $this->assertCount(0, $object->getTitleStyle());
  107. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->setTitleStyleAtLvl($oParagraph, $value));
  108. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\RichText\Paragraph', $object->getTitleStyleAtLvl($value));
  109. $this->assertCount(1, $object->getTitleStyle());
  110. }
  111. }