GroupTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\Shape;
  18. use PhpOffice\PhpPresentation\Shape\Group;
  19. use PhpOffice\PhpPresentation\Shape\Line;
  20. /**
  21. * Test class for Group element
  22. *
  23. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Group
  24. */
  25. class GroupTest extends \PHPUnit_Framework_TestCase
  26. {
  27. public function testConstruct()
  28. {
  29. $object = new Group();
  30. $this->assertEquals(0, $object->getOffsetX());
  31. $this->assertEquals(0, $object->getOffsetY());
  32. $this->assertEquals(0, $object->getExtentX());
  33. $this->assertEquals(0, $object->getExtentY());
  34. $this->assertEquals(0, $object->getShapeCollection()->count());
  35. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Group', $object->setWidth(rand(1, 100)));
  36. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Group', $object->setHeight(rand(1, 100)));
  37. }
  38. public function testAdd()
  39. {
  40. $object = new Group();
  41. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart', $object->createChartShape());
  42. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\File', $object->createDrawingShape());
  43. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Line', $object->createLineShape(10, 10, 10, 10));
  44. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->createRichTextShape());
  45. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table', $object->createTableShape());
  46. $this->assertEquals(5, $object->getShapeCollection()->count());
  47. }
  48. public function testExtentX()
  49. {
  50. $object = new Group();
  51. $line1 = new Line(10, 20, 30, 40);
  52. $object->addShape($line1);
  53. $this->assertEquals(30, $object->getExtentX());
  54. }
  55. public function testExtentY()
  56. {
  57. $object = new Group();
  58. $line1 = new Line(10, 20, 30, 40);
  59. $object->addShape($line1);
  60. $this->assertEquals(40, $object->getExtentY());
  61. }
  62. public function testOffsetX()
  63. {
  64. $object = new Group();
  65. $line1 = new Line(10, 20, 30, 40);
  66. $object->addShape($line1);
  67. $this->assertEquals(10, $object->getOffsetX());
  68. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Group', $object->setOffsetX(rand(1, 100)));
  69. $this->assertEquals(10, $object->getOffsetX());
  70. }
  71. public function testOffsetY()
  72. {
  73. $object = new Group();
  74. $line1 = new Line(10, 20, 30, 40);
  75. $object->addShape($line1);
  76. $this->assertEquals(20, $object->getOffsetY());
  77. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Group', $object->setOffsetY(rand(1, 100)));
  78. $this->assertEquals(20, $object->getOffsetY());
  79. }
  80. public function testExtentsAndOffsetsForOneShape()
  81. {
  82. // We record initial values here because
  83. // PhpOffice\PhpPresentation\Shape\Line subtracts the offsets
  84. // from the extents to produce a raw width and height.
  85. $offsetX = 100;
  86. $offsetY = 100;
  87. $extentX = 1000;
  88. $extentY = 450;
  89. $object = new Group();
  90. $line1 = new Line($offsetX, $offsetY, $extentX, $extentY);
  91. $object->addShape($line1);
  92. $this->assertEquals($offsetX, $object->getOffsetX());
  93. $this->assertEquals($offsetY, $object->getOffsetY());
  94. $this->assertEquals($extentX, $object->getExtentX());
  95. $this->assertEquals($extentY, $object->getExtentY());
  96. }
  97. public function testExtentsAndOffsetsForTwoShapes()
  98. {
  99. // Since Groups and Slides cache offsets and extents on first
  100. // calculation, this test is separate from the above.
  101. // Should the calculation be performed every GET, this test can be
  102. // combined with the above.
  103. $offsetX = 100;
  104. $offsetY = 100;
  105. $extentX = 1000;
  106. $extentY = 450;
  107. $increase = 50;
  108. $line1 = new Line($offsetX, $offsetY, $extentX, $extentY);
  109. $line2 = new Line(
  110. $offsetX+$increase,
  111. $offsetY+$increase,
  112. $extentX+$increase,
  113. $extentY+$increase
  114. );
  115. $object = new Group();
  116. $object->addShape($line1);
  117. $object->addShape($line2);
  118. $this->assertEquals($offsetX, $object->getOffsetX());
  119. $this->assertEquals($offsetY, $object->getOffsetY());
  120. $this->assertEquals($extentX+$increase, $object->getExtentX());
  121. $this->assertEquals($extentY+$increase, $object->getExtentY());
  122. }
  123. }