AbstractGraphicTest.php 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\AbstractGraphic;
  19. /**
  20. * Test class for Table element
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\AbstractGraphic
  23. */
  24. class AbstractGraphicTest extends \PHPUnit_Framework_TestCase
  25. {
  26. public function testWidthAndHeight()
  27. {
  28. $min = 10;
  29. $max = 20;
  30. /** @var AbstractGraphic $stub */
  31. $stub = $this->getMockForAbstractClass('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic');
  32. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setResizeProportional(false));
  33. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidth($min));
  34. $this->assertEquals($min, $stub->getWidth());
  35. $this->assertEquals(0, $stub->getHeight());
  36. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setHeight($max));
  37. $this->assertEquals($min, $stub->getWidth());
  38. $this->assertEquals($max, $stub->getHeight());
  39. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidthAndHeight($min, $max));
  40. $this->assertEquals($min, $stub->getWidth());
  41. $this->assertEquals($max, $stub->getHeight());
  42. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setResizeProportional(true));
  43. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidth($max));
  44. $this->assertEquals($max, $stub->getWidth());
  45. $this->assertEquals($max * ($max / $min), $stub->getHeight());
  46. $this->assertEquals($max, $stub->getWidth());
  47. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setHeight($min));
  48. $this->assertEquals($min * ($max / ($max * ($max / $min))), $stub->getWidth());
  49. $this->assertEquals($min, $stub->getHeight());
  50. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidthAndHeight($min, $max));
  51. $this->assertEquals($min, $stub->getWidth());
  52. $this->assertEquals($max, $stub->getHeight());
  53. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidthAndHeight($max, $min));
  54. $this->assertEquals($min * ($min / $max), $stub->getWidth());
  55. $this->assertEquals($min, $stub->getHeight());
  56. }
  57. public function testWidthAndHeight2()
  58. {
  59. $min = 10;
  60. $max = 20;
  61. /** @var AbstractGraphic $stub */
  62. $stub = $this->getMockForAbstractClass('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic');
  63. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setResizeProportional(false));
  64. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidth($max));
  65. $this->assertEquals($max, $stub->getWidth());
  66. $this->assertEquals(0, $stub->getHeight());
  67. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setHeight($min));
  68. $this->assertEquals($max, $stub->getWidth());
  69. $this->assertEquals($min, $stub->getHeight());
  70. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setResizeProportional(true));
  71. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidth($max));
  72. $this->assertEquals($max, $stub->getWidth());
  73. $this->assertEquals($max * ($min / $max), $stub->getHeight());
  74. $this->assertEquals($max, $stub->getWidth());
  75. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setHeight($min));
  76. $this->assertEquals($max * ($min / ($max * ($min / $max))), $stub->getWidth());
  77. $this->assertEquals($min, $stub->getHeight());
  78. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AbstractGraphic', $stub->setWidthAndHeight($min, $max));
  79. $this->assertEquals($min, $stub->getWidth());
  80. $this->assertEquals($min * ($min / ($max * ($min / ($max * ($min / $max))))), $stub->getHeight());
  81. }
  82. }