AbstractShapeTest.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 2010-2014 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;
  18. use PhpOffice\PhpPresentation\Shape\Placeholder;
  19. use PhpOffice\PhpPresentation\Slide;
  20. use PhpOffice\PhpPresentation\Shape\Hyperlink;
  21. use PhpOffice\PhpPresentation\Shape\RichText;
  22. use PhpOffice\PhpPresentation\Style\Border;
  23. use PhpOffice\PhpPresentation\Style\Fill;
  24. use PhpOffice\PhpPresentation\Style\Shadow;
  25. /**
  26. * Test class for Autoloader
  27. */
  28. class AbstractShapeTest extends \PHPUnit_Framework_TestCase
  29. {
  30. /**
  31. * Register
  32. */
  33. public function testConstruct()
  34. {
  35. $object = new RichText();
  36. $this->assertEquals(0, $object->getOffsetX());
  37. $this->assertEquals(0, $object->getOffsetY());
  38. $this->assertEquals(0, $object->getHeight());
  39. $this->assertEquals(0, $object->getRotation());
  40. $this->assertEquals(0, $object->getWidth());
  41. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Border', $object->getBorder());
  42. $this->assertEquals(Border::LINE_NONE, $object->getBorder()->getLineStyle());
  43. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  44. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->getShadow());
  45. }
  46. public function testFill()
  47. {
  48. $object = new RichText();
  49. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setFill());
  50. $this->assertNull($object->getFill());
  51. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setFill(new Fill()));
  52. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  53. }
  54. public function testHeight()
  55. {
  56. $object = new RichText();
  57. $value = rand(1, 100);
  58. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHeight());
  59. $this->assertEquals(0, $object->getHeight());
  60. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHeight($value));
  61. $this->assertEquals($value, $object->getHeight());
  62. }
  63. public function testHyperlink()
  64. {
  65. $object = new RichText();
  66. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHyperlink());
  67. $this->assertFalse($object->hasHyperlink());
  68. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink());
  69. $this->assertTrue($object->hasHyperlink());
  70. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHyperlink(new Hyperlink('http://www.google.fr')));
  71. $this->assertTrue($object->hasHyperlink());
  72. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink());
  73. $this->assertTrue($object->hasHyperlink());
  74. }
  75. public function testOffsetX()
  76. {
  77. $object = new RichText();
  78. $value = rand(1, 100);
  79. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetX());
  80. $this->assertEquals(0, $object->getOffsetX());
  81. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetX($value));
  82. $this->assertEquals($value, $object->getOffsetX());
  83. }
  84. public function testOffsetY()
  85. {
  86. $object = new RichText();
  87. $value = rand(1, 100);
  88. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetY());
  89. $this->assertEquals(0, $object->getOffsetY());
  90. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetY($value));
  91. $this->assertEquals($value, $object->getOffsetY());
  92. }
  93. public function testRotation()
  94. {
  95. $object = new RichText();
  96. $value = rand(1, 100);
  97. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setRotation());
  98. $this->assertEquals(0, $object->getRotation());
  99. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setRotation($value));
  100. $this->assertEquals($value, $object->getRotation());
  101. }
  102. public function testShadow()
  103. {
  104. $object = new RichText();
  105. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setShadow());
  106. $this->assertNull($object->getShadow());
  107. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setShadow(new Shadow()));
  108. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->getShadow());
  109. }
  110. public function testWidth()
  111. {
  112. $object = new RichText();
  113. $value = rand(1, 100);
  114. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidth());
  115. $this->assertEquals(0, $object->getWidth());
  116. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidth($value));
  117. $this->assertEquals($value, $object->getWidth());
  118. }
  119. public function testWidthAndHeight()
  120. {
  121. $object = new RichText();
  122. $value = rand(1, 100);
  123. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidthAndHeight());
  124. $this->assertEquals(0, $object->getWidth());
  125. $this->assertEquals(0, $object->getHeight());
  126. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidthAndHeight($value));
  127. $this->assertEquals($value, $object->getWidth());
  128. $this->assertEquals(0, $object->getHeight());
  129. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidthAndHeight($value, $value));
  130. $this->assertEquals($value, $object->getWidth());
  131. $this->assertEquals($value, $object->getHeight());
  132. }
  133. public function testPlaceholder()
  134. {
  135. $object = new RichText();
  136. $this->assertFalse($object->isPlaceholder(), 'Standard Shape should not be a placeholder object');
  137. $this->assertNull($object->getPlaceholder());
  138. $this->assertInstanceOf(
  139. 'PhpOffice\\PhpPresentation\\AbstractShape',
  140. $object->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_TITLE))
  141. );
  142. $this->assertTrue($object->isPlaceholder());
  143. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Placeholder', $object->getPlaceholder());
  144. $this->assertEquals('title', $object->getPlaceholder()->getType());
  145. $object = new RichText();
  146. $this->assertFalse($object->isPlaceholder(), 'Standard Shape should not be a placeholder object');
  147. $placeholder = new Placeholder(Placeholder::PH_TYPE_TITLE);
  148. $placeholder->setType(Placeholder::PH_TYPE_SUBTITLE);
  149. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setPlaceHolder($placeholder));
  150. $this->assertTrue($object->isPlaceholder());
  151. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Placeholder', $object->getPlaceholder());
  152. $this->assertEquals('subTitle', $object->getPlaceholder()->getType());
  153. }
  154. public function testContainer()
  155. {
  156. $object = new RichText();
  157. $object2 = new RichText();
  158. $object2->setWrap(RichText::WRAP_NONE);
  159. $oSlide = new Slide();
  160. $oSlide->addShape($object2);
  161. $this->assertNull($object->getContainer());
  162. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer($oSlide));
  163. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->getContainer());
  164. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer(null, true));
  165. $this->assertNull($object->getContainer());
  166. }
  167. /**
  168. * @expectedException \Exception
  169. * @expectedExceptionMessage A \PhpOffice\PhpPresentation\ShapeContainerInterface has already been assigned. Shapes can only exist on one \PhpOffice\PhpPresentation\ShapeContainerInterface.
  170. */
  171. public function testContainerException()
  172. {
  173. $object = new RichText();
  174. $oSlide = new Slide();
  175. $this->assertNull($object->getContainer());
  176. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer($oSlide));
  177. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->getContainer());
  178. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer(null));
  179. }
  180. }